Update plugwise to use CoordinatorEntity (#39457)

This commit is contained in:
J. Nick Koston 2020-08-30 13:02:27 -05:00 committed by GitHub
parent 953626b2d4
commit 773860ca5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,8 +14,11 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.entity import Entity from homeassistant.helpers.update_coordinator import (
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed CoordinatorEntity,
DataUpdateCoordinator,
UpdateFailed,
)
from .const import DOMAIN from .const import DOMAIN
@ -131,13 +134,14 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
return unload_ok return unload_ok
class SmileGateway(Entity): class SmileGateway(CoordinatorEntity):
"""Represent Smile Gateway.""" """Represent Smile Gateway."""
def __init__(self, api, coordinator, name, dev_id): def __init__(self, api, coordinator, name, dev_id):
"""Initialise the gateway.""" """Initialise the gateway."""
super().__init__(coordinator)
self._api = api self._api = api
self._coordinator = coordinator
self._name = name self._name = name
self._dev_id = dev_id self._dev_id = dev_id
@ -151,16 +155,6 @@ class SmileGateway(Entity):
"""Return a unique ID.""" """Return a unique ID."""
return self._unique_id return self._unique_id
@property
def should_poll(self):
"""Return False, updates are controlled via coordinator."""
return False
@property
def available(self):
"""Return True if entity is available."""
return self._coordinator.last_update_success
@property @property
def name(self): def name(self):
"""Return the name of the entity, if any.""" """Return the name of the entity, if any."""
@ -188,14 +182,10 @@ class SmileGateway(Entity):
"""Subscribe to updates.""" """Subscribe to updates."""
self._async_process_data() self._async_process_data()
self.async_on_remove( self.async_on_remove(
self._coordinator.async_add_listener(self._async_process_data) self.coordinator.async_add_listener(self._async_process_data)
) )
@callback @callback
def _async_process_data(self): def _async_process_data(self):
"""Interpret and process API data.""" """Interpret and process API data."""
raise NotImplementedError raise NotImplementedError
async def async_update(self):
"""Update the entity."""
await self._coordinator.async_request_refresh()