Skip to content

Commit 46211bd

Browse files
Gql 4 (#393)
* Gql 4 Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net> * Bump version to 0.36.0 --------- Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
1 parent b0edb82 commit 46211bd

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ classifiers = [
1919
]
2020
dependencies = [
2121
"aiohttp>=3.0.6",
22-
"gql==3.5.0",
22+
"gql>=4.0.0",
2323
"websockets>=14.0.0",
2424
]
2525
dynamic = ["version"]

tibber/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from http import HTTPStatus
44
from typing import Final
55

6-
__version__ = "0.35.0"
6+
__version__ = "0.36.0"
77

88
API_ENDPOINT: Final = "https://api.tibber.com/v1-beta/gql"
99
DATA_API_ENDPOINT: Final = "https://data-api.tibber.com"

tibber/home.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ async def _start() -> None:
436436
return
437437

438438
try:
439-
session = self._tibber_control.realtime.sub_manager.session
440-
if not hasattr(session, "subscribe"):
441-
_LOGGER.error("Session does not support subscribe method")
439+
session = self._tibber_control.realtime.session
440+
if session is None or not hasattr(session, "subscribe"):
441+
_LOGGER.error("Session is not connected or does not support subscribe method")
442442
return
443443
async for _data in session.subscribe(
444444
gql(LIVE_SUBSCRIBE % self.home_id),

tibber/realtime.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(self, access_token: str, timeout: int, user_agent: str, ssl: SSLCon
3939
self._watchdog_running: bool = False
4040

4141
self.sub_manager: Client | None = None
42+
self.session: Any | None = None
4243

4344
async def disconnect(self) -> None:
4445
"""Stop subscription manager.
@@ -52,14 +53,10 @@ async def disconnect(self) -> None:
5253
self._watchdog_runner = None
5354
for home in self._homes:
5455
home.rt_unsubscribe()
55-
if self.sub_manager is None:
56-
return
57-
try:
58-
if not hasattr(self.sub_manager, "session"):
59-
return
56+
if self.session is not None:
6057
await self.sub_manager.close_async()
61-
finally:
62-
self.sub_manager = None
58+
self.session = None
59+
self.sub_manager = None
6360

6461
async def connect(self) -> None:
6562
"""Start subscription manager."""
@@ -74,7 +71,7 @@ async def connect(self) -> None:
7471
_LOGGER.debug("Starting watchdog")
7572
self._watchdog_running = True
7673
self._watchdog_runner = asyncio.create_task(self._watchdog())
77-
await self.sub_manager.connect_async()
74+
self.session = await self.sub_manager.connect_async()
7875

7976
def set_access_token(self, access_token: str) -> None:
8077
"""Set access token."""
@@ -141,8 +138,9 @@ async def _watchdog(self) -> None:
141138
)
142139

143140
try:
144-
if hasattr(self.sub_manager, "session"):
141+
if self.session is not None:
145142
await self.sub_manager.close_async()
143+
self.session = None
146144
except Exception:
147145
_LOGGER.exception("Error in watchdog close")
148146

@@ -152,7 +150,7 @@ async def _watchdog(self) -> None:
152150

153151
self._create_sub_manager()
154152
try:
155-
await self.sub_manager.connect_async()
153+
self.session = await self.sub_manager.connect_async()
156154
await self._resubscribe_homes()
157155
except Exception as err: # noqa: BLE001
158156
delay_seconds = min(
@@ -193,7 +191,7 @@ def subscription_running(self) -> bool:
193191
self.sub_manager is not None
194192
and isinstance(self.sub_manager.transport, TibberWebsocketsTransport)
195193
and self.sub_manager.transport.running
196-
and hasattr(self.sub_manager, "session")
194+
and self.session is not None
197195
)
198196

199197
@property

tibber/websocket_transport.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ def __init__(self, url: str, access_token: str, user_agent: str, ssl: SSLContext
3636
@property
3737
def running(self) -> bool:
3838
"""Is real time subscription running."""
39-
return hasattr(self, "websocket") and self.websocket is not None and self.websocket.state is State.OPEN
39+
return (
40+
hasattr(self, "adapter")
41+
and hasattr(self.adapter, "websocket")
42+
and self.adapter.websocket is not None
43+
and self.adapter.websocket.state is State.OPEN
44+
)
4045

4146
async def _receive(self) -> str:
4247
"""Wait the next message from the websocket connection."""

0 commit comments

Comments
 (0)