Update griddy to use CoordinatorEntity (#39392)

pull/39415/head
J. Nick Koston 2020-08-30 07:39:07 -05:00 committed by GitHub
parent f7d1cfb625
commit a4f475245c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 27 deletions

View File

@ -2,7 +2,7 @@
import logging
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
@ -18,12 +18,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities([GriddyPriceSensor(settlement_point, coordinator)], True)
class GriddyPriceSensor(Entity):
class GriddyPriceSensor(CoordinatorEntity):
"""Representation of an August sensor."""
def __init__(self, settlement_point, coordinator):
"""Initialize the sensor."""
self._coordinator = coordinator
super().__init__(coordinator)
self._settlement_point = settlement_point
@property
@ -46,30 +46,7 @@ class GriddyPriceSensor(Entity):
"""Device Uniqueid."""
return f"{self._settlement_point}_price_now"
@property
def available(self):
"""Return True if entity is available."""
return self._coordinator.last_update_success
@property
def state(self):
"""Get the current price."""
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)
)
return round(float(self.coordinator.data.now.price_cents_kwh), 4)