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

pull/102938/head^2
Franck Nijhof 2023-10-27 23:27:02 +02:00 committed by GitHub
parent 923d2d0d81
commit fd1c1dba7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -47,13 +47,17 @@ class HWEnergyNumberEntity(HomeWizardEntity, NumberEntity):
await self.coordinator.api.state_set(brightness=int(value * (255 / 100)))
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
def native_value(self) -> float | None:
"""Return the current value."""
if (
self.coordinator.data.state is None
or self.coordinator.data.state.brightness is None
not self.coordinator.data.state
or (brightness := self.coordinator.data.state.brightness) is None
):
return None
brightness: float = self.coordinator.data.state.brightness
return round(brightness * (100 / 255))