mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Small cleanups to shelly (#124758)
This commit is contained in:
parent
a63c5e6725
commit
f9bf7f7e05
@ -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
|
||||
|
@ -207,17 +207,17 @@ class RpcNumber(ShellyRpcAttributeEntity, NumberEntity):
|
||||
"""Initialize sensor."""
|
||||
super().__init__(coordinator, key, attribute, description)
|
||||
|
||||
if callable(description.max_fn):
|
||||
if description.max_fn is not None:
|
||||
self._attr_native_max_value = description.max_fn(
|
||||
coordinator.device.config[key]
|
||||
)
|
||||
if callable(description.min_fn):
|
||||
if description.min_fn is not None:
|
||||
self._attr_native_min_value = description.min_fn(
|
||||
coordinator.device.config[key]
|
||||
)
|
||||
if callable(description.step_fn):
|
||||
if description.step_fn is not None:
|
||||
self._attr_native_step = description.step_fn(coordinator.device.config[key])
|
||||
if callable(description.mode_fn):
|
||||
if description.mode_fn is not None:
|
||||
self._attr_mode = description.mode_fn(coordinator.device.config[key])
|
||||
|
||||
@property
|
||||
|
@ -1266,13 +1266,15 @@ class RpcSensor(ShellyRpcAttributeEntity, SensorEntity):
|
||||
@property
|
||||
def native_value(self) -> StateType:
|
||||
"""Return value of sensor."""
|
||||
if not self.option_map:
|
||||
return self.attribute_value
|
||||
attribute_value = self.attribute_value
|
||||
|
||||
if not isinstance(self.attribute_value, str):
|
||||
if not self.option_map:
|
||||
return attribute_value
|
||||
|
||||
if not isinstance(attribute_value, str):
|
||||
return None
|
||||
|
||||
return self.option_map[self.attribute_value]
|
||||
return self.option_map[attribute_value]
|
||||
|
||||
|
||||
class BlockSleepingSensor(ShellySleepingBlockAttributeEntity, RestoreSensor):
|
||||
|
Loading…
x
Reference in New Issue
Block a user