From a03d8477bf2df0420857ed5ce8ed9df5abca284b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Matheson=20Wergeland?= Date: Wed, 27 Mar 2024 20:41:51 +0100 Subject: [PATCH] Support providing timezone for handshake (#36) --- README.md | 2 +- pynobo.py | 7 ++++--- setup.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2caae69..4433428 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ It is possible to discover hubs on the local network, and also test connectivity hubs = await nobo.async_discover_hubs() # Test connection to the first - (serial, ip) = hubs.pop() + (ip, serial) = hubs.pop() hub = nobo(serial + '123', ip=ip, discover=False, synchronous=False) await hub.connect() diff --git a/pynobo.py b/pynobo.py index 60ea615..4ab8d07 100644 --- a/pynobo.py +++ b/pynobo.py @@ -4,7 +4,6 @@ import datetime import errno import logging -import time import threading import warnings import socket @@ -342,7 +341,7 @@ def datagram_received(self, data: bytes, addr): if discover_ip and discover_serial: self.hubs.add( (discover_ip, discover_serial) ) - def __init__(self, serial, ip=None, discover=True, loop=None, synchronous=True): + def __init__(self, serial, ip=None, discover=True, loop=None, synchronous=True, timezone: datetime.tzinfo=None): """ Initialize logger and dictionaries. @@ -359,6 +358,7 @@ def __init__(self, serial, ip=None, discover=True, loop=None, synchronous=True): if loop is not None: _LOGGER.warning("loop is deprecated. Use synchronous=False instead.") synchronous=False + self.timezone = timezone self._callbacks = [] self._reader = None @@ -491,7 +491,8 @@ async def async_connect_hub(self, ip, serial): self._reader, self._writer = await asyncio.wait_for(asyncio.open_connection(ip, 27779), timeout=5) # start handshake: "HELLO \r" - await self.async_send_command([nobo.API.START, nobo.API.VERSION, serial, time.strftime('%Y%m%d%H%M%S')]) + now = datetime.datetime.now(self.timezone).strftime('%Y%m%d%H%M%S') + await self.async_send_command([nobo.API.START, nobo.API.VERSION, serial, now]) # receive the response data (4096 is recommended buffer size) response = await asyncio.wait_for(self.get_response(), timeout=5) diff --git a/setup.py b/setup.py index 5605860..0fb7a9f 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ # For a discussion on single-sourcing the version across setup.py and the # project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='1.7.0', + version='1.8.0', description='Nobø Hub / Nobø Energy Control TCP/IP Interface', license='GPLv3+',