From 29c1f873eb6047218f9437dbe682a983e9b3060b Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Sun, 30 Aug 2020 16:02:12 +0200 Subject: [PATCH] Update brother to use CoordinatorEntity (#39418) --- homeassistant/components/brother/sensor.py | 26 +++------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/brother/sensor.py b/homeassistant/components/brother/sensor.py index 607a5989abc..abc0447e718 100644 --- a/homeassistant/components/brother/sensor.py +++ b/homeassistant/components/brother/sensor.py @@ -3,7 +3,7 @@ from datetime import timedelta import logging from homeassistant.const import DEVICE_CLASS_TIMESTAMP -from homeassistant.helpers.entity import Entity +from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.util.dt import utcnow from .const import ( @@ -60,15 +60,15 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(sensors, False) -class BrotherPrinterSensor(Entity): +class BrotherPrinterSensor(CoordinatorEntity): """Define an Brother Printer sensor.""" def __init__(self, coordinator, kind, device_info): """Initialize.""" + super().__init__(coordinator) self._name = f"{coordinator.data[ATTR_MODEL]} {SENSOR_TYPES[kind][ATTR_LABEL]}" self._unique_id = f"{coordinator.data[ATTR_SERIAL].lower()}_{kind}" self._device_info = device_info - self.coordinator = coordinator self.kind = kind self._attrs = {} @@ -134,16 +134,6 @@ class BrotherPrinterSensor(Entity): """Return the unit the value is expressed in.""" return SENSOR_TYPES[self.kind][ATTR_UNIT] - @property - def available(self): - """Return True if entity is available.""" - return self.coordinator.last_update_success - - @property - def should_poll(self): - """Return the polling requirement of the entity.""" - return False - @property def device_info(self): """Return the device info.""" @@ -153,13 +143,3 @@ class BrotherPrinterSensor(Entity): def entity_registry_enabled_default(self): """Return if the entity should be enabled when first added to the entity registry.""" return True - - async def async_added_to_hass(self): - """Connect to dispatcher listening for entity data notifications.""" - self.async_on_remove( - self.coordinator.async_add_listener(self.async_write_ha_state) - ) - - async def async_update(self): - """Update Brother entity.""" - await self.coordinator.async_request_refresh()