mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Update griddy to use CoordinatorEntity (#39392)
This commit is contained in:
parent
f7d1cfb625
commit
a4f475245c
@ -2,7 +2,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.const import ENERGY_KILO_WATT_HOUR
|
from homeassistant.const import ENERGY_KILO_WATT_HOUR
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import CONF_LOADZONE, DOMAIN
|
from .const import CONF_LOADZONE, DOMAIN
|
||||||
|
|
||||||
@ -18,12 +18,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
async_add_entities([GriddyPriceSensor(settlement_point, coordinator)], True)
|
async_add_entities([GriddyPriceSensor(settlement_point, coordinator)], True)
|
||||||
|
|
||||||
|
|
||||||
class GriddyPriceSensor(Entity):
|
class GriddyPriceSensor(CoordinatorEntity):
|
||||||
"""Representation of an August sensor."""
|
"""Representation of an August sensor."""
|
||||||
|
|
||||||
def __init__(self, settlement_point, coordinator):
|
def __init__(self, settlement_point, coordinator):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._coordinator = coordinator
|
super().__init__(coordinator)
|
||||||
self._settlement_point = settlement_point
|
self._settlement_point = settlement_point
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -46,30 +46,7 @@ class GriddyPriceSensor(Entity):
|
|||||||
"""Device Uniqueid."""
|
"""Device Uniqueid."""
|
||||||
return f"{self._settlement_point}_price_now"
|
return f"{self._settlement_point}_price_now"
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self):
|
|
||||||
"""Return True if entity is available."""
|
|
||||||
return self._coordinator.last_update_success
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Get the current price."""
|
"""Get the current price."""
|
||||||
return round(float(self._coordinator.data.now.price_cents_kwh), 4)
|
return round(float(self.coordinator.data.now.price_cents_kwh), 4)
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Return False, updates are controlled via coordinator."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
async def async_update(self):
|
|
||||||
"""Update the entity.
|
|
||||||
|
|
||||||
Only used by the generic entity update service.
|
|
||||||
"""
|
|
||||||
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)
|
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user