mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Fix D-Link attributes (#86842)
* Fix D-Link attributes * fix blocking call
This commit is contained in:
parent
0f6f63da64
commit
799edd90aa
@ -19,9 +19,9 @@ class SmartPlugData:
|
|||||||
"""Initialize the data object."""
|
"""Initialize the data object."""
|
||||||
self.smartplug = smartplug
|
self.smartplug = smartplug
|
||||||
self.state: str | None = None
|
self.state: str | None = None
|
||||||
self.temperature: str | None = None
|
self.temperature: str = ""
|
||||||
self.current_consumption = None
|
self.current_consumption: str = ""
|
||||||
self.total_consumption: str | None = None
|
self.total_consumption: str = ""
|
||||||
self.available = False
|
self.available = False
|
||||||
self._n_tried = 0
|
self._n_tried = 0
|
||||||
self._last_tried: datetime | None = None
|
self._last_tried: datetime | None = None
|
||||||
|
@ -94,17 +94,22 @@ class SmartPlugSwitch(DLinkEntity, SwitchEntity):
|
|||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict[str, Any]:
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the state attributes of the device."""
|
"""Return the state attributes of the device."""
|
||||||
attrs: dict[str, Any] = {}
|
try:
|
||||||
if self.data.temperature and self.data.temperature.isnumeric():
|
temperature = self.hass.config.units.temperature(
|
||||||
attrs[ATTR_TEMPERATURE] = self.hass.config.units.temperature(
|
|
||||||
int(self.data.temperature), UnitOfTemperature.CELSIUS
|
int(self.data.temperature), UnitOfTemperature.CELSIUS
|
||||||
)
|
)
|
||||||
else:
|
except ValueError:
|
||||||
attrs[ATTR_TEMPERATURE] = None
|
temperature = None
|
||||||
if self.data.total_consumption and self.data.total_consumption.isnumeric():
|
|
||||||
attrs[ATTR_TOTAL_CONSUMPTION] = float(self.data.total_consumption)
|
try:
|
||||||
else:
|
total_consumption = float(self.data.total_consumption)
|
||||||
attrs[ATTR_TOTAL_CONSUMPTION] = None
|
except ValueError:
|
||||||
|
total_consumption = None
|
||||||
|
|
||||||
|
attrs = {
|
||||||
|
ATTR_TOTAL_CONSUMPTION: total_consumption,
|
||||||
|
ATTR_TEMPERATURE: temperature,
|
||||||
|
}
|
||||||
|
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user