Tibber, Add price level (#22085)
* Add price level to Tibber sensor * bump pyTibber versionpull/22130/head
parent
cf5ba7d922
commit
54dfc3e2b4
|
@ -11,7 +11,7 @@ from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, CONF_ACCESS_TOKEN,
|
|||
from homeassistant.helpers import discovery
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
REQUIREMENTS = ['pyTibber==0.9.6']
|
||||
REQUIREMENTS = ['pyTibber==0.9.8']
|
||||
|
||||
DOMAIN = 'tibber'
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class TibberSensorElPrice(Entity):
|
|||
return
|
||||
|
||||
if (not self._last_data_timestamp or
|
||||
(self._last_data_timestamp - now).total_seconds()/3600 < 12
|
||||
(self._last_data_timestamp - now).total_seconds() / 3600 < 12
|
||||
or not self._is_available):
|
||||
_LOGGER.debug("Asking for new data.")
|
||||
await self._fetch_data()
|
||||
|
@ -136,12 +136,13 @@ class TibberSensorElPrice(Entity):
|
|||
for key, price_total in self._tibber_home.price_total.items():
|
||||
price_time = dt_util.as_local(dt_util.parse_datetime(key))
|
||||
price_total = round(price_total, 3)
|
||||
time_diff = (now - price_time).total_seconds()/60
|
||||
time_diff = (now - price_time).total_seconds() / 60
|
||||
if (not self._last_data_timestamp or
|
||||
price_time > self._last_data_timestamp):
|
||||
self._last_data_timestamp = price_time
|
||||
if 0 <= time_diff < 60:
|
||||
state = price_total
|
||||
level = self._tibber_home.price_level[key]
|
||||
self._last_updated = price_time
|
||||
if now.date() == price_time.date():
|
||||
max_price = max(max_price, price_total)
|
||||
|
@ -152,6 +153,7 @@ class TibberSensorElPrice(Entity):
|
|||
self._device_state_attributes['max_price'] = max_price
|
||||
self._device_state_attributes['avg_price'] = round(sum_price / num, 3)
|
||||
self._device_state_attributes['min_price'] = min_price
|
||||
self._device_state_attributes['price_level'] = level
|
||||
return state is not None
|
||||
|
||||
|
||||
|
@ -232,4 +234,4 @@ class TibberSensorRT(Entity):
|
|||
"""Return a unique ID."""
|
||||
home = self._tibber_home.info['viewer']['home']
|
||||
_id = home['meteringPointData']['consumptionEan']
|
||||
return'{}_rt_consumption'.format(_id)
|
||||
return '{}_rt_consumption'.format(_id)
|
||||
|
|
|
@ -925,7 +925,7 @@ pyRFXtrx==0.23
|
|||
# pySwitchmate==0.4.5
|
||||
|
||||
# homeassistant.components.tibber
|
||||
pyTibber==0.9.6
|
||||
pyTibber==0.9.8
|
||||
|
||||
# homeassistant.components.dlink.switch
|
||||
pyW215==0.6.0
|
||||
|
|
Loading…
Reference in New Issue