Update speedtestdotnet to use CoordinatorEntity (#39404)
This commit is contained in:
parent
5dfb043896
commit
be489e83a1
1 changed files with 3 additions and 11 deletions
|
@ -4,6 +4,7 @@ import logging
|
|||
from homeassistant.const import ATTR_ATTRIBUTION
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import (
|
||||
ATTR_BYTES_RECEIVED,
|
||||
|
@ -33,13 +34,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
class SpeedtestSensor(RestoreEntity):
|
||||
class SpeedtestSensor(CoordinatorEntity, RestoreEntity):
|
||||
"""Implementation of a speedtest.net sensor."""
|
||||
|
||||
def __init__(self, coordinator, sensor_type):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator)
|
||||
self._name = SENSOR_TYPES[sensor_type][0]
|
||||
self.coordinator = coordinator
|
||||
self.type = sensor_type
|
||||
self._unit_of_measurement = SENSOR_TYPES[self.type][1]
|
||||
self._state = None
|
||||
|
@ -69,11 +70,6 @@ class SpeedtestSensor(RestoreEntity):
|
|||
"""Return icon."""
|
||||
return ICON
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the polling requirement for this sensor."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
|
@ -118,7 +114,3 @@ class SpeedtestSensor(RestoreEntity):
|
|||
self._state = round(self.coordinator.data["download"] / 10 ** 6, 2)
|
||||
elif self.type == "upload":
|
||||
self._state = round(self.coordinator.data["upload"] / 10 ** 6, 2)
|
||||
|
||||
async def async_update(self):
|
||||
"""Request coordinator to update data."""
|
||||
await self.coordinator.async_request_refresh()
|
||||
|
|
Loading…
Add table
Reference in a new issue