Small cleanups to shelly (#124758)

This commit is contained in:
J. Nick Koston 2024-08-27 21:00:31 -10:00 committed by GitHub
parent a63c5e6725
commit f9bf7f7e05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 11 deletions

View file

@ -488,7 +488,7 @@ class ShellyRestAttributeEntity(CoordinatorEntity[ShellyBlockCoordinator]):
@property
def attribute_value(self) -> StateType:
"""Value of sensor."""
if callable(self.entity_description.value):
if self.entity_description.value is not None:
self._last_value = self.entity_description.value(
self.block_coordinator.device.status, self._last_value
)
@ -518,7 +518,7 @@ class ShellyRpcAttributeEntity(ShellyRpcEntity, Entity):
id_key = key.split(":")[-1]
self._id = int(id_key) if id_key.isnumeric() else None
if callable(description.unit):
if description.unit is not None:
self._attr_native_unit_of_measurement = description.unit(
coordinator.device.config[key]
)
@ -544,7 +544,7 @@ class ShellyRpcAttributeEntity(ShellyRpcEntity, Entity):
@property
def attribute_value(self) -> StateType:
"""Value of sensor."""
if callable(self.entity_description.value):
if self.entity_description.value is not None:
# using "get" here since subkey might not exist (e.g. "errors" sub_key)
self._last_value = self.entity_description.value(
self.status.get(self.entity_description.sub_key), self._last_value