Update myq to use CoordinatorEntity (#39393)
This commit is contained in:
parent
a4f475245c
commit
4e876cb473
2 changed files with 15 additions and 32 deletions
|
@ -14,6 +14,7 @@ from homeassistant.components.binary_sensor import (
|
|||
DEVICE_CLASS_CONNECTIVITY,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN, MYQ_COORDINATOR, MYQ_GATEWAY
|
||||
|
||||
|
@ -35,12 +36,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
class MyQBinarySensorEntity(BinarySensorEntity):
|
||||
class MyQBinarySensorEntity(CoordinatorEntity, BinarySensorEntity):
|
||||
"""Representation of a MyQ gateway."""
|
||||
|
||||
def __init__(self, coordinator, device):
|
||||
"""Initialize with API object, device id."""
|
||||
self._coordinator = coordinator
|
||||
super().__init__(coordinator)
|
||||
self._device = device
|
||||
|
||||
@property
|
||||
|
@ -56,7 +57,7 @@ class MyQBinarySensorEntity(BinarySensorEntity):
|
|||
@property
|
||||
def is_on(self):
|
||||
"""Return if the device is online."""
|
||||
if not self._coordinator.last_update_success:
|
||||
if not self.coordinator.last_update_success:
|
||||
return False
|
||||
|
||||
# Not all devices report online so assume True if its missing
|
||||
|
@ -64,15 +65,16 @@ class MyQBinarySensorEntity(BinarySensorEntity):
|
|||
MYQ_DEVICE_STATE_ONLINE, True
|
||||
)
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Entity is always available."""
|
||||
return True
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique, Home Assistant friendly identifier for this entity."""
|
||||
return self._device.device_id
|
||||
|
||||
async def async_update(self):
|
||||
"""Update status of cover."""
|
||||
await self._coordinator.async_request_refresh()
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device_info of the device."""
|
||||
|
@ -87,14 +89,3 @@ class MyQBinarySensorEntity(BinarySensorEntity):
|
|||
device_info["model"] = model
|
||||
|
||||
return device_info
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return False, updates are controlled via coordinator."""
|
||||
return False
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to updates."""
|
||||
self.async_on_remove(
|
||||
self._coordinator.async_add_listener(self.async_write_ha_state)
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue