From 21f1875816ffb07ef6d69cec7aaf14df53a46d37 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 30 Aug 2020 07:40:55 -0500 Subject: [PATCH] Update updater to use CoordinatorEntity (#39396) --- .../components/updater/binary_sensor.py | 30 ++----------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/homeassistant/components/updater/binary_sensor.py b/homeassistant/components/updater/binary_sensor.py index 5d45b368500..36e05513d43 100644 --- a/homeassistant/components/updater/binary_sensor.py +++ b/homeassistant/components/updater/binary_sensor.py @@ -1,6 +1,7 @@ """Support for Home Assistant Updater binary sensors.""" from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.helpers.update_coordinator import CoordinatorEntity from . import ATTR_NEWEST_VERSION, ATTR_RELEASE_NOTES, DOMAIN as UPDATER_DOMAIN @@ -13,13 +14,9 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= async_add_entities([UpdaterBinary(hass.data[UPDATER_DOMAIN])]) -class UpdaterBinary(BinarySensorEntity): +class UpdaterBinary(CoordinatorEntity, BinarySensorEntity): """Representation of an updater binary sensor.""" - def __init__(self, coordinator): - """Initialize the binary sensor.""" - self.coordinator = coordinator - @property def name(self) -> str: """Return the name of the binary sensor, if any.""" @@ -37,16 +34,6 @@ class UpdaterBinary(BinarySensorEntity): return None return self.coordinator.data.update_available - @property - def available(self) -> bool: - """Return True if entity is available.""" - return self.coordinator.last_update_success - - @property - def should_poll(self) -> bool: - """Return True if entity has to be polled for state.""" - return False - @property def device_state_attributes(self) -> dict: """Return the optional state attributes.""" @@ -58,16 +45,3 @@ class UpdaterBinary(BinarySensorEntity): if self.coordinator.data.newest_version: data[ATTR_NEWEST_VERSION] = self.coordinator.data.newest_version return data - - async def async_added_to_hass(self): - """Register update dispatcher.""" - self.async_on_remove( - self.coordinator.async_add_listener(self.async_write_ha_state) - ) - - async def async_update(self): - """Update the entity. - - Only used by the generic entity update service. - """ - await self.coordinator.async_request_refresh()