mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 10:44:04 +00:00
Fix repr for device created with no sysinfo or discovery info" (#1266)
Co-authored-by: Teemu R. <tpr@iki.fi>
This commit is contained in:
@@ -107,16 +107,26 @@ class SmartChildDevice(SmartDevice):
|
||||
@property
|
||||
def device_type(self) -> DeviceType:
|
||||
"""Return child device type."""
|
||||
category = self.sys_info["category"]
|
||||
dev_type = self.CHILD_DEVICE_TYPE_MAP.get(category)
|
||||
if dev_type is None:
|
||||
_LOGGER.warning(
|
||||
"Unknown child device type %s for model %s, please open issue",
|
||||
category,
|
||||
self.model,
|
||||
)
|
||||
dev_type = DeviceType.Unknown
|
||||
return dev_type
|
||||
if self._device_type is not DeviceType.Unknown:
|
||||
return self._device_type
|
||||
|
||||
if self.sys_info and (category := self.sys_info.get("category")):
|
||||
dev_type = self.CHILD_DEVICE_TYPE_MAP.get(category)
|
||||
if dev_type is None:
|
||||
_LOGGER.warning(
|
||||
"Unknown child device type %s for model %s, please open issue",
|
||||
category,
|
||||
self.model,
|
||||
)
|
||||
self._device_type = DeviceType.Unknown
|
||||
else:
|
||||
self._device_type = dev_type
|
||||
|
||||
return self._device_type
|
||||
|
||||
def __repr__(self) -> str:
|
||||
if not self._parent:
|
||||
return f"<{self.device_type}(child) without parent>"
|
||||
if not self._parent._last_update:
|
||||
return f"<{self.device_type}(child) of {self._parent}>"
|
||||
return f"<{self.device_type} {self.alias} ({self.model}) of {self._parent}>"
|
||||
|
@@ -757,6 +757,10 @@ class SmartDevice(Device):
|
||||
|
||||
# Fallback to device_type (from disco info)
|
||||
type_str = self._info.get("type", self._info.get("device_type"))
|
||||
|
||||
if not type_str: # no update or discovery info
|
||||
return self._device_type
|
||||
|
||||
self._device_type = self._get_device_type_from_components(
|
||||
list(self._components.keys()), type_str
|
||||
)
|
||||
|
Reference in New Issue
Block a user