From 71aebc1f9a7e6b68723d8142d6a5c32a3cbc61ba Mon Sep 17 00:00:00 2001 From: Jason Rumney Date: Sat, 23 Nov 2024 20:18:05 +0900 Subject: [PATCH] Tests: add a check for inconsistent marking as optional. Issues fixed in: - beok_tgr81_thermostat.yaml - ble_water_valve.yaml - ble_ysgbs01_lock.yaml - blitzwolf_bw_lt31.yaml - comon_lights.yaml - eurom_sani_bathroom_towel_radiator.yaml - ezaiot_thermostat_smartplug.yaml (renamed lower case, as not yet released) - hyd_weair_plus_fan.yaml - ironzon_fingerprint_lock.yaml - loratap_relay.yaml - mellerware_citymove_vacuum.yaml - moes_wht009_thermostat.yaml - nedis_zbrc10wt_remotecontrol.yaml - puppy_kitty_pet_feeder.yaml - sensei_airconditioner.yaml - wdyk_2p63a_energy_meter.yaml - wdyk_4p100a_energymeter.yaml - zym100_presence_sensor.yaml --- .../devices/beok_tgr81_thermostat_c.yaml | 2 ++ .../tuya_local/devices/ble_water_valve.yaml | 1 + .../tuya_local/devices/ble_ysgbs01_lock.yaml | 1 + .../tuya_local/devices/blitzwolf_bw_lt31.yaml | 3 --- .../tuya_local/devices/comon_lights.yaml | 1 + .../eurom_sani_bathroom_towel_radiator.yaml | 1 + ....yaml => ezaiot_thermostat_smartplug.yaml} | 5 ++++- .../devices/hyd_weair_plus_fan.yaml | 1 + .../devices/ironzon_fingerprint_lock.yaml | 1 + .../tuya_local/devices/loratap_relay.yaml | 6 ------ .../devices/mellerware_citymove_vacuum.yaml | 5 +++++ .../devices/moes_wht009_thermostat.yaml | 2 ++ .../devices/nedis_zbrc10wt_remotecontrol.yaml | 4 ++++ .../devices/puppy_kitty_pet_feeder.yaml | 1 + .../devices/sensei_airconditioner.yaml | 1 + .../devices/wdyk_2p63a_energy_meter.yaml | 12 ++---------- .../devices/wdyk_4p100a_energymeter.yaml | 8 -------- .../devices/zym100_presence_sensor.yaml | 1 + tests/test_device_config.py | 19 +++++++++++++++---- 19 files changed, 43 insertions(+), 32 deletions(-) rename custom_components/tuya_local/devices/{EZAIOT_thermostat_smartplug.yaml => ezaiot_thermostat_smartplug.yaml} (99%) diff --git a/custom_components/tuya_local/devices/beok_tgr81_thermostat_c.yaml b/custom_components/tuya_local/devices/beok_tgr81_thermostat_c.yaml index 0669617661..c725fc5c29 100644 --- a/custom_components/tuya_local/devices/beok_tgr81_thermostat_c.yaml +++ b/custom_components/tuya_local/devices/beok_tgr81_thermostat_c.yaml @@ -31,6 +31,7 @@ primary_entity: max: 90 - id: 19 type: integer + optional: true name: max_temperature - id: 24 type: integer @@ -110,6 +111,7 @@ secondary_entities: - value: true - id: 45 name: fault_code + optional: true type: bitfield - entity: number name: High temperature limit diff --git a/custom_components/tuya_local/devices/ble_water_valve.yaml b/custom_components/tuya_local/devices/ble_water_valve.yaml index 531631389b..7816589c8d 100644 --- a/custom_components/tuya_local/devices/ble_water_valve.yaml +++ b/custom_components/tuya_local/devices/ble_water_valve.yaml @@ -61,6 +61,7 @@ secondary_entities: - value: true - id: 4 type: bitfield + optional: true name: fault_code - entity: sensor name: Operation diff --git a/custom_components/tuya_local/devices/ble_ysgbs01_lock.yaml b/custom_components/tuya_local/devices/ble_ysgbs01_lock.yaml index cdcc2dcc4d..71f7b6ef6b 100644 --- a/custom_components/tuya_local/devices/ble_ysgbs01_lock.yaml +++ b/custom_components/tuya_local/devices/ble_ysgbs01_lock.yaml @@ -98,6 +98,7 @@ secondary_entities: dps: - id: 21 type: string + optional: true name: sensor mapping: - dps_val: low_battery diff --git a/custom_components/tuya_local/devices/blitzwolf_bw_lt31.yaml b/custom_components/tuya_local/devices/blitzwolf_bw_lt31.yaml index 5467432621..274e1878fc 100644 --- a/custom_components/tuya_local/devices/blitzwolf_bw_lt31.yaml +++ b/custom_components/tuya_local/devices/blitzwolf_bw_lt31.yaml @@ -51,9 +51,6 @@ primary_entity: - id: 103 name: line_sequence_adjustment type: integer - - id: 104 - name: strip_points - type: integer secondary_entities: - entity: select name: Music diff --git a/custom_components/tuya_local/devices/comon_lights.yaml b/custom_components/tuya_local/devices/comon_lights.yaml index c9b8619084..1843be6483 100644 --- a/custom_components/tuya_local/devices/comon_lights.yaml +++ b/custom_components/tuya_local/devices/comon_lights.yaml @@ -56,6 +56,7 @@ secondary_entities: - id: 102 type: string name: option + optional: true mapping: - dps_val: "1e03e801f40000000" value: Combination - All diff --git a/custom_components/tuya_local/devices/eurom_sani_bathroom_towel_radiator.yaml b/custom_components/tuya_local/devices/eurom_sani_bathroom_towel_radiator.yaml index 7057495f59..5d587f912d 100644 --- a/custom_components/tuya_local/devices/eurom_sani_bathroom_towel_radiator.yaml +++ b/custom_components/tuya_local/devices/eurom_sani_bathroom_towel_radiator.yaml @@ -105,6 +105,7 @@ secondary_entities: dps: - id: 105 type: integer + optional: true name: sensor unit: C - entity: sensor diff --git a/custom_components/tuya_local/devices/EZAIOT_thermostat_smartplug.yaml b/custom_components/tuya_local/devices/ezaiot_thermostat_smartplug.yaml similarity index 99% rename from custom_components/tuya_local/devices/EZAIOT_thermostat_smartplug.yaml rename to custom_components/tuya_local/devices/ezaiot_thermostat_smartplug.yaml index 82ab17e20b..632d43f4c9 100644 --- a/custom_components/tuya_local/devices/EZAIOT_thermostat_smartplug.yaml +++ b/custom_components/tuya_local/devices/ezaiot_thermostat_smartplug.yaml @@ -25,8 +25,8 @@ primary_entity: - scale: 10 - id: 9 type: integer - name: max_temperature optional: true + name: max_temperature mapping: - scale: 10 - id: 12 @@ -41,6 +41,9 @@ primary_entity: unit: C mapping: - scale: 10 + range: + min: -30 + max: 110 - id: 114 type: integer name: hvac_action diff --git a/custom_components/tuya_local/devices/hyd_weair_plus_fan.yaml b/custom_components/tuya_local/devices/hyd_weair_plus_fan.yaml index 69443070ce..afd2f5ce92 100644 --- a/custom_components/tuya_local/devices/hyd_weair_plus_fan.yaml +++ b/custom_components/tuya_local/devices/hyd_weair_plus_fan.yaml @@ -125,6 +125,7 @@ secondary_entities: - value: true - id: 13 type: bitfield + optional: true name: fault_code - entity: switch name: Beep diff --git a/custom_components/tuya_local/devices/ironzon_fingerprint_lock.yaml b/custom_components/tuya_local/devices/ironzon_fingerprint_lock.yaml index 7b01abc92a..d70110a976 100644 --- a/custom_components/tuya_local/devices/ironzon_fingerprint_lock.yaml +++ b/custom_components/tuya_local/devices/ironzon_fingerprint_lock.yaml @@ -99,6 +99,7 @@ secondary_entities: - value: true - id: 21 type: string + optional: true name: details - entity: binary_sensor class: lock diff --git a/custom_components/tuya_local/devices/loratap_relay.yaml b/custom_components/tuya_local/devices/loratap_relay.yaml index cb6f150353..f292dc0abd 100644 --- a/custom_components/tuya_local/devices/loratap_relay.yaml +++ b/custom_components/tuya_local/devices/loratap_relay.yaml @@ -46,12 +46,6 @@ secondary_entities: value: "on" - dps_val: 2 value: memory - - id: 42 - type: string - name: cycle_time - - id: 43 - type: string - name: random_time - entity: select name: Light Mode category: config diff --git a/custom_components/tuya_local/devices/mellerware_citymove_vacuum.yaml b/custom_components/tuya_local/devices/mellerware_citymove_vacuum.yaml index c8a1fd975c..44fa10a604 100644 --- a/custom_components/tuya_local/devices/mellerware_citymove_vacuum.yaml +++ b/custom_components/tuya_local/devices/mellerware_citymove_vacuum.yaml @@ -10,6 +10,7 @@ primary_entity: name: power - id: 17 type: bitfield + optional: true name: error hidden: true - id: 101 @@ -127,13 +128,17 @@ secondary_entities: dps: - id: 17 type: bitfield + optional: true name: sensor mapping: - dps_val: 0 value: false + - dps_val: null + value: false - value: true - id: 17 type: bitfield + optional: true name: fault_code - id: 17 type: bitfield diff --git a/custom_components/tuya_local/devices/moes_wht009_thermostat.yaml b/custom_components/tuya_local/devices/moes_wht009_thermostat.yaml index 570a5751cc..13c92f1d31 100644 --- a/custom_components/tuya_local/devices/moes_wht009_thermostat.yaml +++ b/custom_components/tuya_local/devices/moes_wht009_thermostat.yaml @@ -40,11 +40,13 @@ primary_entity: step: 5 - id: 19 type: integer + optional: true name: max_temperature mapping: - scale: 10 - id: 26 type: integer + optional: true name: min_temperature mapping: - scale: 10 diff --git a/custom_components/tuya_local/devices/nedis_zbrc10wt_remotecontrol.yaml b/custom_components/tuya_local/devices/nedis_zbrc10wt_remotecontrol.yaml index 9c053c6fe5..300760b0dc 100644 --- a/custom_components/tuya_local/devices/nedis_zbrc10wt_remotecontrol.yaml +++ b/custom_components/tuya_local/devices/nedis_zbrc10wt_remotecontrol.yaml @@ -17,6 +17,7 @@ primary_entity: - value: pressed - id: 29 type: string + optional: true name: code secondary_entities: - entity: event @@ -33,6 +34,7 @@ secondary_entities: - value: pressed - id: 27 type: string + optional: true name: code - entity: event name: Button A @@ -48,6 +50,7 @@ secondary_entities: - value: pressed - id: 28 type: string + optional: true name: code - entity: event name: Button B @@ -63,6 +66,7 @@ secondary_entities: - value: pressed - id: 26 type: string + optional: true name: code - entity: sensor class: battery diff --git a/custom_components/tuya_local/devices/puppy_kitty_pet_feeder.yaml b/custom_components/tuya_local/devices/puppy_kitty_pet_feeder.yaml index 485b322496..3c98b82a8a 100644 --- a/custom_components/tuya_local/devices/puppy_kitty_pet_feeder.yaml +++ b/custom_components/tuya_local/devices/puppy_kitty_pet_feeder.yaml @@ -60,4 +60,5 @@ secondary_entities: - value: false - id: 4 type: string + optional: true name: raw diff --git a/custom_components/tuya_local/devices/sensei_airconditioner.yaml b/custom_components/tuya_local/devices/sensei_airconditioner.yaml index 7a56a0d660..315fe4a2bd 100644 --- a/custom_components/tuya_local/devices/sensei_airconditioner.yaml +++ b/custom_components/tuya_local/devices/sensei_airconditioner.yaml @@ -242,6 +242,7 @@ secondary_entities: dps: - id: 105 type: string + optional: true name: option mapping: - dps_val: c diff --git a/custom_components/tuya_local/devices/wdyk_2p63a_energy_meter.yaml b/custom_components/tuya_local/devices/wdyk_2p63a_energy_meter.yaml index 92ad867255..310461e53a 100644 --- a/custom_components/tuya_local/devices/wdyk_2p63a_energy_meter.yaml +++ b/custom_components/tuya_local/devices/wdyk_2p63a_energy_meter.yaml @@ -100,12 +100,13 @@ secondary_entities: type: boolean name: switch - entity: button - name: Reset energy + name: Reset balance energy category: config class: restart dps: - id: 12 type: boolean + optional: true name: button - entity: sensor name: Energy balance @@ -336,12 +337,3 @@ secondary_entities: type: boolean name: button optional: true - - entity: button - name: Reset balance energy - class: restart - category: config - dps: - - id: 12 - type: boolean - name: button - optional: true diff --git a/custom_components/tuya_local/devices/wdyk_4p100a_energymeter.yaml b/custom_components/tuya_local/devices/wdyk_4p100a_energymeter.yaml index b7407373fd..88a51502cf 100644 --- a/custom_components/tuya_local/devices/wdyk_4p100a_energymeter.yaml +++ b/custom_components/tuya_local/devices/wdyk_4p100a_energymeter.yaml @@ -99,14 +99,6 @@ secondary_entities: - id: 11 type: boolean name: switch - - entity: button - name: Reset energy - category: config - class: restart - dps: - - id: 12 - type: boolean - name: button - entity: sensor name: Energy balance class: energy_storage diff --git a/custom_components/tuya_local/devices/zym100_presence_sensor.yaml b/custom_components/tuya_local/devices/zym100_presence_sensor.yaml index ad21794e49..c3292c5d65 100644 --- a/custom_components/tuya_local/devices/zym100_presence_sensor.yaml +++ b/custom_components/tuya_local/devices/zym100_presence_sensor.yaml @@ -99,6 +99,7 @@ secondary_entities: - value: true - id: 6 type: string + optional: true name: description - entity: sensor name: Target distance diff --git a/tests/test_device_config.py b/tests/test_device_config.py index 95c52beafd..c274e2607d 100644 --- a/tests/test_device_config.py +++ b/tests/test_device_config.py @@ -531,18 +531,29 @@ def test_config_files_parse(self): def test_configs_can_be_matched(self): """Test that the config files can be matched to a device.""" for cfg in available_configs(): - required_dps = 0 + optional = set() + required = set() parsed = TuyaDeviceConfig(cfg) for entity in parsed.all_entities(): for dp in entity.dps(): - if not dp.optional: - required_dps += 1 + if dp.optional: + optional.add(dp.id) + else: + required.add(dp.id) + self.assertGreater( - required_dps, + len(required), 0, msg=f"No required dps found in {cfg}", ) + for dp in required: + self.assertNotIn( + dp, + optional, + msg=f"Optional dp {dp} is required in {cfg}", + ) + # Most of the device_config functionality is exercised during testing of # the various supported devices. These tests concentrate only on the gaps.