Handle/extend number entity availability property in HomeWizard Energy (#102934)

This commit is contained in:
Paulus Schoutsen
2023-10-28 23:29:02 -04:00
parent 974c34e2b6
commit f9f010643a

View File

@@ -47,13 +47,17 @@ class HWEnergyNumberEntity(HomeWizardEntity, NumberEntity):
await self.coordinator.api.state_set(brightness=int(value * (255 / 100))) await self.coordinator.api.state_set(brightness=int(value * (255 / 100)))
await self.coordinator.async_refresh() await self.coordinator.async_refresh()
@property
def available(self) -> bool:
"""Return if entity is available."""
return super().available and self.coordinator.data.state is not None
@property @property
def native_value(self) -> float | None: def native_value(self) -> float | None:
"""Return the current value.""" """Return the current value."""
if ( if (
self.coordinator.data.state is None not self.coordinator.data.state
or self.coordinator.data.state.brightness is None or (brightness := self.coordinator.data.state.brightness) is None
): ):
return None return None
brightness: float = self.coordinator.data.state.brightness
return round(brightness * (100 / 255)) return round(brightness * (100 / 255))