From 891cd4c4e0c0e933eac83f0e97ebdf2f4b210500 Mon Sep 17 00:00:00 2001 From: MatthewFlamm <39341281+MatthewFlamm@users.noreply.github.com> Date: Sat, 19 Sep 2020 04:59:47 -0400 Subject: [PATCH] Use CoordinatorEntity (#33) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Joakim Sørensen --- custom_components/blueprint/entity.py | 26 +++----------------------- hacs.json | 4 ++-- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/custom_components/blueprint/entity.py b/custom_components/blueprint/entity.py index 7972e37..684f2d4 100644 --- a/custom_components/blueprint/entity.py +++ b/custom_components/blueprint/entity.py @@ -1,24 +1,14 @@ """BlueprintEntity class""" -from homeassistant.helpers import entity +from homeassistant.helpers.update_coordinator import CoordinatorEntity from custom_components.blueprint.const import DOMAIN, NAME, VERSION -class BlueprintEntity(entity.Entity): +class BlueprintEntity(CoordinatorEntity): def __init__(self, coordinator, config_entry): - self.coordinator = coordinator + super().__init__(coordinator) self.config_entry = config_entry - @property - def should_poll(self): - """No need to poll. Coordinator notifies entity of updates.""" - return False - - @property - def available(self): - """Return if entity is available.""" - return self.coordinator.last_update_success - @property def unique_id(self): """Return a unique ID to use for this entity.""" @@ -40,13 +30,3 @@ class BlueprintEntity(entity.Entity): "time": str(self.coordinator.data.get("time")), "static": self.coordinator.data.get("static"), } - - 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() diff --git a/hacs.json b/hacs.json index 5cf17fb..c2a336b 100644 --- a/hacs.json +++ b/hacs.json @@ -7,5 +7,5 @@ "switch" ], "iot_class": "Cloud Polling", - "homeassistant": "0.110.0" -} \ No newline at end of file + "homeassistant": "0.115.0" +}