From d64fc6820f0939daae4605d5776f80d7ff21834f Mon Sep 17 00:00:00 2001 From: xZetsubou Date: Wed, 15 May 2024 00:53:09 +0300 Subject: [PATCH] Add motion sensor DPCodes and "tdq" category. #231 #232 * Motion sensor added "pir_state" possibility. * Motion sensor add Pir Sensitivity. * Motion sensor add reset time. " Dimmer add new category "tdq" --- .../localtuya/core/ha_entities/base.py | 2 ++ .../core/ha_entities/binary_sensors.py | 2 +- .../localtuya/core/ha_entities/lights.py | 8 ++++--- .../localtuya/core/ha_entities/selects.py | 21 ++++++++++++++++++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/custom_components/localtuya/core/ha_entities/base.py b/custom_components/localtuya/core/ha_entities/base.py index c79f19a94..0bb6e358f 100644 --- a/custom_components/localtuya/core/ha_entities/base.py +++ b/custom_components/localtuya/core/ha_entities/base.py @@ -389,6 +389,8 @@ class DPCode(StrEnum): PHOTO_MODE = "photo_mode" PIR = "pir" # Motion sensor PIR_SENSITIVITY = "pir_sensitivity" + PIR_STATE = "pir_state" + PIR_TIME = "pir_time" PLAY_INFO = "play_info" PLAY_MODE = "play_mode" PLAY_TIME = "play_time" diff --git a/custom_components/localtuya/core/ha_entities/binary_sensors.py b/custom_components/localtuya/core/ha_entities/binary_sensors.py index e25a251b0..748e5a77a 100644 --- a/custom_components/localtuya/core/ha_entities/binary_sensors.py +++ b/custom_components/localtuya/core/ha_entities/binary_sensors.py @@ -279,7 +279,7 @@ def localtuya_binarySensor(state_on="1"): # https://developer.tuya.com/en/docs/iot/categorypir?id=Kaiuz3ss11b80 "pir": ( LocalTuyaEntity( - id=DPCode.PIR, + id=(DPCode.PIR, DPCode.PIR_STATE), device_class=BinarySensorDeviceClass.MOTION, custom_configs={CONF_STATE_ON: "pir"}, ), diff --git a/custom_components/localtuya/core/ha_entities/lights.py b/custom_components/localtuya/core/ha_entities/lights.py index 0085d3137..dfc580b9e 100644 --- a/custom_components/localtuya/core/ha_entities/lights.py +++ b/custom_components/localtuya/core/ha_entities/lights.py @@ -261,7 +261,6 @@ def localtuya_light( "tgkg": ( LocalTuyaEntity( id=DPCode.SWITCH_LED_1, - name="light", brightness=DPCode.BRIGHT_VALUE_1, brightness_upper=DPCode.BRIGHTNESS_MAX_1, brightness_lower=DPCode.BRIGHTNESS_MIN_1, @@ -269,7 +268,7 @@ def localtuya_light( ), LocalTuyaEntity( id=DPCode.SWITCH_LED_2, - name="light_2", + name="Light 2", brightness=DPCode.BRIGHT_VALUE_2, brightness_upper=DPCode.BRIGHTNESS_MAX_2, brightness_lower=DPCode.BRIGHTNESS_MIN_2, @@ -277,7 +276,7 @@ def localtuya_light( ), LocalTuyaEntity( id=DPCode.SWITCH_LED_3, - name="light_3", + name="Light 3", brightness=DPCode.BRIGHT_VALUE_3, brightness_upper=DPCode.BRIGHTNESS_MAX_3, brightness_lower=DPCode.BRIGHTNESS_MIN_3, @@ -399,6 +398,9 @@ def localtuya_light( *LIGHTS["dj"], ) +# Dimmer +LIGHTS["tdq"] = LIGHTS["tgkg"] + # Scene Switch # https://developer.tuya.com/en/docs/iot/f?id=K9gf7nx6jelo8 LIGHTS["cjkg"] = LIGHTS["tgkg"] diff --git a/custom_components/localtuya/core/ha_entities/selects.py b/custom_components/localtuya/core/ha_entities/selects.py index c73ba85bc..00a528e4f 100644 --- a/custom_components/localtuya/core/ha_entities/selects.py +++ b/custom_components/localtuya/core/ha_entities/selects.py @@ -554,8 +554,9 @@ def localtuya_selector(options): ), LocalTuyaEntity( id=DPCode.PIR_SENSITIVITY, + icon="mdi:ray-start-arrow", entity_category=EntityCategory.CONFIG, - name="PIR sensitivity", + name="PIR Sensitivity", custom_configs=localtuya_selector({"0": "Low", "1": "Medium", "2": "High"}), ), ), @@ -966,6 +967,24 @@ def localtuya_selector(options): {"mode_auto": "AUTO", "mode_on": "ON", "mode_off": "OFF"} ), ), + LocalTuyaEntity( + id=DPCode.PIR_SENSITIVITY, + icon="mdi:ray-start-arrow", + entity_category=EntityCategory.CONFIG, + name="PIR Sensitivity", + custom_configs=localtuya_selector( + {"low": "Low", "middle": "Middle", "high": "High"} + ), + ), + LocalTuyaEntity( + id=DPCode.PIR_TIME, + icon="mdi:timer-sand", + entity_category=EntityCategory.CONFIG, + name="Reset Time", + custom_configs=localtuya_selector( + {"30s": "30 Seconds", "60s": "60 Seconds", "120s": "120 Seconds"} + ), + ), ), # Thermostat # https://developer.tuya.com/en/docs/iot/f?id=K9gf45ld5l0t9