From 3e57d0d3d30add2a7d126a499b4800c78e1043e4 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Wed, 20 Oct 2021 19:08:43 +0200 Subject: [PATCH] Complete Switch/Socket/Power Strip device support for Tuya (#58106) --- homeassistant/components/tuya/const.py | 5 +++ homeassistant/components/tuya/light.py | 16 +++++++++ homeassistant/components/tuya/select.py | 33 ++++++++++++++++++- .../components/tuya/strings.select.json | 14 ++++++++ .../tuya/translations/select.en.json | 14 ++++++++ 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/tuya/strings.select.json create mode 100644 homeassistant/components/tuya/translations/select.en.json diff --git a/homeassistant/components/tuya/const.py b/homeassistant/components/tuya/const.py index 9fc6a30e80c..7825c919a31 100644 --- a/homeassistant/components/tuya/const.py +++ b/homeassistant/components/tuya/const.py @@ -75,6 +75,9 @@ CONF_PASSWORD = "password" CONF_COUNTRY_CODE = "country_code" CONF_APP_TYPE = "tuya_app_type" +DEVICE_CLASS_TUYA_RELAY_STATUS = "tuya__relay_status" +DEVICE_CLASS_TUYA_LIGHT_MODE = "tuya__light_mode" + TUYA_DISCOVERY_NEW = "tuya_discovery_new" TUYA_HA_SIGNAL_UPDATE_ENTITY = "tuya_entry_update" @@ -164,6 +167,7 @@ class DPCode(str, Enum): HUMIDITY_SET = "humidity_set" # Humidity setting HUMIDITY_VALUE = "humidity_value" # Humidity LIGHT = "light" # Light + LIGHT_MODE = "light_mode" LOCK = "lock" # Lock / Child lock MATERIAL = "material" # Material MODE = "mode" # Working mode / Mode @@ -183,6 +187,7 @@ class DPCode(str, Enum): PRESENCE_STATE = "presence_state" PUMP_RESET = "pump_reset" # Water pump reset RECORD_SWITCH = "record_switch" # Recording switch + RELAY_STATUS = "relay_status" SEEK = "seek" SENSITIVITY = "sensitivity" # Sensitivity SHAKE = "shake" # Oscillating diff --git a/homeassistant/components/tuya/light.py b/homeassistant/components/tuya/light.py index c22050eb85e..18aedb9366b 100644 --- a/homeassistant/components/tuya/light.py +++ b/homeassistant/components/tuya/light.py @@ -105,6 +105,14 @@ LIGHTS: dict[str, tuple[TuyaLightEntityDescription, ...]] = { color_data=DPCode.COLOUR_DATA, ), ), + # Switch + # https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s + "kg": ( + TuyaLightEntityDescription( + key=DPCode.SWITCH_BACKLIGHT, + name="Backlight", + ), + ), # Dimmer # https://developer.tuya.com/en/docs/iot/tgq?id=Kaof8ke9il4k4 "tgq": ( @@ -157,6 +165,14 @@ LIGHTS: dict[str, tuple[TuyaLightEntityDescription, ...]] = { ), } +# Socket (duplicate of `kg`) +# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s +LIGHTS["cz"] = LIGHTS["kg"] + +# Power Socket (duplicate of `kg`) +# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s +LIGHTS["pc"] = LIGHTS["kg"] + @dataclass class ColorTypeData: diff --git a/homeassistant/components/tuya/select.py b/homeassistant/components/tuya/select.py index 762c105632f..17d6a9c91cb 100644 --- a/homeassistant/components/tuya/select.py +++ b/homeassistant/components/tuya/select.py @@ -15,7 +15,13 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import HomeAssistantTuyaData from .base import EnumTypeData, TuyaEntity -from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode +from .const import ( + DEVICE_CLASS_TUYA_LIGHT_MODE, + DEVICE_CLASS_TUYA_RELAY_STATUS, + DOMAIN, + TUYA_DISCOVERY_NEW, + DPCode, +) # All descriptions can be found here. Mostly the Enum data types in the # default instructions set of each category end up being a select. @@ -46,6 +52,22 @@ SELECTS: dict[str, tuple[SelectEntityDescription, ...]] = { icon="mdi:coffee", ), ), + # Switch + # https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s + "kg": ( + SelectEntityDescription( + key=DPCode.RELAY_STATUS, + name="Power on Behavior", + device_class=DEVICE_CLASS_TUYA_RELAY_STATUS, + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SelectEntityDescription( + key=DPCode.LIGHT_MODE, + name="Indicator Light Mode", + device_class=DEVICE_CLASS_TUYA_LIGHT_MODE, + entity_category=ENTITY_CATEGORY_CONFIG, + ), + ), # Siren Alarm # https://developer.tuya.com/en/docs/iot/categorysgbj?id=Kaiuz37tlpbnu "sgbj": ( @@ -63,6 +85,15 @@ SELECTS: dict[str, tuple[SelectEntityDescription, ...]] = { } +# Socket (duplicate of `kg`) +# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s +SELECTS["cz"] = SELECTS["kg"] + +# Power Socket (duplicate of `kg`) +# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s +SELECTS["pc"] = SELECTS["kg"] + + async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: diff --git a/homeassistant/components/tuya/strings.select.json b/homeassistant/components/tuya/strings.select.json new file mode 100644 index 00000000000..18450f8d6ff --- /dev/null +++ b/homeassistant/components/tuya/strings.select.json @@ -0,0 +1,14 @@ +{ + "state": { + "tuya__light_mode": { + "none": "[%key:common::state::off%]", + "pos": "Indicate switch location", + "relay": "Indicate switch on/off state" + }, + "tuya__relay_status": { + "last": "Remember last state", + "power_off": "[%key:common::state::off%]", + "power_on": "[%key:common::state::on%]" + } + } +} diff --git a/homeassistant/components/tuya/translations/select.en.json b/homeassistant/components/tuya/translations/select.en.json new file mode 100644 index 00000000000..b1e8670f5d4 --- /dev/null +++ b/homeassistant/components/tuya/translations/select.en.json @@ -0,0 +1,14 @@ +{ + "state": { + "tuya__light_mode": { + "none": "Off", + "pos": "Indicate switch location", + "relay": "Indicate switch on/off state" + }, + "tuya__relay_status": { + "last": "Remember last state", + "power_off": "Off", + "power_on": "On" + } + } +} \ No newline at end of file