Use CoordinatorEntity (#33)

Co-authored-by: Joakim Sørensen <hi@ludeeus.dev>
This commit is contained in:
MatthewFlamm 2020-09-19 04:59:47 -04:00 committed by GitHub
parent 3c2cd2413d
commit 891cd4c4e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 25 deletions

View File

@ -1,24 +1,14 @@
"""BlueprintEntity class""" """BlueprintEntity class"""
from homeassistant.helpers import entity from homeassistant.helpers.update_coordinator import CoordinatorEntity
from custom_components.blueprint.const import DOMAIN, NAME, VERSION from custom_components.blueprint.const import DOMAIN, NAME, VERSION
class BlueprintEntity(entity.Entity): class BlueprintEntity(CoordinatorEntity):
def __init__(self, coordinator, config_entry): def __init__(self, coordinator, config_entry):
self.coordinator = coordinator super().__init__(coordinator)
self.config_entry = config_entry 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 @property
def unique_id(self): def unique_id(self):
"""Return a unique ID to use for this entity.""" """Return a unique ID to use for this entity."""
@ -40,13 +30,3 @@ class BlueprintEntity(entity.Entity):
"time": str(self.coordinator.data.get("time")), "time": str(self.coordinator.data.get("time")),
"static": self.coordinator.data.get("static"), "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()

View File

@ -7,5 +7,5 @@
"switch" "switch"
], ],
"iot_class": "Cloud Polling", "iot_class": "Cloud Polling",
"homeassistant": "0.110.0" "homeassistant": "0.115.0"
} }