Skip to content

Commit

Permalink
feat: Add via_device for subdevice for homeassistant topology
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou committed Nov 19, 2024
1 parent 6a902e6 commit 248513c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions custom_components/localtuya/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(
self._entry = entry
self._hass_entry: HassLocalTuyaData = hass.data[DOMAIN][entry.entry_id]
self._device_config = DeviceConfig(device_config.copy())
self.id = self._device_config.id

self._status = {}
self._interface = None
Expand Down
12 changes: 10 additions & 2 deletions custom_components/localtuya/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
EntityCategory,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
ATTR_VIA_DEVICE,
)
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.dispatcher import (
Expand Down Expand Up @@ -207,15 +208,17 @@ def extra_state_attributes(self):
def device_info(self) -> DeviceInfo:
"""Return device information for the device registry."""
model = self._device_config.model

return DeviceInfo(
device_info = DeviceInfo(
# Serial numbers are unique identifiers within a specific domain
identifiers={(DOMAIN, f"local_{self._device_config.id}")},
name=self._device_config.name,
manufacturer="Tuya",
model=f"{model} ({self._device_config.id})",
sw_version=self._device_config.protocol_version,
)
if self._device.is_subdevice:
device_info[ATTR_VIA_DEVICE] = (DOMAIN, f"local_{self._device.gateway.id}")
return device_info

@property
def name(self) -> str:
Expand Down Expand Up @@ -258,6 +261,11 @@ def device_class(self):
"""Return the class of this device."""
return self._config.get(CONF_DEVICE_CLASS, self._attr_device_class)

@property
def write_only_device(self):
"""Return if this device write-only, if the device sent any payload this will be false."""
return self._device._status == RESTORE_STATES

def has_config(self, attr) -> bool:
"""Return if a config parameter has a valid value."""
value = self._config.get(attr, "-1")
Expand Down

0 comments on commit 248513c

Please sign in to comment.