Use DataUpdateCoordinator for wemo (#54866)

* Use DataUpdateCoordinator for wemo

* Rename DeviceWrapper->DeviceCoordinator and make it a subclass of DataUpdateCoordinator

* Rename async_update_data->_async_update_data to override base class

* Rename: device -> coordinator
This commit is contained in:
Eric Severance 2021-08-21 11:14:55 -07:00 committed by GitHub
parent 6cefd558d8
commit 67d04b6082
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 507 additions and 629 deletions

View file

@ -6,7 +6,7 @@ from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from .const import DOMAIN as WEMO_DOMAIN
from .entity import WemoSubscriptionEntity
from .entity import WemoEntity
_LOGGER = logging.getLogger(__name__)
@ -14,24 +14,24 @@ _LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up WeMo binary sensors."""
async def _discovered_wemo(device):
async def _discovered_wemo(coordinator):
"""Handle a discovered Wemo device."""
async_add_entities([WemoBinarySensor(device)])
async_add_entities([WemoBinarySensor(coordinator)])
async_dispatcher_connect(hass, f"{WEMO_DOMAIN}.binary_sensor", _discovered_wemo)
await asyncio.gather(
*(
_discovered_wemo(device)
for device in hass.data[WEMO_DOMAIN]["pending"].pop("binary_sensor")
_discovered_wemo(coordinator)
for coordinator in hass.data[WEMO_DOMAIN]["pending"].pop("binary_sensor")
)
)
class WemoBinarySensor(WemoSubscriptionEntity, BinarySensorEntity):
class WemoBinarySensor(WemoEntity, BinarySensorEntity):
"""Representation a WeMo binary sensor."""
def _update(self, force_update=True):
"""Update the sensor state."""
with self._wemo_exception_handler("update status"):
self._state = self.wemo.get_state(force_update)
@property
def is_on(self) -> bool:
"""Return true if the state is on. Standby is on."""
return self.wemo.get_state()