Skip to content

Commit

Permalink
Add Eletricity sensor and fix UoM for current #109
Browse files Browse the repository at this point in the history
* Lights add scene data and colour data for "dd" category
  • Loading branch information
xZetsubou committed Jan 13, 2024
1 parent 9fe1d10 commit 3a6441f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions custom_components/localtuya/core/ha_entities/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class DPCode(StrEnum):
https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq
"""

ADD_ELE = "add_ele"
AIR_QUALITY = "air_quality"
ALARM_LOCK = "alarm_lock"
ALARM_MESSAGE = "alarm_message"
Expand Down
7 changes: 4 additions & 3 deletions custom_components/localtuya/core/ha_entities/lights.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ def localtuya_light(
id=DPCode.SWITCH_LED,
name=None,
color_mode=DPCode.WORK_MODE,
brightness=DPCode.BRIGHT_VALUE,
color_temp=DPCode.TEMP_VALUE,
color=DPCode.COLOUR_DATA,
brightness=(DPCode.BRIGHT_VALUE_V2, DPCode.BRIGHT_VALUE),
color_temp=(DPCode.TEMP_VALUE_V2, DPCode.TEMP_VALUE),
color=(DPCode.COLOUR_DATA_V2, DPCode.COLOUR_DATA),
scene=(DPCode.SCENE_DATA_V2, DPCode.SCENE_DATA),
custom_configs=localtuya_light(29, 1000, 2700, 6500, False, False)
# default_color_type=DEFAULT_COLOR_TYPE_DATA_V2,
),
Expand Down
39 changes: 29 additions & 10 deletions custom_components/localtuya/core/ha_entities/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
UnitOfTime,
CONF_UNIT_OF_MEASUREMENT,
UnitOfTemperature,
UnitOfEnergy,
)

from .base import DPCode, LocalTuyaEntity, CONF_DEVICE_CLASS, EntityCategory
Expand Down Expand Up @@ -353,7 +354,7 @@ def localtuya_sensor(unit_of_measurement=None, scale_factor: float = None) -> di
name="Power",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
custom_configs=localtuya_sensor(UnitOfPower.KILO_WATT, 0.1),
custom_configs=localtuya_sensor(UnitOfPower.WATT, 0.1),
),
LocalTuyaEntity(
id=DPCode.CUR_VOLTAGE,
Expand All @@ -362,6 +363,12 @@ def localtuya_sensor(unit_of_measurement=None, scale_factor: float = None) -> di
state_class=SensorStateClass.MEASUREMENT,
custom_configs=localtuya_sensor(UnitOfElectricPotential.VOLT, 0.1),
),
LocalTuyaEntity(
id=DPCode.ADD_ELE,
name="Electricity",
device_class=SensorDeviceClass.ENERGY,
custom_configs=localtuya_sensor(UnitOfEnergy.KILO_WATT_HOUR, 0.001),
),
),
# IoT Switch
# Note: Undocumented
Expand All @@ -379,7 +386,7 @@ def localtuya_sensor(unit_of_measurement=None, scale_factor: float = None) -> di
name="Power",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
custom_configs=localtuya_sensor(UnitOfPower.KILO_WATT, 0.1),
custom_configs=localtuya_sensor(UnitOfPower.WATT, 0.1),
# entity_registry_enabled_default=False,
),
LocalTuyaEntity(
Expand All @@ -390,6 +397,12 @@ def localtuya_sensor(unit_of_measurement=None, scale_factor: float = None) -> di
custom_configs=localtuya_sensor(UnitOfElectricPotential.VOLT, 0.1),
# entity_registry_enabled_default=False,
),
LocalTuyaEntity(
id=DPCode.ADD_ELE,
name="Electricity",
device_class=SensorDeviceClass.ENERGY,
custom_configs=localtuya_sensor(UnitOfEnergy.KILO_WATT_HOUR, 0.001),
),
),
# Luminance Sensor
# https://developer.tuya.com/en/docs/iot/categoryldcg?id=Kaiuz3n7u69l8
Expand Down Expand Up @@ -530,7 +543,7 @@ def localtuya_sensor(unit_of_measurement=None, scale_factor: float = None) -> di
name="Power",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
custom_configs=localtuya_sensor(UnitOfPower.KILO_WATT, 0.1),
custom_configs=localtuya_sensor(UnitOfPower.WATT, 0.1),
),
),
# Gas Detector
Expand Down Expand Up @@ -716,7 +729,7 @@ def localtuya_sensor(unit_of_measurement=None, scale_factor: float = None) -> di
name="Phase C Power",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
custom_configs=localtuya_sensor(UnitOfPower.KILO_WATT, 0.1),
custom_configs=localtuya_sensor(UnitOfPower.WATT, 0.1),
),
LocalTuyaEntity(
id=DPCode.PHASE_A,
Expand All @@ -737,7 +750,7 @@ def localtuya_sensor(unit_of_measurement=None, scale_factor: float = None) -> di
name="Phase B Power",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
custom_configs=localtuya_sensor(UnitOfPower.KILO_WATT, 0.1),
custom_configs=localtuya_sensor(UnitOfPower.WATT, 0.1),
),
LocalTuyaEntity(
id=DPCode.PHASE_B,
Expand All @@ -758,7 +771,7 @@ def localtuya_sensor(unit_of_measurement=None, scale_factor: float = None) -> di
name="Phase C Power",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
custom_configs=localtuya_sensor(UnitOfPower.KILO_WATT, 0.1),
custom_configs=localtuya_sensor(UnitOfPower.WATT, 0.1),
),
LocalTuyaEntity(
id=DPCode.PHASE_C,
Expand Down Expand Up @@ -789,7 +802,7 @@ def localtuya_sensor(unit_of_measurement=None, scale_factor: float = None) -> di
name="Phase C Power",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
custom_configs=localtuya_sensor(UnitOfPower.KILO_WATT, 0.1),
custom_configs=localtuya_sensor(UnitOfPower.WATT, 0.1),
),
LocalTuyaEntity(
id=DPCode.PHASE_A,
Expand All @@ -810,7 +823,7 @@ def localtuya_sensor(unit_of_measurement=None, scale_factor: float = None) -> di
name="Phase B Power",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
custom_configs=localtuya_sensor(UnitOfPower.KILO_WATT, 0.1),
custom_configs=localtuya_sensor(UnitOfPower.WATT, 0.1),
),
LocalTuyaEntity(
id=DPCode.PHASE_B,
Expand All @@ -831,7 +844,7 @@ def localtuya_sensor(unit_of_measurement=None, scale_factor: float = None) -> di
name="Phase C Power",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
custom_configs=localtuya_sensor(UnitOfPower.KILO_WATT, 0.1),
custom_configs=localtuya_sensor(UnitOfPower.WATT, 0.1),
),
LocalTuyaEntity(
id=DPCode.PHASE_C,
Expand Down Expand Up @@ -1037,7 +1050,7 @@ def localtuya_sensor(unit_of_measurement=None, scale_factor: float = None) -> di
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
custom_configs=localtuya_sensor(UnitOfPower.KILO_WATT, 0.1),
custom_configs=localtuya_sensor(UnitOfPower.WATT, 0.1),
# entity_registry_enabled_default=False,
),
LocalTuyaEntity(
Expand All @@ -1049,6 +1062,12 @@ def localtuya_sensor(unit_of_measurement=None, scale_factor: float = None) -> di
custom_configs=localtuya_sensor(UnitOfElectricPotential.VOLT, 0.1),
# entity_registry_enabled_default=False,
),
LocalTuyaEntity(
id=DPCode.ADD_ELE,
name="Electricity",
device_class=SensorDeviceClass.ENERGY,
custom_configs=localtuya_sensor(UnitOfEnergy.KILO_WATT_HOUR, 0.001),
),
),
# Dehumidifier
# https://developer.tuya.com/en/docs/iot/s?id=K9gf48r6jke8e
Expand Down

0 comments on commit 3a6441f

Please sign in to comment.