Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Danielhiversen/pyTibber
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielhiversen committed Jun 24, 2024
2 parents 570d676 + 6809547 commit 08a0f33
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![PyPI version](https://badge.fury.io/py/pyTibber.svg)](https://badge.fury.io/py/pyTibber)
<a href="https://github.com/ambv/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
<a href="https://github.com/ambv/black/blob/master/LICENSE"><img alt="License: MIT" src="https://black.readthedocs.io/en/stable/_static/license.svg"></a>


Python3 library for [Tibber](https://tibber.com/).
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
"Programming Language :: Python :: 3",
"Topic :: Home Automation",
"Topic :: Software Development :: Libraries :: Python Modules",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
],
)
2 changes: 1 addition & 1 deletion tibber/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from http import HTTPStatus
from typing import Final

__version__ = "0.29.1"
__version__ = "0.29.2"

API_ENDPOINT: Final = "https://api.tibber.com/v1-beta/gql"
DEFAULT_TIMEOUT: Final = 10
Expand Down
14 changes: 8 additions & 6 deletions tibber/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ def _add_extra_data(data: dict[str, Any]) -> dict[str, Any]:
if "lastMeterProduction" in live_data:
live_data["lastMeterProduction"] = max(0, live_data["lastMeterProduction"])

if live_data.get("powerProduction", 0) > 0 and live_data.get("power") is None:
live_data["power"] = 0

if live_data.get("power", 0) > 0 and live_data.get("powerProduction") is None:
live_data["powerProduction"] = 0

current_hour = live_data["accumulatedConsumptionLastHour"]
if current_hour is not None:
power = sum(p[1] for p in self._rt_power) / len(self._rt_power)
Expand All @@ -444,7 +450,6 @@ async def _start() -> None:
else:
_LOGGER.error("rt not running")
return
assert self._tibber_control.realtime.sub_manager is not None

try:
async for _data in self._tibber_control.realtime.sub_manager.session.subscribe(
Expand All @@ -469,10 +474,10 @@ async def _start() -> None:
_LOGGER.exception("Error in rt_subscribe")

self._rt_callback = callback
self._tibber_control.realtime.add_home(self)
await self._tibber_control.realtime.connect()
self._rt_listener = asyncio.create_task(_start())
self._rt_stopped = False
await self._tibber_control.realtime.connect()
self._tibber_control.realtime.add_home(self)

async def rt_resubscribe(self) -> None:
"""Resubscribe to Tibber data."""
Expand All @@ -487,9 +492,6 @@ async def rt_resubscribe(self) -> None:
if self._rt_callback is None:
_LOGGER.warning("No callback set for rt_resubscribe")
return
if self.has_real_time_consumption is False:
_LOGGER.error("No real time device for %s", self.home_id)
return
await self.rt_subscribe(self._rt_callback)

def rt_unsubscribe(self) -> None:
Expand Down
7 changes: 3 additions & 4 deletions tibber/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ async def _watchdog(self) -> None:
home.has_real_time_consumption,
home.rt_subscription_running,
)
if home.has_real_time_consumption is False:
continue
if not home.rt_subscription_running:
is_running = False
next_test_all_homes_running = dt.datetime.now(tz=dt.UTC) + dt.timedelta(seconds=60)
Expand Down Expand Up @@ -153,8 +151,8 @@ async def _watchdog(self) -> None:
await self._resubscribe_homes()
except Exception: # pylint: disable=broad-except
delay_seconds = min(
random.SystemRandom().randint(1, 60) + _retry_count**2,
20 * 60,
random.SystemRandom().randint(1, 30) + _retry_count**2,
5 * 60,
)
_retry_count += 1
_LOGGER.error(
Expand Down Expand Up @@ -189,6 +187,7 @@ def subscription_running(self) -> bool:
self.sub_manager is not None
and isinstance(self.sub_manager.transport, TibberWebsocketsTransport)
and self.sub_manager.transport.running
and hasattr(self.sub_manager, "session")
)

@property
Expand Down

0 comments on commit 08a0f33

Please sign in to comment.