From 40dcbddbb8054a173f6b5d65b9ea454aaf8000d8 Mon Sep 17 00:00:00 2001 From: Pavlo Dudnytskyi Date: Sat, 27 Jul 2024 15:07:25 +0200 Subject: [PATCH] Script for examples added --- .github/workflows/documentation.yaml | 20 +++++++++++++++++- .github/workflows/examples.yaml | 2 +- docs/examples/hon_example.rst | 12 +++++++++++ docs/examples/res.txt | 18 ---------------- docs/examples/smartair2_example.rst | 12 +++++++++++ docs/hon_example.rst | 21 +++++++++++++++++-- docs/script/process_examples.py | 31 ++++++++++++++++++++++++++++ docs/smartair2_example.rst | 19 +++++++++++------ 8 files changed, 107 insertions(+), 28 deletions(-) create mode 100644 docs/examples/hon_example.rst delete mode 100644 docs/examples/res.txt create mode 100644 docs/examples/smartair2_example.rst create mode 100644 docs/script/process_examples.py diff --git a/.github/workflows/documentation.yaml b/.github/workflows/documentation.yaml index ba2cc1e..a2ef21b 100644 --- a/.github/workflows/documentation.yaml +++ b/.github/workflows/documentation.yaml @@ -7,7 +7,7 @@ on: jobs: tests: - name: documentation check + - name: Readme check runs-on: ubuntu-latest steps: - name: Checkout code @@ -16,3 +16,21 @@ 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 + - name: Check hon_example + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4.1.3 + - 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 + - name: Check smartair2_example + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4.1.3 + - 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 diff --git a/.github/workflows/examples.yaml b/.github/workflows/examples.yaml index 429a872..41850d3 100644 --- a/.github/workflows/examples.yaml +++ b/.github/workflows/examples.yaml @@ -29,6 +29,6 @@ jobs: - name: Version esphome run: esphome version - name: Prepering test file - run: cat .base.yaml ${{ matrix.file }} > __test__.yaml + run: cat docs/examples/.base.yaml ${{ matrix.file }} > __test__.yaml - name: Build ESPHome config run: esphome compile __test__.yaml diff --git a/docs/examples/hon_example.rst b/docs/examples/hon_example.rst new file mode 100644 index 0000000..b7f6b74 --- /dev/null +++ b/docs/examples/hon_example.rst @@ -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:: examples/min-hon.yaml + +Maximum configuration witch will use all possible options will look like this: + +.. example_yaml:: examples/max-hon.yaml diff --git a/docs/examples/res.txt b/docs/examples/res.txt deleted file mode 100644 index 9c0a83a..0000000 --- a/docs/examples/res.txt +++ /dev/null @@ -1,18 +0,0 @@ - Volume in drive D is Mirror storage - Volume Serial Number is 1EBC-0533 - - Directory of D:\Work\git\haier-esphome\docs\examples - -27/07/2024 13:37 . -27/07/2024 13:37 .. -27/07/2024 13:23 186 .base.yaml -27/07/2024 13:23 .esphome -27/07/2024 13:32 189 .gitignore -27/07/2024 13:19 9.469 max-hon.yaml -27/07/2024 09:15 1.511 max-smartair2.yaml -27/07/2024 09:33 126 min-hon.yaml -27/07/2024 13:21 108 min-smartair2.yaml -27/07/2024 13:37 0 res.txt -27/07/2024 13:23 9.655 __test__.yaml - 8 File(s) 21.244 bytes - 3 Dir(s) 782.259.322.880 bytes free diff --git a/docs/examples/smartair2_example.rst b/docs/examples/smartair2_example.rst new file mode 100644 index 0000000..101fe9b --- /dev/null +++ b/docs/examples/smartair2_example.rst @@ -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:: examples/min-smartair2.yaml + +Maximum configuration witch will use all possible options will look like this: + +.. example_yaml:: examples/max-smartair2.yaml diff --git a/docs/hon_example.rst b/docs/hon_example.rst index 66e5147..98e103b 100644 --- a/docs/hon_example.rst +++ b/docs/hon_example.rst @@ -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 hOn protocol ================================================= @@ -5,8 +9,18 @@ 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: @@ -290,3 +304,6 @@ 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 + + + diff --git a/docs/script/process_examples.py b/docs/script/process_examples.py new file mode 100644 index 0000000..ea84d54 --- /dev/null +++ b/docs/script/process_examples.py @@ -0,0 +1,31 @@ +import sys +import re + +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 ") + sys.exit(1) + +input_file = sys.argv[1] +output_file = sys.argv[2] + +with open(input_file, "r") as f: + 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(m.group(1), "r") + for l in example.readlines(): + ofile.write(" " + l) + ofile.write("\n") + else: + ofile.write(line) \ No newline at end of file diff --git a/docs/smartair2_example.rst b/docs/smartair2_example.rst index fc865c7..e7ce69c 100644 --- a/docs/smartair2_example.rst +++ b/docs/smartair2_example.rst @@ -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 ======================================================= @@ -11,22 +15,22 @@ 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: .. code-block:: yaml - uart: + uart: baud_rate: 9600 tx_pin: 17 rx_pin: 16 id: haier_uart - + api: services: - service: turn_on @@ -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 @@ -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 @@ -89,3 +93,6 @@ 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 + + +