From d1163685d4983baeef462ab5d4efe6343d5bf670 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Wed, 13 Dec 2023 21:37:23 +0100 Subject: [PATCH] Verify YAML output (#9) * make -m upk2esphome.test exit(1) when yaml content is not as expected * add output verification workflow --- .github/workflows/check-output.yml | 13 ++ upk2esphome/test.py | 17 +- .../tests/expected_output/bulb_pwm_ct.yaml | 16 ++ .../tests/expected_output/bulb_pwm_cw.yaml | 16 ++ .../tests/expected_output/bulb_pwm_rgbct.yaml | 29 +++ .../tests/expected_output/bulb_pwm_rgbcw.yaml | 29 +++ .../expected_output/bulb_rgbc_2135_2.yaml | 28 +++ .../expected_output/bulb_rgbcw_2135.yaml | 35 +++ .../bulb_rgbcw_2135_ampere.yaml | 35 +++ .../expected_output/bulb_rgbcw_2235.yaml | 35 +++ .../expected_output/bulb_rgbcw_5758d.yaml | 38 ++++ upk2esphome/tests/expected_output/empty.yaml | 1 + .../expected_output/plug_monitor_bl0937.yaml | 44 ++++ .../expected_output/plug_monitor_bl0942.yaml | 45 ++++ .../expected_output/plug_monitor_hlw8032.yaml | 34 +++ .../expected_output/plug_netled_reuse.yaml | 50 +++++ .../plug_netled_reuse_led1.yaml | 50 +++++ .../tests/expected_output/plug_total.yaml | 27 +++ .../tests/expected_output/switch_monitor.yaml | 52 +++++ ...uyamcu_gogb05wrtredz3bs_wk_thermostat.yaml | 110 ++++++++++ .../tuyamcu_hqq73kftvzh8c92u_fs_fan.yaml | 43 ++++ .../tuyamcu_kpp4upyyxrllgpzg_wsdcg_all.yaml | 203 ++++++++++++++++++ .../tuyamcu_lf36y5nwb8jkxwgg_wsdcg_th01.yaml | 49 +++++ .../expected_output/tuyamcu_uap_dimmer.yaml | 6 + .../tuyamcu_wcihaluccfsoayqa_dlq_breaker.yaml | 69 ++++++ 25 files changed, 1073 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/check-output.yml create mode 100644 upk2esphome/tests/expected_output/bulb_pwm_ct.yaml create mode 100644 upk2esphome/tests/expected_output/bulb_pwm_cw.yaml create mode 100644 upk2esphome/tests/expected_output/bulb_pwm_rgbct.yaml create mode 100644 upk2esphome/tests/expected_output/bulb_pwm_rgbcw.yaml create mode 100644 upk2esphome/tests/expected_output/bulb_rgbc_2135_2.yaml create mode 100644 upk2esphome/tests/expected_output/bulb_rgbcw_2135.yaml create mode 100644 upk2esphome/tests/expected_output/bulb_rgbcw_2135_ampere.yaml create mode 100644 upk2esphome/tests/expected_output/bulb_rgbcw_2235.yaml create mode 100644 upk2esphome/tests/expected_output/bulb_rgbcw_5758d.yaml create mode 100644 upk2esphome/tests/expected_output/empty.yaml create mode 100644 upk2esphome/tests/expected_output/plug_monitor_bl0937.yaml create mode 100644 upk2esphome/tests/expected_output/plug_monitor_bl0942.yaml create mode 100644 upk2esphome/tests/expected_output/plug_monitor_hlw8032.yaml create mode 100644 upk2esphome/tests/expected_output/plug_netled_reuse.yaml create mode 100644 upk2esphome/tests/expected_output/plug_netled_reuse_led1.yaml create mode 100644 upk2esphome/tests/expected_output/plug_total.yaml create mode 100644 upk2esphome/tests/expected_output/switch_monitor.yaml create mode 100644 upk2esphome/tests/expected_output/tuyamcu_gogb05wrtredz3bs_wk_thermostat.yaml create mode 100644 upk2esphome/tests/expected_output/tuyamcu_hqq73kftvzh8c92u_fs_fan.yaml create mode 100644 upk2esphome/tests/expected_output/tuyamcu_kpp4upyyxrllgpzg_wsdcg_all.yaml create mode 100644 upk2esphome/tests/expected_output/tuyamcu_lf36y5nwb8jkxwgg_wsdcg_th01.yaml create mode 100644 upk2esphome/tests/expected_output/tuyamcu_uap_dimmer.yaml create mode 100644 upk2esphome/tests/expected_output/tuyamcu_wcihaluccfsoayqa_dlq_breaker.yaml diff --git a/.github/workflows/check-output.yml b/.github/workflows/check-output.yml new file mode 100644 index 0000000..d26a631 --- /dev/null +++ b/.github/workflows/check-output.yml @@ -0,0 +1,13 @@ +name: Check ESPHome YAML output +on: + push: + branches: ["**"] + pull_request: +jobs: + check-output: + name: Verify YAML output + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - run: python3 -m upk2esphome.test diff --git a/upk2esphome/test.py b/upk2esphome/test.py index 61d84bd..6512c4f 100644 --- a/upk2esphome/test.py +++ b/upk2esphome/test.py @@ -4,7 +4,7 @@ import json import sys from glob import glob - from os.path import dirname, isfile, join + from os.path import basename, dirname, isfile, join from .generator import upk2esphome from .opts import Opts @@ -20,6 +20,8 @@ mask = "*.txt" + errors = [] + for file in glob(join(dirname(__file__), "tests", mask)): if len(sys.argv) == 2 and sys.argv[1] not in file: continue @@ -39,3 +41,16 @@ print("\n".join(f"E: {s}" for s in yr.errors)) print(yr.text) print("-" * 80) + + expected = join( + dirname(__file__), "tests", "expected_output", basename(file) + ).replace(".txt", ".yaml") + with open(expected, "r") as f: + expected_yaml = f.read() + if expected_yaml != yr.text: + errors.append(f"content of {expected} was not as expected") + + if errors: + print("got errors:") + print("\n".join(errors)) + sys.exit(1) diff --git a/upk2esphome/tests/expected_output/bulb_pwm_ct.yaml b/upk2esphome/tests/expected_output/bulb_pwm_ct.yaml new file mode 100644 index 0000000..ce5ea96 --- /dev/null +++ b/upk2esphome/tests/expected_output/bulb_pwm_ct.yaml @@ -0,0 +1,16 @@ +output: + - platform: libretiny_pwm + id: output_brightness + pin: P8 + - platform: libretiny_pwm + id: output_temperature + pin: P7 + +light: + - platform: color_temperature + id: light_color_temperature + name: Light + cold_white_color_temperature: 6500 K + warm_white_color_temperature: 2700 K + brightness: output_brightness + color_temperature: output_temperature diff --git a/upk2esphome/tests/expected_output/bulb_pwm_cw.yaml b/upk2esphome/tests/expected_output/bulb_pwm_cw.yaml new file mode 100644 index 0000000..ba7615e --- /dev/null +++ b/upk2esphome/tests/expected_output/bulb_pwm_cw.yaml @@ -0,0 +1,16 @@ +output: + - platform: libretiny_pwm + id: output_cold + pin: P7 + - platform: libretiny_pwm + id: output_warm + pin: P6 + +light: + - platform: cwww + id: light_cwww + name: Light + cold_white_color_temperature: 6500 K + warm_white_color_temperature: 2700 K + cold_white: output_cold + warm_white: output_warm diff --git a/upk2esphome/tests/expected_output/bulb_pwm_rgbct.yaml b/upk2esphome/tests/expected_output/bulb_pwm_rgbct.yaml new file mode 100644 index 0000000..bd4d228 --- /dev/null +++ b/upk2esphome/tests/expected_output/bulb_pwm_rgbct.yaml @@ -0,0 +1,29 @@ +output: + - platform: libretiny_pwm + id: output_red + pin: P24 + - platform: libretiny_pwm + id: output_green + pin: P9 + - platform: libretiny_pwm + id: output_blue + pin: P26 + - platform: libretiny_pwm + id: output_brightness + pin: P7 + - platform: libretiny_pwm + id: output_temperature + pin: P8 + +light: + - platform: rgbct + id: light_rgbct + name: Light + color_interlock: true + cold_white_color_temperature: 6500 K + warm_white_color_temperature: 2700 K + red: output_red + green: output_green + blue: output_blue + white_brightness: output_brightness + color_temperature: output_temperature diff --git a/upk2esphome/tests/expected_output/bulb_pwm_rgbcw.yaml b/upk2esphome/tests/expected_output/bulb_pwm_rgbcw.yaml new file mode 100644 index 0000000..f9b729c --- /dev/null +++ b/upk2esphome/tests/expected_output/bulb_pwm_rgbcw.yaml @@ -0,0 +1,29 @@ +output: + - platform: libretiny_pwm + id: output_red + pin: P6 + - platform: libretiny_pwm + id: output_green + pin: P26 + - platform: libretiny_pwm + id: output_blue + pin: P24 + - platform: libretiny_pwm + id: output_cold + pin: P7 + - platform: libretiny_pwm + id: output_warm + pin: P8 + +light: + - platform: rgbww + id: light_rgbww + name: Light + color_interlock: true + cold_white_color_temperature: 6500 K + warm_white_color_temperature: 2700 K + red: output_red + green: output_green + blue: output_blue + cold_white: output_cold + warm_white: output_warm diff --git a/upk2esphome/tests/expected_output/bulb_rgbc_2135_2.yaml b/upk2esphome/tests/expected_output/bulb_rgbc_2135_2.yaml new file mode 100644 index 0000000..93a07d8 --- /dev/null +++ b/upk2esphome/tests/expected_output/bulb_rgbc_2135_2.yaml @@ -0,0 +1,28 @@ +sm2135: + clock_pin: P8 + data_pin: P7 + rgb_current: 30mA + cw_current: 45mA + +output: + - platform: sm2135 + id: output_red + channel: 2 + - platform: sm2135 + id: output_green + channel: 1 + - platform: sm2135 + id: output_blue + channel: 0 + - platform: sm2135 + id: output_cold + channel: 3 + +light: + - platform: rgbw + id: light_rgbw + name: Light + red: output_red + green: output_green + blue: output_blue + white: output_cold diff --git a/upk2esphome/tests/expected_output/bulb_rgbcw_2135.yaml b/upk2esphome/tests/expected_output/bulb_rgbcw_2135.yaml new file mode 100644 index 0000000..25b9d3a --- /dev/null +++ b/upk2esphome/tests/expected_output/bulb_rgbcw_2135.yaml @@ -0,0 +1,35 @@ +sm2135: + clock_pin: P7 + data_pin: P9 + rgb_current: 40mA + cw_current: 25mA + +output: + - platform: sm2135 + id: output_red + channel: 2 + - platform: sm2135 + id: output_green + channel: 1 + - platform: sm2135 + id: output_blue + channel: 0 + - platform: sm2135 + id: output_cold + channel: 4 + - platform: sm2135 + id: output_warm + channel: 3 + +light: + - platform: rgbww + id: light_rgbww + name: Light + color_interlock: true + cold_white_color_temperature: 6500 K + warm_white_color_temperature: 2700 K + red: output_red + green: output_green + blue: output_blue + cold_white: output_cold + warm_white: output_warm diff --git a/upk2esphome/tests/expected_output/bulb_rgbcw_2135_ampere.yaml b/upk2esphome/tests/expected_output/bulb_rgbcw_2135_ampere.yaml new file mode 100644 index 0000000..71d5fc4 --- /dev/null +++ b/upk2esphome/tests/expected_output/bulb_rgbcw_2135_ampere.yaml @@ -0,0 +1,35 @@ +sm2135: + clock_pin: P8 + data_pin: P26 + rgb_current: 20mA + cw_current: 50mA + +output: + - platform: sm2135 + id: output_red + channel: 2 + - platform: sm2135 + id: output_green + channel: 1 + - platform: sm2135 + id: output_blue + channel: 0 + - platform: sm2135 + id: output_cold + channel: 4 + - platform: sm2135 + id: output_warm + channel: 3 + +light: + - platform: rgbww + id: light_rgbww + name: Light + color_interlock: true + cold_white_color_temperature: 6500 K + warm_white_color_temperature: 2700 K + red: output_red + green: output_green + blue: output_blue + cold_white: output_cold + warm_white: output_warm diff --git a/upk2esphome/tests/expected_output/bulb_rgbcw_2235.yaml b/upk2esphome/tests/expected_output/bulb_rgbcw_2235.yaml new file mode 100644 index 0000000..f73f1d6 --- /dev/null +++ b/upk2esphome/tests/expected_output/bulb_rgbcw_2235.yaml @@ -0,0 +1,35 @@ +sm2235: + clock_pin: P26 + data_pin: P24 + max_power_color_channels: 1 + max_power_white_channels: 2 + +output: + - platform: sm2235 + id: output_red + channel: 1 + - platform: sm2235 + id: output_green + channel: 0 + - platform: sm2235 + id: output_blue + channel: 2 + - platform: sm2235 + id: output_cold + channel: 4 + - platform: sm2235 + id: output_warm + channel: 3 + +light: + - platform: rgbww + id: light_rgbww + name: Light + color_interlock: true + cold_white_color_temperature: 6500 K + warm_white_color_temperature: 2700 K + red: output_red + green: output_green + blue: output_blue + cold_white: output_cold + warm_white: output_warm diff --git a/upk2esphome/tests/expected_output/bulb_rgbcw_5758d.yaml b/upk2esphome/tests/expected_output/bulb_rgbcw_5758d.yaml new file mode 100644 index 0000000..62d990d --- /dev/null +++ b/upk2esphome/tests/expected_output/bulb_rgbcw_5758d.yaml @@ -0,0 +1,38 @@ +bp5758d: + clock_pin: P24 + data_pin: P26 + +output: + - platform: bp5758d + id: output_red + channel: 2 + current: 14 + - platform: bp5758d + id: output_green + channel: 1 + current: 14 + - platform: bp5758d + id: output_blue + channel: 3 + current: 14 + - platform: bp5758d + id: output_cold + channel: 5 + current: 26 + - platform: bp5758d + id: output_warm + channel: 4 + current: 26 + +light: + - platform: rgbww + id: light_rgbww + name: Light + color_interlock: true + cold_white_color_temperature: 6500 K + warm_white_color_temperature: 2700 K + red: output_red + green: output_green + blue: output_blue + cold_white: output_cold + warm_white: output_warm diff --git a/upk2esphome/tests/expected_output/empty.yaml b/upk2esphome/tests/expected_output/empty.yaml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/upk2esphome/tests/expected_output/empty.yaml @@ -0,0 +1 @@ + diff --git a/upk2esphome/tests/expected_output/plug_monitor_bl0937.yaml b/upk2esphome/tests/expected_output/plug_monitor_bl0937.yaml new file mode 100644 index 0000000..0330e66 --- /dev/null +++ b/upk2esphome/tests/expected_output/plug_monitor_bl0937.yaml @@ -0,0 +1,44 @@ +binary_sensor: + - platform: gpio + id: binary_switch_1 + pin: + number: P10 + inverted: true + mode: INPUT_PULLUP + on_press: + then: + - switch.toggle: switch_1 + +switch: + - platform: gpio + id: switch_1 + name: Relay 1 + pin: P26 + +status_led: + pin: + number: P6 + inverted: true + +sensor: + - platform: hlw8012 + model: BL0937 + cf_pin: + number: P7 + inverted: true + cf1_pin: + number: P8 + inverted: true + sel_pin: + number: P24 + inverted: true + current: + name: BL0937 Current + voltage: + name: BL0937 Voltage + power: + name: BL0937 Power + energy: + name: BL0937 Energy + voltage_divider: 1600 + current_resistor: 0.001 ohm diff --git a/upk2esphome/tests/expected_output/plug_monitor_bl0942.yaml b/upk2esphome/tests/expected_output/plug_monitor_bl0942.yaml new file mode 100644 index 0000000..350b66f --- /dev/null +++ b/upk2esphome/tests/expected_output/plug_monitor_bl0942.yaml @@ -0,0 +1,45 @@ +binary_sensor: + - platform: gpio + id: binary_switch_1 + pin: + number: P6 + inverted: true + mode: INPUT_PULLUP + on_press: + then: + - switch.toggle: switch_1 + +switch: + - platform: gpio + id: switch_1 + name: Relay 1 + pin: P26 + +status_led: + pin: + number: P8 + inverted: true + +uart: + id: uart_bus + tx_pin: TX1 + rx_pin: RX1 + baud_rate: 4800 + stop_bits: 1 + +sensor: + - platform: bl0942 + uart_id: uart_bus + current: + name: BL0942 Current + voltage: + name: BL0942 Voltage + power: + name: BL0942 Power + filters: + multiply: -1 + energy: + name: BL0942 Energy + frequency: + name: BL0942 Frequency + accuracy_decimals: 2 diff --git a/upk2esphome/tests/expected_output/plug_monitor_hlw8032.yaml b/upk2esphome/tests/expected_output/plug_monitor_hlw8032.yaml new file mode 100644 index 0000000..eb3b895 --- /dev/null +++ b/upk2esphome/tests/expected_output/plug_monitor_hlw8032.yaml @@ -0,0 +1,34 @@ +binary_sensor: + - platform: gpio + id: binary_switch_1 + pin: + number: P7 + inverted: true + mode: INPUT_PULLUP + on_press: + then: + - switch.toggle: switch_1 + - platform: gpio + id: binary_switch_2 + pin: + number: P24 + inverted: true + mode: INPUT_PULLUP + on_press: + then: + - switch.toggle: switch_2 + +switch: + - platform: gpio + id: switch_1 + name: Relay 1 + pin: P6 + - platform: gpio + id: switch_2 + name: Relay 2 + pin: P26 + +status_led: + pin: + number: P8 + inverted: true diff --git a/upk2esphome/tests/expected_output/plug_netled_reuse.yaml b/upk2esphome/tests/expected_output/plug_netled_reuse.yaml new file mode 100644 index 0000000..cb862d1 --- /dev/null +++ b/upk2esphome/tests/expected_output/plug_netled_reuse.yaml @@ -0,0 +1,50 @@ +binary_sensor: + - platform: gpio + id: binary_switch_1 + pin: + number: P23 + inverted: true + mode: INPUT_PULLUP + on_press: + then: + - switch.toggle: switch_1 + +switch: + - platform: gpio + id: switch_1 + name: Relay 1 + pin: P26 + on_turn_on: + - light.turn_on: light_status + on_turn_off: + - light.turn_off: light_status + +light: + - platform: status_led + id: light_status + pin: + number: P8 + inverted: true + +sensor: + - platform: hlw8012 + model: BL0937 + cf_pin: + number: P7 + inverted: true + cf1_pin: + number: P6 + inverted: true + sel_pin: + number: P24 + inverted: true + current: + name: BL0937 Current + voltage: + name: BL0937 Voltage + power: + name: BL0937 Power + energy: + name: BL0937 Energy + voltage_divider: 1600 + current_resistor: 0.001 ohm diff --git a/upk2esphome/tests/expected_output/plug_netled_reuse_led1.yaml b/upk2esphome/tests/expected_output/plug_netled_reuse_led1.yaml new file mode 100644 index 0000000..d654d16 --- /dev/null +++ b/upk2esphome/tests/expected_output/plug_netled_reuse_led1.yaml @@ -0,0 +1,50 @@ +binary_sensor: + - platform: gpio + id: binary_switch_1 + pin: + number: P10 + inverted: true + mode: INPUT_PULLUP + on_press: + then: + - switch.toggle: switch_1 + +switch: + - platform: gpio + id: switch_1 + name: Relay 1 + pin: P26 + on_turn_on: + - light.turn_on: light_status + on_turn_off: + - light.turn_off: light_status + +light: + - platform: status_led + id: light_status + pin: + number: P8 + inverted: true + +sensor: + - platform: hlw8012 + model: BL0937 + cf_pin: + number: P7 + inverted: true + cf1_pin: + number: P6 + inverted: true + sel_pin: + number: P24 + inverted: true + current: + name: BL0937 Current + voltage: + name: BL0937 Voltage + power: + name: BL0937 Power + energy: + name: BL0937 Energy + voltage_divider: 1600 + current_resistor: 0.001 ohm diff --git a/upk2esphome/tests/expected_output/plug_total.yaml b/upk2esphome/tests/expected_output/plug_total.yaml new file mode 100644 index 0000000..074f48b --- /dev/null +++ b/upk2esphome/tests/expected_output/plug_total.yaml @@ -0,0 +1,27 @@ +switch: + - platform: gpio + id: switch_1 + name: Relay 1 + pin: P24 + on_turn_on: + - light.turn_on: light_status + on_turn_off: + - light.turn_off: light_status + +binary_sensor: + - platform: gpio + id: binary_switch_all + pin: + number: P26 + inverted: true + mode: INPUT_PULLUP + on_press: + then: + - switch.toggle: switch_1 + +light: + - platform: status_led + id: light_status + pin: + number: P7 + inverted: true diff --git a/upk2esphome/tests/expected_output/switch_monitor.yaml b/upk2esphome/tests/expected_output/switch_monitor.yaml new file mode 100644 index 0000000..cf3335e --- /dev/null +++ b/upk2esphome/tests/expected_output/switch_monitor.yaml @@ -0,0 +1,52 @@ +binary_sensor: + - platform: gpio + id: binary_onoff_1 + pin: + number: P6 + inverted: true + mode: INPUT_PULLUP + on_state: + then: + - switch.toggle: switch_1 + - platform: gpio + id: binary_switch_all + pin: + number: P23 + inverted: true + mode: INPUT_PULLUP + on_press: + then: + - switch.toggle: switch_1 + +switch: + - platform: gpio + id: switch_1 + name: Relay 1 + pin: P7 + +status_led: + pin: P26 + +uart: + id: uart_bus + tx_pin: P11 + rx_pin: P10 + baud_rate: 4800 + stop_bits: 1 + +sensor: + - platform: bl0942 + uart_id: uart_bus + current: + name: BL0942 Current + voltage: + name: BL0942 Voltage + power: + name: BL0942 Power + filters: + multiply: -1 + energy: + name: BL0942 Energy + frequency: + name: BL0942 Frequency + accuracy_decimals: 2 diff --git a/upk2esphome/tests/expected_output/tuyamcu_gogb05wrtredz3bs_wk_thermostat.yaml b/upk2esphome/tests/expected_output/tuyamcu_gogb05wrtredz3bs_wk_thermostat.yaml new file mode 100644 index 0000000..57551f6 --- /dev/null +++ b/upk2esphome/tests/expected_output/tuyamcu_gogb05wrtredz3bs_wk_thermostat.yaml @@ -0,0 +1,110 @@ +uart: + rx_pin: RX1 + tx_pin: TX1 + baud_rate: 115200 + +tuya: + # DPIDs processed from schema model: 00000045od + on_datapoint_update: + - sensor_datapoint: 36 + datapoint_type: enum + then: + - text_sensor.template.publish: + id: tuya_valve_state + state: !lambda "return std::to_string(x);" + +switch: + - platform: tuya + switch_datapoint: 1 + name: (Unconfirmed) Switch + - platform: tuya + switch_datapoint: 10 + name: (Unconfirmed) Frost + - platform: tuya + switch_datapoint: 39 + name: (Unconfirmed) Factory Reset + - platform: tuya + switch_datapoint: 40 + name: (Unconfirmed) Child Lock + +select: + - platform: tuya + enum_datapoint: 2 + name: (Unconfirmed) Mode + optimistic: true + options: + 0: Auto + 1: Manual + - platform: tuya + enum_datapoint: 43 + name: (Unconfirmed) Sensor Choose + optimistic: true + options: + 0: In + 1: Out + 2: All + - platform: tuya + enum_datapoint: 102 + name: (Unconfirmed) Program Mode + optimistic: true + options: + 0: "00" + 1: "52" + 2: "61" + 3: "70" + +number: + - platform: tuya + number_datapoint: 16 + name: (Unconfirmed) Temp Set + unit_of_measurement: "\xB0C" + min_value: 5 + max_value: 90 + step: 1 + - platform: tuya + number_datapoint: 19 + name: (Unconfirmed) Upper Temp + unit_of_measurement: "\xB0C" + min_value: 30 + max_value: 90 + step: 1 + - platform: tuya + number_datapoint: 26 + name: (Unconfirmed) Lower Temp + unit_of_measurement: "\xB0C" + min_value: 5 + max_value: 20 + step: 1 + - platform: tuya + number_datapoint: 27 + name: (Unconfirmed) Temp Correction + unit_of_measurement: "" + min_value: -9 + max_value: 9 + step: 1 + - platform: tuya + number_datapoint: 101 + name: (Unconfirmed) Temp Dif + unit_of_measurement: "\xB0C" + min_value: 1 + max_value: 5 + step: 1 + +sensor: + - platform: tuya + sensor_datapoint: 24 + name: Temperature + device_class: temperature + unit_of_measurement: "\xB0C" + accuracy_decimals: 1 + filters: + - multiply: 0.1 + +text_sensor: + - platform: template + id: tuya_valve_state + name: (Unconfirmed) Valve State + filters: + - map: + - 0 -> Open + - 1 -> Close diff --git a/upk2esphome/tests/expected_output/tuyamcu_hqq73kftvzh8c92u_fs_fan.yaml b/upk2esphome/tests/expected_output/tuyamcu_hqq73kftvzh8c92u_fs_fan.yaml new file mode 100644 index 0000000..35b24a2 --- /dev/null +++ b/upk2esphome/tests/expected_output/tuyamcu_hqq73kftvzh8c92u_fs_fan.yaml @@ -0,0 +1,43 @@ +uart: + rx_pin: RX1 + tx_pin: TX1 + baud_rate: 115200 + +tuya: + # DPIDs processed from schema model: 0000003niz + +switch: + - platform: tuya + switch_datapoint: 1 + name: (Unconfirmed) Switch + - platform: tuya + switch_datapoint: 9 + name: (Unconfirmed) Light + +select: + - platform: tuya + enum_datapoint: 3 + name: (Unconfirmed) Fan Speed + optimistic: true + options: + 0: "1" + 1: "2" + 2: "3" + - platform: tuya + enum_datapoint: 6 + name: (Unconfirmed) Countdown + optimistic: true + options: + 0: "0" + 1: "1" + 2: "2" + 3: "3" + 4: "4" + 5: "5" + 6: "6" + +sensor: + - platform: tuya + sensor_datapoint: 7 + name: (Unconfirmed) Countdown Left + unit_of_measurement: "" diff --git a/upk2esphome/tests/expected_output/tuyamcu_kpp4upyyxrllgpzg_wsdcg_all.yaml b/upk2esphome/tests/expected_output/tuyamcu_kpp4upyyxrllgpzg_wsdcg_all.yaml new file mode 100644 index 0000000..1014238 --- /dev/null +++ b/upk2esphome/tests/expected_output/tuyamcu_kpp4upyyxrllgpzg_wsdcg_all.yaml @@ -0,0 +1,203 @@ +uart: + rx_pin: RX1 + tx_pin: TX1 + baud_rate: 115200 + +tuya: + # DPIDs processed from schema model: ew4h7s + on_datapoint_update: + - sensor_datapoint: 3 + datapoint_type: enum + then: + - text_sensor.template.publish: + id: tuya_battery_state + state: !lambda "return std::to_string(x);" + - sensor_datapoint: 14 + datapoint_type: enum + then: + - text_sensor.template.publish: + id: tuya_temp_alarm + state: !lambda "return std::to_string(x);" + - sensor_datapoint: 15 + datapoint_type: enum + then: + - text_sensor.template.publish: + id: tuya_hum_alarm + state: !lambda "return std::to_string(x);" + +sensor: + - platform: tuya + sensor_datapoint: 1 + name: Temperature + device_class: temperature + unit_of_measurement: "\xB0C" + accuracy_decimals: 1 + filters: + - multiply: 0.1 + - platform: tuya + sensor_datapoint: 2 + name: Humidity + device_class: humidity + unit_of_measurement: "%" + - platform: tuya + sensor_datapoint: 4 + name: Battery Level + device_class: battery + unit_of_measurement: "%" + - platform: tuya + sensor_datapoint: 16 + name: Luminance + device_class: illuminance + unit_of_measurement: lx + +text_sensor: + - platform: template + id: tuya_battery_state + name: Battery Level + filters: + - map: + - 0 -> Low + - 1 -> Medium + - 2 -> High + - platform: template + id: tuya_temp_alarm + name: (Unconfirmed) Temp Alarm + filters: + - map: + - 0 -> Loweralarm + - 1 -> Upperalarm + - 2 -> Cancel + - platform: template + id: tuya_hum_alarm + name: (Unconfirmed) Hum Alarm + filters: + - map: + - 0 -> Loweralarm + - 1 -> Upperalarm + - 2 -> Cancel + +binary_sensor: + - platform: tuya + sensor_datapoint: 5 + name: Tamper Alarm + - platform: tuya + sensor_datapoint: 8 + name: (Unconfirmed) Charge State + +number: + - platform: tuya + number_datapoint: 6 + name: Temperature Sampling Interval + entity_category: config + unit_of_measurement: s + min_value: 0 + max_value: 3600 + step: 1 + - platform: tuya + number_datapoint: 7 + name: Humidity Sampling Interval + entity_category: config + unit_of_measurement: s + min_value: 0 + max_value: 3600 + step: 1 + - platform: tuya + number_datapoint: 10 + name: Temperature Upper Limit + entity_category: config + device_class: temperature + unit_of_measurement: "\xB0C" + min_value: -200 + max_value: 600 + step: 1 + - platform: tuya + number_datapoint: 11 + name: Temperature Lower Limit + entity_category: config + device_class: temperature + unit_of_measurement: "\xB0C" + min_value: -200 + max_value: 600 + step: 1 + - platform: tuya + number_datapoint: 12 + name: Humidity Upper Limit + entity_category: config + device_class: humidity + unit_of_measurement: "%" + min_value: 0 + max_value: 100 + step: 1 + - platform: tuya + number_datapoint: 13 + name: Humidity Lower Limit + entity_category: config + device_class: humidity + unit_of_measurement: "%" + min_value: 0 + max_value: 100 + step: 1 + - platform: tuya + number_datapoint: 17 + name: (Unconfirmed) Temp Periodic Report + unit_of_measurement: min + min_value: 1 + max_value: 60 + step: 1 + - platform: tuya + number_datapoint: 18 + name: (Unconfirmed) Hum Periodic Report + unit_of_measurement: min + min_value: 1 + max_value: 60 + step: 1 + - platform: tuya + number_datapoint: 19 + name: (Unconfirmed) Temp Sensitivity + unit_of_measurement: "\xB0C" + min_value: 3 + max_value: 10 + step: 1 + - platform: tuya + number_datapoint: 20 + name: (Unconfirmed) Hum Sensitivity + unit_of_measurement: "%" + min_value: 3 + max_value: 10 + step: 1 + - platform: tuya + number_datapoint: 22 + name: (Unconfirmed) Temp Set + unit_of_measurement: "\xB0C" + min_value: 50 + max_value: 350 + step: 5 + - platform: tuya + number_datapoint: 23 + name: (Unconfirmed) Temp Calibration + unit_of_measurement: "\xB0C" + min_value: -20 + max_value: 20 + step: 1 + - platform: tuya + number_datapoint: 24 + name: (Unconfirmed) Hum Calibration + unit_of_measurement: "%" + min_value: -10 + max_value: 10 + step: 1 + +select: + - platform: tuya + enum_datapoint: 9 + name: Unit Conversion + entity_category: config + optimistic: true + options: + 0: C + 1: F + +switch: + - platform: tuya + switch_datapoint: 21 + name: (Unconfirmed) Switch diff --git a/upk2esphome/tests/expected_output/tuyamcu_lf36y5nwb8jkxwgg_wsdcg_th01.yaml b/upk2esphome/tests/expected_output/tuyamcu_lf36y5nwb8jkxwgg_wsdcg_th01.yaml new file mode 100644 index 0000000..b30dcbe --- /dev/null +++ b/upk2esphome/tests/expected_output/tuyamcu_lf36y5nwb8jkxwgg_wsdcg_th01.yaml @@ -0,0 +1,49 @@ +uart: + rx_pin: RX1 + tx_pin: TX1 + baud_rate: REPLACEME + +tuya: + # DPIDs processed from schema model: 000004ax7p + on_datapoint_update: + - sensor_datapoint: 3 + datapoint_type: enum + then: + - text_sensor.template.publish: + id: tuya_battery_state + state: !lambda "return std::to_string(x);" + +sensor: + - platform: tuya + sensor_datapoint: 1 + name: Temperature + device_class: temperature + unit_of_measurement: "\xB0C" + accuracy_decimals: 1 + filters: + - multiply: 0.1 + - platform: tuya + sensor_datapoint: 2 + name: Humidity + device_class: humidity + unit_of_measurement: "%" + +text_sensor: + - platform: template + id: tuya_battery_state + name: Battery Level + filters: + - map: + - 0 -> Low + - 1 -> Medium + - 2 -> High + +select: + - platform: tuya + enum_datapoint: 9 + name: Unit Conversion + entity_category: config + optimistic: true + options: + 0: C + 1: F diff --git a/upk2esphome/tests/expected_output/tuyamcu_uap_dimmer.yaml b/upk2esphome/tests/expected_output/tuyamcu_uap_dimmer.yaml new file mode 100644 index 0000000..5aa5706 --- /dev/null +++ b/upk2esphome/tests/expected_output/tuyamcu_uap_dimmer.yaml @@ -0,0 +1,6 @@ +uart: + rx_pin: RX1 + tx_pin: TX1 + baud_rate: 9600 + +tuya: diff --git a/upk2esphome/tests/expected_output/tuyamcu_wcihaluccfsoayqa_dlq_breaker.yaml b/upk2esphome/tests/expected_output/tuyamcu_wcihaluccfsoayqa_dlq_breaker.yaml new file mode 100644 index 0000000..09f3ba4 --- /dev/null +++ b/upk2esphome/tests/expected_output/tuyamcu_wcihaluccfsoayqa_dlq_breaker.yaml @@ -0,0 +1,69 @@ +uart: + rx_pin: RX1 + tx_pin: TX1 + baud_rate: 115200 + +tuya: + # DPIDs processed from schema model: 000004pxun + +sensor: + - platform: tuya + sensor_datapoint: 1 + name: Total Forward Active Energy + device_class: energy + state_class: total_increasing + unit_of_measurement: kWh + accuracy_decimals: 2 + filters: + - multiply: 0.01 + - platform: tuya + sensor_datapoint: 13 + name: Remaining Available Energy Display + unit_of_measurement: kWh + accuracy_decimals: 2 + filters: + - multiply: 0.01 + - platform: tuya + sensor_datapoint: 15 + name: Leakage Current + unit_of_measurement: mA + +switch: + - platform: tuya + switch_datapoint: 11 + name: Prepayment Function + - platform: tuya + switch_datapoint: 12 + name: Clear Energy Data + entity_category: config + - platform: tuya + switch_datapoint: 16 + name: Circuit Breaker On/Off + +number: + - platform: tuya + number_datapoint: 14 + name: (Unconfirmed) Charge Energy + unit_of_measurement: kWh + min_value: 0 + max_value: 999999 + step: 1 + - platform: tuya + number_datapoint: 104 + name: (Unconfirmed) Over Vol Protect Time + unit_of_measurement: sec + min_value: 1 + max_value: 30 + step: 1 + - platform: tuya + number_datapoint: 105 + name: (Unconfirmed) Over Vol Recovery Time + unit_of_measurement: sec + min_value: 1 + max_value: 500 + step: 1 + +text_sensor: + - platform: tuya + sensor_datapoint: 19 + name: (Unconfirmed) Breaker Id