mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Update juicenet to use CoordinatorEntity (#39424)
This commit is contained in:
parent
baf5750425
commit
a1d48ad1ec
@ -1,44 +1,24 @@
|
|||||||
"""Adapter to wrap the pyjuicenet api for home assistant."""
|
"""Adapter to wrap the pyjuicenet api for home assistant."""
|
||||||
|
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
class JuiceNetDevice(Entity):
|
class JuiceNetDevice(CoordinatorEntity):
|
||||||
"""Represent a base JuiceNet device."""
|
"""Represent a base JuiceNet device."""
|
||||||
|
|
||||||
def __init__(self, device, sensor_type, coordinator):
|
def __init__(self, device, sensor_type, coordinator):
|
||||||
"""Initialise the sensor."""
|
"""Initialise the sensor."""
|
||||||
|
super().__init__(coordinator)
|
||||||
self.device = device
|
self.device = device
|
||||||
self.type = sensor_type
|
self.type = sensor_type
|
||||||
self.coordinator = coordinator
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the device."""
|
"""Return the name of the device."""
|
||||||
return self.device.name
|
return self.device.name
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Return False, updates are controlled via coordinator."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self):
|
|
||||||
"""Return True if entity is available."""
|
|
||||||
return self.coordinator.last_update_success
|
|
||||||
|
|
||||||
async def async_update(self):
|
|
||||||
"""Update the entity."""
|
|
||||||
await self.coordinator.async_request_refresh()
|
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
|
||||||
"""Subscribe to updates."""
|
|
||||||
self.async_on_remove(
|
|
||||||
self.coordinator.async_add_listener(self.async_write_ha_state)
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return a unique ID."""
|
"""Return a unique ID."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user