Fix missing attributes bug
This commit is contained in:
committed by
rospogrigio
parent
caaf884a7a
commit
e673340229
@@ -184,6 +184,11 @@ class LocalTuyaEntity(Entity):
|
|||||||
"""Return unique device identifier."""
|
"""Return unique device identifier."""
|
||||||
return f"local_{self._device.unique_id}_{self._dps_id}"
|
return f"local_{self._device.unique_id}_{self._dps_id}"
|
||||||
|
|
||||||
|
def has_config(self, attr):
|
||||||
|
"""Return if a config parameter has a valid value."""
|
||||||
|
value = self._config.get(attr, "-1")
|
||||||
|
return value is not None and value != "-1"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
"""Return if device is available or not."""
|
"""Return if device is available or not."""
|
||||||
|
@@ -80,13 +80,13 @@ class LocaltuyaSwitch(LocalTuyaEntity, SwitchEntity):
|
|||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return device state attributes."""
|
"""Return device state attributes."""
|
||||||
attrs = {}
|
attrs = {}
|
||||||
if self._config.get(CONF_CURRENT, "-1") != "-1":
|
if self.has_config(CONF_CURRENT):
|
||||||
attrs[ATTR_CURRENT] = self.dps(self._config[CONF_CURRENT])
|
attrs[ATTR_CURRENT] = self.dps(self._config[CONF_CURRENT])
|
||||||
if self._config.get(ATTR_CURRENT_CONSUMPTION, "-1") != "-1":
|
if self.has_config(CONF_CURRENT_CONSUMPTION):
|
||||||
attrs[ATTR_CURRENT_CONSUMPTION] = (
|
attrs[ATTR_CURRENT_CONSUMPTION] = (
|
||||||
self.dps(self._config[CONF_CURRENT_CONSUMPTION]) / 10
|
self.dps(self._config[CONF_CURRENT_CONSUMPTION]) / 10
|
||||||
)
|
)
|
||||||
if self._config.get(CONF_VOLTAGE, "-1") != "-1":
|
if self.has_config(CONF_VOLTAGE):
|
||||||
attrs[ATTR_VOLTAGE] = self.dps(self._config[CONF_VOLTAGE]) / 10
|
attrs[ATTR_VOLTAGE] = self.dps(self._config[CONF_VOLTAGE]) / 10
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user