Skip to content

Commit

Permalink
Script for examples added
Browse files Browse the repository at this point in the history
  • Loading branch information
paveldn authored and Pavlo Dudnytskyi committed Jul 30, 2024
1 parent ae97970 commit 0b1518c
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 39 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ on:
branches: [ "master", "dev" , "experimental" ]

jobs:
tests:
name: documentation check
readme_check:
name: Readme check
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -16,3 +16,23 @@ jobs:
run: python docs/script/make_doc.py README.tmp
- name: Compare temp file with readme.rst
run: diff -u --strip-trailing-cr README.rst README.tmp
hon_examples_check:
name: Check hon_example
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
- name: Run script and save results
run: python docs/script/process_examples.py docs/examples/hon_example.rst docs/hon_example.tmp
- name: Compare temp file with hon_example.rst
run: diff -u --strip-trailing-cr docs/hon_example.rst docs/hon_example.tmp
smartair2_examples_check:
name: Check smartair2_example
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
- name: Run script and save results
run: python docs/script/process_examples.py docs/examples/smartair2_example.rst docs/smartair2_example.tmp
- name: Compare temp file with smartair2_example.rst
run: diff -u --strip-trailing-cr docs/smartair2_example.rst docs/smartair2_example.tmp
22 changes: 11 additions & 11 deletions .github/workflows/examples.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build component for different platforms
name: build CI test
name: build examples

on:
push:
Expand All @@ -22,13 +22,13 @@ jobs:


steps:
- name: Checkout code
uses: actions/[email protected]
- name: Install esphome
run: pip3 install -U esphome
- name: Version esphome
run: esphome version
- name: Prepering test file
run: cat .base.yaml ${{ matrix.file }} > __test__.yaml
- name: Build ESPHome config
run: esphome compile __test__.yaml
- name: Checkout code
uses: actions/[email protected]
- name: Install esphome
run: pip3 install -U esphome
- name: Version esphome
run: esphome version
- name: Prepering test file
run: cat docs/examples/.base.yaml ${{ matrix.file }} > __test__.yaml
- name: Build ESPHome config
run: esphome compile __test__.yaml
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,4 @@ Additional information
- `ESPHome Haier Climate Sensors <https://esphome.io/components/sensor/haier.html>`_
- `ESPHome Haier Climate Binary Sensors <https://esphome.io/components/binary_sensor/haier.html>`_
- `Esptool.py Documentation <https://docs.espressif.com/projects/esptool/en/latest/esp32/>`_
- `Sniffing serial communication <./docs/sniffing_serial_communication.rst>`_
1 change: 1 addition & 0 deletions docs/examples/.base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ logger:
wifi:
ssid: test_ssid
password: test_pass

12 changes: 12 additions & 0 deletions docs/examples/hon_example.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Example of climate configuration for hOn protocol
=================================================

Configuration of your climate will depend on capabilities specific model.

Minimal configuration will look like this:

.. example_yaml:: min-hon.yaml

Maximum configuration witch will use all possible options will look like this:

.. example_yaml:: max-hon.yaml
2 changes: 1 addition & 1 deletion docs/examples/max-smartair2.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
uart:
uart:
baud_rate: 9600
tx_pin: 17
rx_pin: 16
Expand Down
18 changes: 0 additions & 18 deletions docs/examples/res.txt

This file was deleted.

12 changes: 12 additions & 0 deletions docs/examples/smartair2_example.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Example of climate configuration for smartair2 protocol
=======================================================

Configuration of your climate will depend on capabilities specific model.

Minimal configuration will look like this:

.. example_yaml:: min-smartair2.yaml

Maximum configuration witch will use all possible options will look like this:

.. example_yaml:: max-smartair2.yaml
19 changes: 17 additions & 2 deletions docs/hon_example.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
.. This file is automatically generated by ./docs/script/make_doc.py Python script.
Please, don't change. In case you need to make corrections or changes change
source documentation in ./doc folder or script.
Example of climate configuration for hOn protocol
=================================================

Configuration of your climate will depend on capabilities specific model.

Minimal configuration will look like this:

.. literalinclude:: examples/min-hon.yaml
:language: yaml
.. code-block:: yaml
uart:
baud_rate: 9600
tx_pin: 17
rx_pin: 16
climate:
- platform: haier
protocol: hOn
name: Haier hOn Climate
Maximum configuration witch will use all possible options will look like this:

Expand Down Expand Up @@ -290,3 +304,4 @@ Maximum configuration witch will use all possible options will look like this:
name: Haier hOn Climate Indoor Fan Status
outdoor_fan_status:
name: Haier hOn Climate Outdoor Fan Status
33 changes: 33 additions & 0 deletions docs/script/process_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import sys
import re
import os

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"
]

if len(sys.argv) < 3:
print("Usage: python process_examples.py <input_file> <output_file>")
sys.exit(1)

input_file = sys.argv[1]
output_file = sys.argv[2]

with open(input_file, "r") as f:
fpath = os.path.dirname(os.path.abspath(input_file))
ofile = open(output_file, "w")
lines = f.readlines()
ofile.writelines(document_header)
for line in lines:
m = re.match(r"^.. example_yaml:: ([^\n]+)", line)
if m:
print("Processing example: " + m.group(1))
ofile.write(".. code-block:: yaml\n\n")
example = open(os.path.join(fpath, m.group(1)), "r")
for l in example.readlines():
ofile.write(" " + l)
ofile.write("\n")
else:
ofile.write(line)
15 changes: 10 additions & 5 deletions docs/smartair2_example.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.. This file is automatically generated by ./docs/script/make_doc.py Python script.
Please, don't change. In case you need to make corrections or changes change
source documentation in ./doc folder or script.
Example of climate configuration for smartair2 protocol
=======================================================

Expand All @@ -11,10 +15,10 @@ Minimal configuration will look like this:
baud_rate: 9600
tx_pin: 17
rx_pin: 16
climate:
- platform: haier
name: Haier SmartAir2 Climate
name: Haier hOn Climate
Maximum configuration witch will use all possible options will look like this:
Expand All @@ -26,7 +30,7 @@ Maximum configuration witch will use all possible options will look like this:
tx_pin: 17
rx_pin: 16
id: haier_uart
api:
services:
- service: turn_on
Expand All @@ -35,7 +39,7 @@ Maximum configuration witch will use all possible options will look like this:
- service: turn_off
then:
- climate.haier.power_off: haier_ac
climate:
- platform: haier
id: haier_ac
Expand Down Expand Up @@ -64,7 +68,7 @@ Maximum configuration witch will use all possible options will look like this:
- BOOST
- COMFORT
- AWAY
switch:
- platform: template
id: haier_ac_health_mode
Expand All @@ -89,3 +93,4 @@ Maximum configuration witch will use all possible options will look like this:
climate.haier.display_on: haier_ac
turn_off_action:
climate.haier.display_off: haier_ac

0 comments on commit 0b1518c

Please sign in to comment.