From 54dfc3e2b419fdb5f9346fe75b19863cb38e78aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B8yer=20Iversen?= Date: Sun, 17 Mar 2019 09:34:50 +0100 Subject: [PATCH] Tibber, Add price level (#22085) * Add price level to Tibber sensor * bump pyTibber version --- homeassistant/components/tibber/__init__.py | 2 +- homeassistant/components/tibber/sensor.py | 8 +++++--- requirements_all.txt | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/tibber/__init__.py b/homeassistant/components/tibber/__init__.py index f254774eea4..9c5f375e19f 100644 --- a/homeassistant/components/tibber/__init__.py +++ b/homeassistant/components/tibber/__init__.py @@ -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' diff --git a/homeassistant/components/tibber/sensor.py b/homeassistant/components/tibber/sensor.py index f3e0c39a1e6..fb224a25468 100644 --- a/homeassistant/components/tibber/sensor.py +++ b/homeassistant/components/tibber/sensor.py @@ -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) diff --git a/requirements_all.txt b/requirements_all.txt index 512079a2347..2484c563fe1 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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