Update brother to use CoordinatorEntity (#39418)

pull/39424/head
springstan 2020-08-30 16:02:12 +02:00 committed by GitHub
parent 64513c8c9a
commit 29c1f873eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 23 deletions

View File

@ -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()