mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Update iammeter to use CoordinatorEntity (#39423)
* Update iammeter to use CoordinatorEntity * Remove async_will_remove_from_hass and async_added_to_hass
This commit is contained in:
parent
0a389a4651
commit
e984801104
@ -13,8 +13,11 @@ from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT
|
|||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
from homeassistant.helpers import debounce
|
from homeassistant.helpers import debounce
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.update_coordinator import (
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
CoordinatorEntity,
|
||||||
|
DataUpdateCoordinator,
|
||||||
|
UpdateFailed,
|
||||||
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -71,12 +74,12 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
class IamMeter(Entity):
|
class IamMeter(CoordinatorEntity):
|
||||||
"""Class for a sensor."""
|
"""Class for a sensor."""
|
||||||
|
|
||||||
def __init__(self, coordinator, uid, sensor_name, unit, dev_name):
|
def __init__(self, coordinator, uid, sensor_name, unit, dev_name):
|
||||||
"""Initialize an iammeter sensor."""
|
"""Initialize an iammeter sensor."""
|
||||||
self.coordinator = coordinator
|
super().__init__(coordinator)
|
||||||
self.uid = uid
|
self.uid = uid
|
||||||
self.sensor_name = sensor_name
|
self.sensor_name = sensor_name
|
||||||
self.unit = unit
|
self.unit = unit
|
||||||
@ -106,25 +109,3 @@ class IamMeter(Entity):
|
|||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
return self.unit
|
return self.unit
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Poll needed."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self):
|
|
||||||
"""Return if entity is available."""
|
|
||||||
return self.coordinator.last_update_success
|
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
|
||||||
"""When entity is added to hass."""
|
|
||||||
self.coordinator.async_add_listener(self.async_write_ha_state)
|
|
||||||
|
|
||||||
async def async_will_remove_from_hass(self):
|
|
||||||
"""When entity will be removed from hass."""
|
|
||||||
self.coordinator.async_remove_listener(self.async_write_ha_state)
|
|
||||||
|
|
||||||
async def async_update(self):
|
|
||||||
"""Update the entity."""
|
|
||||||
await self.coordinator.async_request_refresh()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user