From 3fdd8b437fa7bc144080c1af06aed744ce56b2a1 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 30 Jul 2025 15:12:21 +0000 Subject: [PATCH] Add initial support for Tuya wg2 category --- homeassistant/components/tuya/const.py | 3 +- homeassistant/components/tuya/sensor.py | 12 +++ homeassistant/components/tuya/strings.json | 10 ++ tests/components/tuya/__init__.py | 4 + .../tuya/fixtures/wg2_zigbee_gateway.json | 90 +++++++++++++++++ .../tuya/snapshots/test_sensor.ambr | 96 +++++++++++++++++++ 6 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 tests/components/tuya/fixtures/wg2_zigbee_gateway.json diff --git a/homeassistant/components/tuya/const.py b/homeassistant/components/tuya/const.py index 87f80755e8b..94529e383bb 100644 --- a/homeassistant/components/tuya/const.py +++ b/homeassistant/components/tuya/const.py @@ -229,7 +229,8 @@ class DPCode(StrEnum): LIGHT_MODE = "light_mode" LOCK = "lock" # Lock / Child lock MASTER_MODE = "master_mode" # alarm mode - MASTER_STATE = "master_state" # alarm state + MASTER_INFORMATION = "master_information" + MASTER_STATE = "master_state" MACH_OPERATE = "mach_operate" MANUAL_FEED = "manual_feed" MATERIAL = "material" # Material diff --git a/homeassistant/components/tuya/sensor.py b/homeassistant/components/tuya/sensor.py index 6e8da29ef53..01cf39e88e7 100644 --- a/homeassistant/components/tuya/sensor.py +++ b/homeassistant/components/tuya/sensor.py @@ -1077,6 +1077,18 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = { ), *BATTERY_SENSORS, ), + # Zigbee gateway + # Undocumented + "wg2": ( + TuyaSensorEntityDescription( + key=DPCode.MASTER_INFORMATION, + translation_key="master_information", + ), + TuyaSensorEntityDescription( + key=DPCode.MASTER_STATE, + translation_key="master_state", + ), + ), # Thermostat # https://developer.tuya.com/en/docs/iot/f?id=K9gf45ld5l0t9 "wk": (*BATTERY_SENSORS,), diff --git a/homeassistant/components/tuya/strings.json b/homeassistant/components/tuya/strings.json index 97d623d7c21..05dedc6ac5e 100644 --- a/homeassistant/components/tuya/strings.json +++ b/homeassistant/components/tuya/strings.json @@ -699,6 +699,16 @@ "charging": "[%key:common::state::charging%]", "charge_done": "Charge done" } + }, + "master_information": { + "name": "Master information" + }, + "master_state": { + "name": "Master state", + "state": { + "normal": "[%key:common::state::normal%]", + "alarm": "Alarm" + } } }, "switch": { diff --git a/tests/components/tuya/__init__.py b/tests/components/tuya/__init__.py index 039b8f29290..14aa94eecd0 100644 --- a/tests/components/tuya/__init__.py +++ b/tests/components/tuya/__init__.py @@ -158,6 +158,10 @@ DEVICE_MOCKS = { # https://github.com/orgs/home-assistant/discussions/288 # unsupported device - no platforms ], + "wg2_zigbee_gateway": [ + # https://github.com/orgs/home-assistant/discussions/430 + Platform.SENSOR, + ], "wk_wifi_smart_gas_boiler_thermostat": [ # https://github.com/orgs/home-assistant/discussions/243 Platform.CLIMATE, diff --git a/tests/components/tuya/fixtures/wg2_zigbee_gateway.json b/tests/components/tuya/fixtures/wg2_zigbee_gateway.json new file mode 100644 index 00000000000..0e39f713dd0 --- /dev/null +++ b/tests/components/tuya/fixtures/wg2_zigbee_gateway.json @@ -0,0 +1,90 @@ +{ + "endpoint": "https://apigw.tuyaeu.com", + "terminal_id": "1752690839034sq255y", + "mqtt_connected": true, + "disabled_by": null, + "disabled_polling": false, + "id": "bf79ca977d67322eb2o68m", + "name": "X5 Zigbee Gateway", + "category": "wg2", + "product_id": "nwxr8qcu4seltoro", + "product_name": "X5", + "online": true, + "sub": true, + "time_zone": "+02:00", + "active_time": "2025-07-14T10:19:21+00:00", + "create_time": "2025-07-14T10:19:21+00:00", + "update_time": "2025-07-14T10:19:21+00:00", + "function": { + "master_state": { + "type": "Enum", + "value": { + "range": ["normal", "alarm"] + } + }, + "factory_reset": { + "type": "Boolean", + "value": {} + }, + "master_language": { + "type": "Enum", + "value": { + "range": [ + "chinese_simplified", + "chinese_traditional", + "english", + "french", + "italian", + "german", + "spanish", + "portuguese", + "russian", + "japanese" + ] + } + } + }, + "status_range": { + "master_state": { + "type": "Enum", + "value": { + "range": ["normal", "alarm"] + } + }, + "master_information": { + "type": "String", + "value": { + "maxlen": 255 + } + }, + "factory_reset": { + "type": "Boolean", + "value": {} + }, + "master_language": { + "type": "Enum", + "value": { + "range": [ + "chinese_simplified", + "chinese_traditional", + "english", + "french", + "italian", + "german", + "spanish", + "portuguese", + "russian", + "japanese" + ] + } + } + }, + "status": { + "master_state": "normal", + "master_information": "", + "factory_reset": false, + "master_language": "chinese_simplified" + }, + "set_up": false, + "support_local": true +} diff --git a/tests/components/tuya/snapshots/test_sensor.ambr b/tests/components/tuya/snapshots/test_sensor.ambr index 57e73eccda5..7a20bfec8b8 100644 --- a/tests/components/tuya/snapshots/test_sensor.ambr +++ b/tests/components/tuya/snapshots/test_sensor.ambr @@ -2233,6 +2233,102 @@ 'state': '0.0', }) # --- +# name: test_platform_setup_and_discovery[wg2_zigbee_gateway][sensor.x5_zigbee_gateway_master_information-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.x5_zigbee_gateway_master_information', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Master information', + 'platform': 'tuya', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'master_information', + 'unique_id': 'tuya.bf79ca977d67322eb2o68mmaster_information', + 'unit_of_measurement': None, + }) +# --- +# name: test_platform_setup_and_discovery[wg2_zigbee_gateway][sensor.x5_zigbee_gateway_master_information-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'X5 Zigbee Gateway Master information', + }), + 'context': , + 'entity_id': 'sensor.x5_zigbee_gateway_master_information', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '', + }) +# --- +# name: test_platform_setup_and_discovery[wg2_zigbee_gateway][sensor.x5_zigbee_gateway_master_state-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.x5_zigbee_gateway_master_state', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Master state', + 'platform': 'tuya', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'master_state', + 'unique_id': 'tuya.bf79ca977d67322eb2o68mmaster_state', + 'unit_of_measurement': None, + }) +# --- +# name: test_platform_setup_and_discovery[wg2_zigbee_gateway][sensor.x5_zigbee_gateway_master_state-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'X5 Zigbee Gateway Master state', + }), + 'context': , + 'entity_id': 'sensor.x5_zigbee_gateway_master_state', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'normal', + }) +# --- # name: test_platform_setup_and_discovery[wk_wifi_smart_gas_boiler_thermostat][sensor.wifi_smart_gas_boiler_thermostat_battery-entry] EntityRegistryEntrySnapshot({ 'aliases': set({