From 75e561f1fab16088a29429dc21b98d9ff2ea5e99 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 23 Oct 2021 21:24:40 +0200 Subject: [PATCH] Complete Smart Camera (sp) device support to Tuya (#58301) --- homeassistant/components/tuya/const.py | 29 ++++++++ homeassistant/components/tuya/light.py | 15 ++++ homeassistant/components/tuya/number.py | 10 +++ homeassistant/components/tuya/select.py | 51 ++++++++++++++ homeassistant/components/tuya/sensor.py | 23 ++++++ homeassistant/components/tuya/siren.py | 8 +++ .../components/tuya/strings.select.json | 27 +++++++ homeassistant/components/tuya/switch.py | 70 +++++++++++++++++++ .../tuya/translations/select.en.json | 27 +++++++ 9 files changed, 260 insertions(+) diff --git a/homeassistant/components/tuya/const.py b/homeassistant/components/tuya/const.py index 364febe5703..0cf46390601 100644 --- a/homeassistant/components/tuya/const.py +++ b/homeassistant/components/tuya/const.py @@ -75,8 +75,14 @@ CONF_PASSWORD = "password" CONF_COUNTRY_CODE = "country_code" CONF_APP_TYPE = "tuya_app_type" +DEVICE_CLASS_TUYA_BASIC_ANTI_FLICKR = "tuya__basic_anti_flickr" +DEVICE_CLASS_TUYA_BASIC_NIGHTVISION = "tuya__basic_nightvision" +DEVICE_CLASS_TUYA_DECIBEL_SENSITIVITY = "tuya__decibel_sensitivity" +DEVICE_CLASS_TUYA_IPC_WORK_MODE = "tuya__ipc_work_mode" DEVICE_CLASS_TUYA_LED_TYPE = "tuya__led_type" DEVICE_CLASS_TUYA_LIGHT_MODE = "tuya__light_mode" +DEVICE_CLASS_TUYA_MOTION_SENSITIVITY = "tuya__motion_sensitivity" +DEVICE_CLASS_TUYA_RECORD_MODE = "tuya__record_mode" DEVICE_CLASS_TUYA_RELAY_STATUS = "tuya__relay_status" TUYA_DISCOVERY_NEW = "tuya_discovery_new" @@ -130,6 +136,14 @@ class DPCode(str, Enum): ANGLE_HORIZONTAL = "angle_horizontal" ANGLE_VERTICAL = "angle_vertical" ANION = "anion" # Ionizer unit + BASIC_ANTI_FLICKER = "basic_anti_flicker" + BASIC_DEVICE_VOLUME = "basic_device_volume" + BASIC_FLIP = "basic_flip" + BASIC_INDICATOR = "basic_indicator" + BASIC_NIGHTVISION = "basic_nightvision" + BASIC_OSD = "basic_osd" + BASIC_PRIVATE = "basic_private" + BASIC_WDR = "basic_wdr" BATTERY_PERCENTAGE = "battery_percentage" # Battery percentage BATTERY_STATE = "battery_state" # Battery state BATTERY_VALUE = "battery_value" # Battery value @@ -162,10 +176,13 @@ class DPCode(str, Enum): CONTROL = "control" CONTROL_2 = "control_2" CONTROL_3 = "control_3" + CRY_DETECTION_SWITCH = "cry_detection_switch" CUP_NUMBER = "cup_number" # NUmber of cups CUR_CURRENT = "cur_current" # Actual current CUR_POWER = "cur_power" # Actual power CUR_VOLTAGE = "cur_voltage" # Actual voltage + DECIBEL_SENSITIVITY = "decibel_sensitivity" + DECIBEL_SWITCH = "decibel_switch" DEHUMIDITY_SET_VALUE = "dehumidify_set_value" DO_NOT_DISTURB = "do_not_disturb" DOORCONTACT_STATE = "doorcontact_state" # Status of door window sensor @@ -177,12 +194,15 @@ class DPCode(str, Enum): FAN_SPEED_PERCENT = "fan_speed_percent" # Stepless speed FAR_DETECTION = "far_detection" FILTER_RESET = "filter_reset" # Filter (cartridge) reset + FLOODLIGHT_LIGHTNESS = "floodlight_lightness" + FLOODLIGHT_SWITCH = "floodlight_switch" GAS_SENSOR_STATE = "gas_sensor_state" GAS_SENSOR_STATUS = "gas_sensor_status" GAS_SENSOR_VALUE = "gas_sensor_value" HUMIDITY_CURRENT = "humidity_current" # Current humidity HUMIDITY_SET = "humidity_set" # Humidity setting HUMIDITY_VALUE = "humidity_value" # Humidity + IPC_WORK_MODE = "ipc_work_mode" LED_TYPE_1 = "led_type_1" LED_TYPE_2 = "led_type_2" LED_TYPE_3 = "led_type_3" @@ -191,7 +211,10 @@ class DPCode(str, Enum): LOCK = "lock" # Lock / Child lock MATERIAL = "material" # Material MODE = "mode" # Working mode / Mode + MOTION_RECORD = "motion_record" + MOTION_SENSITIVITY = "motion_sensitivity" MOTION_SWITCH = "motion_switch" # Motion switch + MOTION_TRACKING = "motion_tracking" MUFFLING = "muffling" # Muffling NEAR_DETECTION = "near_detection" PAUSE = "pause" @@ -209,12 +232,16 @@ class DPCode(str, Enum): PRESSURE_STATE = "pressure_state" PRESSURE_VALUE = "pressure_value" PUMP_RESET = "pump_reset" # Water pump reset + RECORD_MODE = "record_mode" RECORD_SWITCH = "record_switch" # Recording switch RELAY_STATUS = "relay_status" SEEK = "seek" SENSITIVITY = "sensitivity" # Sensitivity + SENSOR_HUMIDITY = "sensor_humidity" + SENSOR_TEMPERATURE = "sensor_temperature" SHAKE = "shake" # Oscillating SHOCK_STATE = "shock_state" # Vibration status + SIREN_SWITCH = "siren_switch" SITUATION_SET = "situation_set" SMOKE_SENSOR_STATE = "smoke_sensor_state" SMOKE_SENSOR_STATUS = "smoke_sensor_status" @@ -270,6 +297,8 @@ class DPCode(str, Enum): WATER_SET = "water_set" # Water level WATERSENSOR_STATE = "watersensor_state" WET = "wet" # Humidification + WIRELESS_BATTERYLOCK = "wireless_batterylock" + WIRELESS_ELECTRICITY = "wireless_electricity" WORK_MODE = "work_mode" # Working mode WORK_POWER = "work_power" diff --git a/homeassistant/components/tuya/light.py b/homeassistant/components/tuya/light.py index 6a194ed94b2..437c1a1262f 100644 --- a/homeassistant/components/tuya/light.py +++ b/homeassistant/components/tuya/light.py @@ -19,6 +19,7 @@ from homeassistant.components.light import ( LightEntityDescription, ) from homeassistant.config_entries import ConfigEntry +from homeassistant.const import ENTITY_CATEGORY_CONFIG from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -116,6 +117,20 @@ LIGHTS: dict[str, tuple[TuyaLightEntityDescription, ...]] = { name="Backlight", ), ), + # Smart Camera + # https://developer.tuya.com/en/docs/iot/categorysp?id=Kaiuz35leyo12 + "sp": ( + TuyaLightEntityDescription( + key=DPCode.FLOODLIGHT_SWITCH, + brightness=DPCode.FLOODLIGHT_LIGHTNESS, + name="Floodlight", + ), + TuyaLightEntityDescription( + key=DPCode.BASIC_INDICATOR, + name="Indicator Light", + entity_category=ENTITY_CATEGORY_CONFIG, + ), + ), # Dimmer Switch # https://developer.tuya.com/en/docs/iot/categorytgkg?id=Kaiuz0ktx7m0o "tgkg": ( diff --git a/homeassistant/components/tuya/number.py b/homeassistant/components/tuya/number.py index 922012412b7..c69756d2998 100644 --- a/homeassistant/components/tuya/number.py +++ b/homeassistant/components/tuya/number.py @@ -78,6 +78,16 @@ NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = { entity_category=ENTITY_CATEGORY_CONFIG, ), ), + # Smart Camera + # https://developer.tuya.com/en/docs/iot/categorysp?id=Kaiuz35leyo12 + "sp": ( + NumberEntityDescription( + key=DPCode.BASIC_DEVICE_VOLUME, + name="Volume", + icon="mdi:volume-high", + entity_category=ENTITY_CATEGORY_CONFIG, + ), + ), # Dimmer Switch # https://developer.tuya.com/en/docs/iot/categorytgkg?id=Kaiuz0ktx7m0o "tgkg": ( diff --git a/homeassistant/components/tuya/select.py b/homeassistant/components/tuya/select.py index fe6c030f0bc..f56d2929a84 100644 --- a/homeassistant/components/tuya/select.py +++ b/homeassistant/components/tuya/select.py @@ -16,8 +16,14 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import HomeAssistantTuyaData from .base import EnumTypeData, TuyaEntity from .const import ( + DEVICE_CLASS_TUYA_BASIC_ANTI_FLICKR, + DEVICE_CLASS_TUYA_BASIC_NIGHTVISION, + DEVICE_CLASS_TUYA_DECIBEL_SENSITIVITY, + DEVICE_CLASS_TUYA_IPC_WORK_MODE, DEVICE_CLASS_TUYA_LED_TYPE, DEVICE_CLASS_TUYA_LIGHT_MODE, + DEVICE_CLASS_TUYA_MOTION_SENSITIVITY, + DEVICE_CLASS_TUYA_RECORD_MODE, DEVICE_CLASS_TUYA_RELAY_STATUS, DOMAIN, TUYA_DISCOVERY_NEW, @@ -83,6 +89,51 @@ SELECTS: dict[str, tuple[SelectEntityDescription, ...]] = { entity_category=ENTITY_CATEGORY_CONFIG, ), ), + # Smart Camera + # https://developer.tuya.com/en/docs/iot/categorysp?id=Kaiuz35leyo12 + "sp": ( + SelectEntityDescription( + key=DPCode.IPC_WORK_MODE, + name="IPC Mode", + device_class=DEVICE_CLASS_TUYA_IPC_WORK_MODE, + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SelectEntityDescription( + key=DPCode.DECIBEL_SENSITIVITY, + name="Sound Detection Sensitivity", + icon="mdi:volume-vibrate", + device_class=DEVICE_CLASS_TUYA_DECIBEL_SENSITIVITY, + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SelectEntityDescription( + key=DPCode.RECORD_MODE, + name="Record Mode", + icon="mdi:record-rec", + device_class=DEVICE_CLASS_TUYA_RECORD_MODE, + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SelectEntityDescription( + key=DPCode.BASIC_NIGHTVISION, + name="Night Vision", + icon="mdi:theme-light-dark", + device_class=DEVICE_CLASS_TUYA_BASIC_NIGHTVISION, + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SelectEntityDescription( + key=DPCode.BASIC_ANTI_FLICKER, + name="Anti-flicker", + icon="mdi:image-outline", + device_class=DEVICE_CLASS_TUYA_BASIC_ANTI_FLICKR, + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SelectEntityDescription( + key=DPCode.MOTION_SENSITIVITY, + name="Motion Detection Sensitivity", + icon="mdi:motion-sensor", + device_class=DEVICE_CLASS_TUYA_MOTION_SENSITIVITY, + entity_category=ENTITY_CATEGORY_CONFIG, + ), + ), # Dimmer Switch # https://developer.tuya.com/en/docs/iot/categorytgkg?id=Kaiuz0ktx7m0o "tgkg": ( diff --git a/homeassistant/components/tuya/sensor.py b/homeassistant/components/tuya/sensor.py index 2e0b1562ff1..f67d8f1c242 100644 --- a/homeassistant/components/tuya/sensor.py +++ b/homeassistant/components/tuya/sensor.py @@ -238,6 +238,29 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { # Emergency Button # https://developer.tuya.com/en/docs/iot/categorysos?id=Kaiuz3oi6agjy "sos": BATTERY_SENSORS, + # Smart Camera + # https://developer.tuya.com/en/docs/iot/categorysp?id=Kaiuz35leyo12 + "sp": ( + SensorEntityDescription( + key=DPCode.SENSOR_TEMPERATURE, + name="Temperature", + device_class=DEVICE_CLASS_TEMPERATURE, + state_class=STATE_CLASS_MEASUREMENT, + ), + SensorEntityDescription( + key=DPCode.SENSOR_HUMIDITY, + name="Humidity", + device_class=DEVICE_CLASS_HUMIDITY, + state_class=STATE_CLASS_MEASUREMENT, + ), + SensorEntityDescription( + key=DPCode.WIRELESS_ELECTRICITY, + name="Battery", + device_class=DEVICE_CLASS_BATTERY, + entity_category=ENTITY_CATEGORY_DIAGNOSTIC, + state_class=STATE_CLASS_MEASUREMENT, + ), + ), # Pressure Sensor # https://developer.tuya.com/en/docs/iot/categoryylcg?id=Kaiuz3kc2e4gm "ylcg": ( diff --git a/homeassistant/components/tuya/siren.py b/homeassistant/components/tuya/siren.py index 42b1f6839f5..bfdca70ac25 100644 --- a/homeassistant/components/tuya/siren.py +++ b/homeassistant/components/tuya/siren.py @@ -27,6 +27,14 @@ SIRENS: dict[str, tuple[SirenEntityDescription, ...]] = { name="Siren", ), ), + # Smart Camera + # https://developer.tuya.com/en/docs/iot/categorysp?id=Kaiuz35leyo12 + "sp": ( + SirenEntityDescription( + key=DPCode.SIREN_SWITCH, + name="Siren", + ), + ), } diff --git a/homeassistant/components/tuya/strings.select.json b/homeassistant/components/tuya/strings.select.json index 38d3e7c4a20..ccc78704166 100644 --- a/homeassistant/components/tuya/strings.select.json +++ b/homeassistant/components/tuya/strings.select.json @@ -1,5 +1,23 @@ { "state": { + "tuya__basic_anti_flickr": { + "0": "Disabled", + "1": "50 Hz", + "2": "60 Hz" + }, + "tuya__basic_nightvision": { + "0": "Automatic", + "1": "[%key:common::state::off%]", + "2": "[%key:common::state::on%]" + }, + "tuya__decibel_sensitivity": { + "0": "Low sensitivity", + "1": "High sensitivity" + }, + "tuya__ipc_work_mode": { + "0": "Low power mode", + "1": "Continuous working mode" + }, "tuya__led_type": { "halogen": "Halogen", "incandescent": "Incandescent", @@ -10,6 +28,15 @@ "pos": "Indicate switch location", "relay": "Indicate switch on/off state" }, + "tuya__motion_sensitivity": { + "0": "Low sensitivity", + "1": "Medium sensitivity", + "2": "High sensitivity" + }, + "tuya__record_mode": { + "1": "Record events only", + "2": "Continuous recording" + }, "tuya__relay_status": { "last": "Remember last state", "memory": "Remember last state", diff --git a/homeassistant/components/tuya/switch.py b/homeassistant/components/tuya/switch.py index 8f5b2715731..d27fe764541 100644 --- a/homeassistant/components/tuya/switch.py +++ b/homeassistant/components/tuya/switch.py @@ -272,6 +272,76 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = { entity_category=ENTITY_CATEGORY_CONFIG, ), ), + # Smart Camera + # https://developer.tuya.com/en/docs/iot/categorysp?id=Kaiuz35leyo12 + "sp": ( + SwitchEntityDescription( + key=DPCode.WIRELESS_BATTERYLOCK, + name="Battery Lock", + icon="mdi:battery-lock", + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SwitchEntityDescription( + key=DPCode.CRY_DETECTION_SWITCH, + icon="mdi:emoticon-cry", + name="Cry Detection", + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SwitchEntityDescription( + key=DPCode.DECIBEL_SWITCH, + icon="mdi:microphone-outline", + name="Sound Detection", + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SwitchEntityDescription( + key=DPCode.RECORD_SWITCH, + icon="mdi:record-rec", + name="Video Recording", + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SwitchEntityDescription( + key=DPCode.MOTION_RECORD, + icon="mdi:record-rec", + name="Motion Recording", + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SwitchEntityDescription( + key=DPCode.BASIC_PRIVATE, + icon="mdi:eye-off", + name="Privacy Mode", + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SwitchEntityDescription( + key=DPCode.BASIC_FLIP, + icon="mdi:flip-horizontal", + name="Flip", + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SwitchEntityDescription( + key=DPCode.BASIC_OSD, + icon="mdi:watermark", + name="Time Watermark", + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SwitchEntityDescription( + key=DPCode.BASIC_WDR, + icon="mdi:watermark", + name="Wide Dynamic Range", + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SwitchEntityDescription( + key=DPCode.MOTION_TRACKING, + icon="mdi:motion-sensor", + name="Motion Tracking", + entity_category=ENTITY_CATEGORY_CONFIG, + ), + SwitchEntityDescription( + key=DPCode.MOTION_SWITCH, + icon="mdi:motion-sensor", + name="Motion Alarm", + entity_category=ENTITY_CATEGORY_CONFIG, + ), + ), # Ceiling Light # https://developer.tuya.com/en/docs/iot/ceiling-light?id=Kaiuz03xxfc4r "xdd": ( diff --git a/homeassistant/components/tuya/translations/select.en.json b/homeassistant/components/tuya/translations/select.en.json index 70ef9486196..7ac1f656d87 100644 --- a/homeassistant/components/tuya/translations/select.en.json +++ b/homeassistant/components/tuya/translations/select.en.json @@ -1,5 +1,23 @@ { "state": { + "tuya__basic_anti_flickr": { + "0": "Disabled", + "1": "50 Hz", + "2": "60 Hz" + }, + "tuya__basic_nightvision": { + "0": "Automatic", + "1": "Off", + "2": "On" + }, + "tuya__decibel_sensitivity": { + "0": "Low sensitivity", + "1": "High sensitivity" + }, + "tuya__ipc_work_mode": { + "0": "Low power mode", + "1": "Continuous working mode" + }, "tuya__led_type": { "halogen": "Halogen", "incandescent": "Incandescent", @@ -10,6 +28,15 @@ "pos": "Indicate switch location", "relay": "Indicate switch on/off state" }, + "tuya__motion_sensitivity": { + "0": "Low sensitivity", + "1": "Medium sensitivity", + "2": "High sensitivity" + }, + "tuya__record_mode": { + "1": "Record events only", + "2": "Continuous recording" + }, "tuya__relay_status": { "last": "Remember last state", "memory": "Remember last state",