Skip to content

Commit

Permalink
Processing images as section
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavlo Dudnytskyi committed May 24, 2024
1 parent 6a1b10b commit 2287f33
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 33 deletions.
16 changes: 3 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,15 @@ Older Haier models controlled by the SmartAir2 application are using the KZW-W00

.. raw:: HTML

<p><a href="./docs/esphome-docs/climate/images/usb_pinout.png?raw=true"><img src="./docs/esphome-docs/climate/images/usb_pinout.png?raw=true" height="50%" width="50%"></a></p>

KZW-W002 module pinout
<p><a href="./docs/esphome-docs/climate/images/usb_pinout.png?raw=true"><img src="./docs/esphome-docs/climate/images/usb_pinout.png?raw=true" height="70%" width="70%"></a><br><i>&emsp;KZW-W002 module pinout</i></p>

Newer Haier models using a module called ESP32-for-Haier. It is an ESP32 single-core board with an ESP32-S0WD chip. In some cases, you can reuse this module and flash it with ESPHome, but some new modules don’t support this. They look the same but have encryption enabled.

**Warning!** The new generation of ESP32-Haier devices has encryption enabled, so they can only be flashed with firmware that is signed with a private key. There is no way to make them work with ESPHome, so if you try to do it, the board will get into a boot loop with the error ``rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)`` The only way to recover this board is to flash it with the original image. So before starting your experiments make a backup image.

.. raw:: HTML

<p><a href="./docs/esphome-docs/climate/images/haier_pinout.jpg?raw=true"><img src="./docs/esphome-docs/climate/images/haier_pinout.jpg?raw=true" height="50%" width="50%"></a></p>

ESP32-for-Haier UART0 pinout
<p><a href="./docs/esphome-docs/climate/images/haier_pinout.jpg?raw=true"><img src="./docs/esphome-docs/climate/images/haier_pinout.jpg?raw=true" height="70%" width="70%"></a><br><i>&emsp;ESP32-for-Haier UART0 pinout</i></p>

Also, you can use any other ESP32, ESP8266, or an RPI pico W board. In this case, you will need to cut the original wire or make a connector yourself (the board has a JST SM04B-GHS-TB connector)

Expand Down Expand Up @@ -305,12 +301,6 @@ Turn off health mode

(supported only by hOn) Start 56°C steri-cleaning

.. code-block:: yaml
on_...:
then:
- climate.haier.start_steri_cleaning: device_id
.. Generated from esphome-docs/sensor/haier.rst
Haier Climate Sensors
Expand Down Expand Up @@ -503,7 +493,7 @@ mm <https://www.tinytronics.nl/shop/en/tools-and-mounting/measuring/accessories/

.. raw:: HTML

<p><a href="./docs/esphome-docs/climate/images/haier_pinout.jpg?raw=true"><img src="./docs/esphome-docs/climate/images/haier_pinout.jpg?raw=true" height="50%" width="50%"></a></p>
<p><a href="./docs/esphome-docs/climate/images/haier_pinout.jpg?raw=true"><img src="./docs/esphome-docs/climate/images/haier_pinout.jpg?raw=true" height="70%" width="70%"></a></p>

To put the device in the flash mode you will need to shortcut GPIO0 to
the ground before powering the device.
Expand Down
6 changes: 3 additions & 3 deletions docs/ESP32_backup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ mm <https://www.tinytronics.nl/shop/en/tools-and-mounting/measuring/accessories/

**UART0 pinout:**

.. raw:: HTML

<p><a href="./docs/esphome-docs/climate/images/haier_pinout.jpg?raw=true"><img src="./docs/esphome-docs/climate/images/haier_pinout.jpg?raw=true" height="50%" width="50%"></a></p>
.. figure:: esphome-docs/climate/images/haier_pinout.jpg
:align: center
:width: 70.0%

To put the device in the flash mode you will need to shortcut GPIO0 to
the ground before powering the device.
Expand Down
63 changes: 46 additions & 17 deletions docs/script/make_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
'additional_information.rst',
]

def process_images(line, pth):
m = re.match(r"^( *\.\. +figure:: +)(.+)$", line)
if m:
new_url = "./docs/" + pth + "/" + m.group(2)
return ".. raw:: HTML\n\n <p><a href=\"" + new_url + "?raw=true\"><img src=\"" + new_url + "?raw=true\" height=\"50%\" width=\"50%\"></a></p>\n"
#return m.group(1) + new_url + "\n"
return line

def process_esphome_refs(line, l_num):
esphome_refs = [
(":ref:`uart`", "`UART Bus <https://esphome.io/components/uart#uart>`_"),
Expand All @@ -42,17 +34,44 @@ def process_esphome_refs(line, l_num):
print(f"\tWarning: ref found, line #{l_num}")
return res

def process_figure(section, output_file, pth):
m = re.match(r"^( *\.\. +figure:: +)(.+) *$", section[0])
if m:
new_url = "./docs/"
if len(pth) > 0:
new_url += pth + "/"
new_url += m.group(2)
width = "100"
center = False
desc = ""
for sl in section[1:]:
if not sl.strip().startswith(":"):
if len(sl.strip()) > 0:
desc += f"<br><i>&emsp;{sl.strip()}</i>"
if re.match(r"^ *:align: +center *$", sl):
center = True
else:
m = re.match(r"^ *:width: +(\d+)(?:\.\d+)?\%$", sl)
if m:
width = m.group(1)
htm = f"<img src=\"{new_url}?raw=true\" height=\"{width}%\" width=\"{width}%\">"
output_file.write(f".. raw:: HTML\n\n <p><a href=\"{new_url}?raw=true\">{htm}</a>{desc}</p>\n\n")

def process_section(section, output_file, pth):
print(f"\tProcessing section: {section[0].strip()}")
if section[0] == ".. seo::\n":
pass
elif section[0].startswith(".. figure::"):
process_figure(section, output_file, pth)
else:
output_file.writelines(section)

document_header = [
".. This file is automatically generated by ./docs/script/make_doc.py Python script.\n",
" Please, don't change. In case you need to make corrections or changes change\n",
" source documentation in ./doc folder or script.\n\n"
]

lines_to_remove = [
" :align: center\n",
" :width: 50.0%\n",
" :width: 70.0%\n"
]
output_file = open("../../README.rst", "w")
output_file.writelines(document_header)
for in_f in doc_file_path:
Expand All @@ -62,21 +81,31 @@ def process_esphome_refs(line, l_num):
p = os.path.dirname(in_f)
lines = input_file.readlines()
is_seo = False
is_section = False
section = []
l_counter = 0
for line in lines:
l_counter += 1
if line == "See Also\n":
break
if is_section:
if (line in ['\n', '\r\n']) or line.startswith(" "):
section.append(line)
continue
else:
is_section = False
process_section(section, output_file, p)
if (not is_section) and line.startswith(".. "):
is_section = True
section = [ line ]
continue
if line == ".. seo::\n":
is_seo = True
continue
if is_seo:
if not line.startswith(" :"):
is_seo = False
continue
if line in lines_to_remove:
continue
l = process_images(line, p)
l = process_esphome_refs(l, l_counter)
l = process_esphome_refs(line, l_counter)
output_file.write(l)
print(f"\tProcessed {l_counter} line(s)")

0 comments on commit 2287f33

Please sign in to comment.