Skip to content

Commit

Permalink
Auto configure add znsb category #144
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou committed Feb 17, 2024
1 parent c70dcce commit 46cadfe
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
6 changes: 6 additions & 0 deletions custom_components/localtuya/core/ha_entities/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class DPCode(StrEnum):
ARM_DOWN_PERCENT = "arm_down_percent"
ARM_UP_PERCENT = "arm_up_percent"
AUTOMATIC_LOCK = "automatic_lock"
AUTO_CLEAN = "auto_clean"
AUTO_LOCK_TIME = "auto_lock_time"
BACKLIGHT_SWITCH = "backlight_switch"
BASIC_ANTI_FLICKER = "basic_anti_flicker"
Expand Down Expand Up @@ -366,6 +367,7 @@ class DPCode(StrEnum):
RELAY_STATUS_8 = "relay_status_8" # Scene Switch cjkg
REMAIN_TIME = "remain_time"
REMOTE_REGISTER = "remote_register"
REPORT_PERIOD_SET = "report_period_set"
RESET_DUSTER_CLOTH = "reset_duster_cloth"
RESET_EDGE_BRUSH = "reset_edge_brush"
RESET_FILTER = "reset_filter"
Expand Down Expand Up @@ -457,6 +459,7 @@ class DPCode(StrEnum):
SWITCH_ALARM_SOUND = "switch_alarm_sound"
SWITCH_BACKLIGHT = "switch_backlight" # Backlight switch
SWITCH_CHARGE = "switch_charge"
SWITCH_COLD = "switch_cold"
SWITCH_CONTROLLER = "switch_controller"
SWITCH_DISTURB = "switch_disturb"
SWITCH_FAN = "switch_fan"
Expand Down Expand Up @@ -554,6 +557,7 @@ class DPCode(StrEnum):
VOICE_SWITCH = "voice_switch"
VOICE_TIMES = "voice_times"
VOICE_VOL = "voice_vol"
VOLTAGE_CURRENT = "voltage_current"
VOLUME_SET = "volume_set"
WARM = "warm" # Heat preservation
WARM_TIME = "warm_time" # Heat preservation time
Expand All @@ -564,6 +568,8 @@ class DPCode(StrEnum):
WATERSENSOR_STATE = "watersensor_state"
WATER_RESET = "water_reset" # Resetting of water usage days
WATER_SET = "water_set" # Water level
WATER_TEMP = "water_temp"
WATER_USE_DATA = "water_use_data"
WET = "wet" # Humidification
WINDOWDETECT = "windowdetect"
WINDOW_CHECK = "window_check"
Expand Down
24 changes: 24 additions & 0 deletions custom_components/localtuya/core/ha_entities/selects.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,30 @@ def localtuya_selector(options):
),
),
),
# Smart Water Meter
# https://developer.tuya.com/en/docs/iot/f?id=Ka8n052xu7w4c
"znsb": (
LocalTuyaEntity(
id=DPCode.REPORT_PERIOD_SET,
entity_category=EntityCategory.CONFIG,
name="Report Period",
custom_configs=localtuya_selector(
{
"1h": "1 Hours",
"2h": "2 Hours",
"3h": "3 Hours",
"4h": "4 Hours",
"6h": "6 Hours",
"8h": "8 Hours",
"12h": "12 Hours",
"24h": "24 Hours",
"48h": "48 Hours",
"72h": "72 Hours",
}
),
icon="mdi:file-chart-outline",
),
),
}
# Wireless Switch # also can come as knob switch. # and scene switch.
# https://developer.tuya.com/en/docs/iot/wxkg?id=Kbeo9t3ryuqm5
Expand Down
30 changes: 29 additions & 1 deletion custom_components/localtuya/core/ha_entities/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
PERCENTAGE,
UnitOfElectricCurrent,
UnitOfElectricPotential,
UnitOfPower,
UnitOfTime,
CONF_UNIT_OF_MEASUREMENT,
UnitOfTemperature,
UnitOfEnergy,
UnitOfVolume,
UnitOfElectricPotential,
)

from .base import (
Expand Down Expand Up @@ -1296,6 +1297,33 @@ def localtuya_sensor(unit_of_measurement=None, scale_factor: float = None) -> di
entity_category=EntityCategory.DIAGNOSTIC,
),
),
# Smart Water Meter
# https://developer.tuya.com/en/docs/iot/f?id=Ka8n052xu7w4c
"znsb": (
LocalTuyaEntity(
id=DPCode.WATER_USE_DATA,
name="Total Water Consumption",
icon="mdi:water-outline",
device_class=SensorDeviceClass.WATER,
state_class=SensorStateClass.TOTAL_INCREASING,
custom_configs=localtuya_sensor(UnitOfVolume.LITERS, 1),
),
LocalTuyaEntity(
id=DPCode.WATER_TEMP,
name="Temperature",
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
custom_configs=localtuya_sensor(UnitOfTemperature.CELSIUS, 0.01),
),
LocalTuyaEntity(
id=DPCode.VOLTAGE_CURRENT,
name="Battery",
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
custom_configs=localtuya_sensor(UnitOfElectricPotential.VOLT, 0.01),
),
),
}

# Socket (duplicate of `kg`)
Expand Down
15 changes: 15 additions & 0 deletions custom_components/localtuya/core/ha_entities/switches.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,21 @@
entity_category=EntityCategory.CONFIG,
),
),
# Smart Water Meter
# https://developer.tuya.com/en/docs/iot/f?id=Ka8n052xu7w4c
"znsb": (
LocalTuyaEntity(
id=DPCode.SWITCH_COLD,
name="Valve",
icon="mdi:Valve",
),
LocalTuyaEntity(
id=DPCode.AUTO_CLEAN,
name="Auto Clean",
icon="mdi:auto-fix",
entity_category=EntityCategory.CONFIG,
),
),
}

# Scene Switch
Expand Down

0 comments on commit 46cadfe

Please sign in to comment.