Move temperature conversions to sensor base class (6/8) (#54476)
* Move temperature conversions to entity base class (6/8) * Fix tests
This commit is contained in:
parent
6de6a5dc14
commit
e558b3463e
64 changed files with 199 additions and 188 deletions
|
@ -85,7 +85,7 @@ class SpeedtestSensor(CoordinatorEntity, RestoreEntity, SensorEntity):
|
|||
await super().async_added_to_hass()
|
||||
state = await self.async_get_last_state()
|
||||
if state:
|
||||
self._attr_state = state.state
|
||||
self._attr_native_value = state.state
|
||||
|
||||
@callback
|
||||
def update() -> None:
|
||||
|
@ -100,8 +100,12 @@ class SpeedtestSensor(CoordinatorEntity, RestoreEntity, SensorEntity):
|
|||
"""Update sensors state."""
|
||||
if self.coordinator.data:
|
||||
if self.entity_description.key == "ping":
|
||||
self._attr_state = self.coordinator.data["ping"]
|
||||
self._attr_native_value = self.coordinator.data["ping"]
|
||||
elif self.entity_description.key == "download":
|
||||
self._attr_state = round(self.coordinator.data["download"] / 10 ** 6, 2)
|
||||
self._attr_native_value = round(
|
||||
self.coordinator.data["download"] / 10 ** 6, 2
|
||||
)
|
||||
elif self.entity_description.key == "upload":
|
||||
self._attr_state = round(self.coordinator.data["upload"] / 10 ** 6, 2)
|
||||
self._attr_native_value = round(
|
||||
self.coordinator.data["upload"] / 10 ** 6, 2
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue