Update poolsense to use CoordinatorEntity (#39435)

pull/39449/head
springstan 2020-08-30 17:47:45 +02:00 committed by GitHub
parent 1e97ca14f1
commit e701001c5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 24 deletions

View File

@ -12,8 +12,11 @@ from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import aiohttp_client
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
UpdateFailed,
)
from .const import DOMAIN
@ -78,13 +81,13 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
return unload_ok
class PoolSenseEntity(Entity):
class PoolSenseEntity(CoordinatorEntity):
"""Implements a common class elements representing the PoolSense component."""
def __init__(self, coordinator, email, info_type):
"""Initialize poolsense sensor."""
super().__init__(coordinator)
self._unique_id = f"{email}-{info_type}"
self.coordinator = coordinator
self.info_type = info_type
@property
@ -92,26 +95,6 @@ class PoolSenseEntity(Entity):
"""Return a unique id."""
return self._unique_id
@property
def available(self):
"""Return if sensor is available."""
return self.coordinator.last_update_success
@property
def should_poll(self) -> bool:
"""Return the polling requirement of the entity."""
return False
async def async_added_to_hass(self) -> None:
"""Connect to dispatcher listening for entity data notifications."""
self.async_on_remove(
self.coordinator.async_add_listener(self.async_write_ha_state)
)
async def async_update(self) -> None:
"""Request an update of the coordinator for entity."""
await self.coordinator.async_request_refresh()
class PoolSenseDataUpdateCoordinator(DataUpdateCoordinator):
"""Define an object to hold PoolSense data."""