Update updater to use CoordinatorEntity (#39396)
This commit is contained in:
parent
2525d319a3
commit
21f1875816
1 changed files with 2 additions and 28 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue