Skip to content

Commit

Permalink
Auto configure: Fix Name -> name
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou authored Nov 10, 2023
1 parent aedf07b commit c7dbb6f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
15 changes: 15 additions & 0 deletions custom_components/localtuya/core/tuya_devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def generate_tuya_device(localtuya_data: dict, tuya_category: str) -> dict | lis
"""Create localtuya configs using the data that provided from TUYA"""
detected_dps: list = localtuya_data.get(CONF_DPS_STRINGS)
device_name: str = localtuya_data.get(CONF_FRIENDLY_NAME).strip()
device_cloud_data: dict = localtuya_data.get("device_cloud_data")
ent_data: LocalTuyaEntity

if not tuya_category or not detected_dps:
Expand Down Expand Up @@ -137,3 +138,17 @@ def parse_enum(dp_code):
parsed_dp_code = dp_code

return parsed_dp_code


def merge_local_cloud_dps(dps_strings: list, cloud_dps_data: dict[str, dict]):
"""Merge founded dps_string with dps_data in cloud data"""
merged_list = dps_strings
dps_strings_dict = {dp.split(" ", 1)[0]: dp.split(" ", 1)[1] for dp in dps_strings}

for dp, value in cloud_dps_data.items():
if dp not in dps_strings_dict:
merged_list.append(
f"{dp} ( code: {value.get('code')} , value: {value.get('value')} )"
)

return sorted(merged_list, key=lambda i: int(i.split()[0]))
2 changes: 2 additions & 0 deletions custom_components/localtuya/core/tuya_devices/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,11 @@ class DPCode(StrEnum):
RECORD_SWITCH = "record_switch" # Recording switch
RELAY_STATUS = "relay_status"
REMAIN_TIME = "remain_time"
REMOTE_REGISTER = "remote_register"
RESET_DUSTER_CLOTH = "reset_duster_cloth"
RESET_EDGE_BRUSH = "reset_edge_brush"
RESET_FILTER = "reset_filter"
RESET_LIMIT = "reset_limit"
RESET_MAP = "reset_map"
RESET_ROLL_BRUSH = "reset_roll_brush"
ROLL_BRUSH = "roll_brush"
Expand Down
23 changes: 17 additions & 6 deletions custom_components/localtuya/core/tuya_devices/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,47 @@
from .base import DPCode, LocalTuyaEntity, CONF_DEVICE_CLASS, EntityCategory

BUTTONS: dict[LocalTuyaEntity] = {
# Curtain
# Note: Multiple curtains isn't documented
# https://developer.tuya.com/en/docs/iot/categorycl?id=Kaiuz1hnpo7df
"cl": (
LocalTuyaEntity(
id=DPCode.REMOTE_REGISTER,
name="Pair Remote",
icon="mdi:remote",
entity_category=EntityCategory.CONFIG,
),
),
# Robot Vacuum
# https://developer.tuya.com/en/docs/iot/fsd?id=K9gf487ck1tlo
"sd": (
LocalTuyaEntity(
id=DPCode.RESET_DUSTER_CLOTH,
Name="Reset Duster Cloth",
name="Reset Duster Cloth",
icon="mdi:restart",
entity_category=EntityCategory.CONFIG,
),
LocalTuyaEntity(
id=DPCode.RESET_EDGE_BRUSH,
Name="Reset Edge Brush",
name="Reset Edge Brush",
icon="mdi:restart",
entity_category=EntityCategory.CONFIG,
),
LocalTuyaEntity(
id=DPCode.RESET_FILTER,
Name="Reset Filter",
name="Reset Filter",
icon="mdi:air-filter",
entity_category=EntityCategory.CONFIG,
),
LocalTuyaEntity(
id=DPCode.RESET_MAP,
Name="Reset Map",
name="Reset Map",
icon="mdi:map-marker-remove",
entity_category=EntityCategory.CONFIG,
),
LocalTuyaEntity(
id=DPCode.RESET_ROLL_BRUSH,
Name="Reset Roll Brush",
name="Reset Roll Brush",
icon="mdi:restart",
entity_category=EntityCategory.CONFIG,
),
Expand All @@ -47,7 +58,7 @@
"hxd": (
LocalTuyaEntity(
id=DPCode.SWITCH_USB6,
Name="Snooze",
name="Snooze",
icon="mdi:sleep",
),
),
Expand Down

0 comments on commit c7dbb6f

Please sign in to comment.