1 """Support for Flick Electric Pricing data."""
4 from datetime
import timedelta
8 from pyflick
import FlickAPI, FlickPrice
17 from .const
import ATTR_COMPONENTS, ATTR_END_AT, ATTR_START_AT, DOMAIN
19 _LOGGER = logging.getLogger(__name__)
25 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
27 """Flick Sensor Setup."""
28 api: FlickAPI = hass.data[DOMAIN][entry.entry_id]
34 """Entity object for Flick Electric sensor."""
36 _attr_attribution =
"Data provided by Flick Electric"
37 _attr_native_unit_of_measurement = f
"{CURRENCY_CENT}/{UnitOfEnergy.KILO_WATT_HOUR}"
38 _attr_has_entity_name =
True
39 _attr_translation_key =
"power_price"
40 _attributes: dict[str, Any] = {}
43 """Entity object for Flick Electric sensor."""
44 self._api: FlickAPI = api
45 self.
_price_price: FlickPrice =
None
49 """Return the state of the sensor."""
50 return self.
_price_price.price
54 """Return the state attributes."""
55 return self._attributes
58 """Get the Flick Pricing data from the web service."""
62 async
with asyncio.timeout(60):
63 self.
_price_price = await self._api.getPricing()
65 _LOGGER.debug(
"Pricing data: %s", self.
_price_price)
67 self._attributes[ATTR_START_AT] = self.
_price_price.start_at
68 self._attributes[ATTR_END_AT] = self.
_price_price.end_at
69 for component
in self.
_price_price.components:
70 if component.charge_setter
not in ATTR_COMPONENTS:
71 _LOGGER.warning(
"Found unknown component: %s", component.charge_setter)
74 self._attributes[component.charge_setter] =
float(component.value)
None __init__(self, FlickAPI api)
def extra_state_attributes(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)