Fix D-Link attributes (#86842)
* Fix D-Link attributes * fix blocking call
This commit is contained in:
parent
0f6f63da64
commit
799edd90aa
2 changed files with 17 additions and 12 deletions
|
@ -19,9 +19,9 @@ class SmartPlugData:
|
|||
"""Initialize the data object."""
|
||||
self.smartplug = smartplug
|
||||
self.state: str | None = None
|
||||
self.temperature: str | None = None
|
||||
self.current_consumption = None
|
||||
self.total_consumption: str | None = None
|
||||
self.temperature: str = ""
|
||||
self.current_consumption: str = ""
|
||||
self.total_consumption: str = ""
|
||||
self.available = False
|
||||
self._n_tried = 0
|
||||
self._last_tried: datetime | None = None
|
||||
|
|
|
@ -94,17 +94,22 @@ class SmartPlugSwitch(DLinkEntity, SwitchEntity):
|
|||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
"""Return the state attributes of the device."""
|
||||
attrs: dict[str, Any] = {}
|
||||
if self.data.temperature and self.data.temperature.isnumeric():
|
||||
attrs[ATTR_TEMPERATURE] = self.hass.config.units.temperature(
|
||||
try:
|
||||
temperature = self.hass.config.units.temperature(
|
||||
int(self.data.temperature), UnitOfTemperature.CELSIUS
|
||||
)
|
||||
else:
|
||||
attrs[ATTR_TEMPERATURE] = None
|
||||
if self.data.total_consumption and self.data.total_consumption.isnumeric():
|
||||
attrs[ATTR_TOTAL_CONSUMPTION] = float(self.data.total_consumption)
|
||||
else:
|
||||
attrs[ATTR_TOTAL_CONSUMPTION] = None
|
||||
except ValueError:
|
||||
temperature = None
|
||||
|
||||
try:
|
||||
total_consumption = float(self.data.total_consumption)
|
||||
except ValueError:
|
||||
total_consumption = None
|
||||
|
||||
attrs = {
|
||||
ATTR_TOTAL_CONSUMPTION: total_consumption,
|
||||
ATTR_TEMPERATURE: temperature,
|
||||
}
|
||||
|
||||
return attrs
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue