Spring cleaning ☀️ (#23)
* Spring cleaning * Actions * Fix branches * Changes for config_flow
This commit is contained in:
54
custom_components/blueprint/entity.py
Normal file
54
custom_components/blueprint/entity.py
Normal file
@ -0,0 +1,54 @@
|
||||
"""BlueprintEntity class"""
|
||||
from homeassistant.helpers import entity
|
||||
|
||||
from custom_components.blueprint.const import DOMAIN, VERSION, NAME
|
||||
|
||||
|
||||
class BlueprintEntity(entity.Entity):
|
||||
def __init__(self, coordinator, config_entry):
|
||||
self.coordinator = 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."""
|
||||
return self.config_entry.entry_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.unique_id)},
|
||||
"name": NAME,
|
||||
"model": VERSION,
|
||||
"manufacturer": NAME,
|
||||
}
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return {
|
||||
"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.coordinator.async_add_listener(self.async_write_ha_state)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Disconnect from update signal."""
|
||||
self.coordinator.async_remove_listener(self.async_write_ha_state)
|
||||
|
||||
async def async_update(self):
|
||||
"""Update Brother entity."""
|
||||
await self.coordinator.async_request_refresh()
|
Reference in New Issue
Block a user