Skip to content

Commit a03d847

Browse files
authored
Support providing timezone for handshake (#36)
1 parent b07910d commit a03d847

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ It is possible to discover hubs on the local network, and also test connectivity
6161
hubs = await nobo.async_discover_hubs()
6262

6363
# Test connection to the first
64-
(serial, ip) = hubs.pop()
64+
(ip, serial) = hubs.pop()
6565
hub = nobo(serial + '123', ip=ip, discover=False, synchronous=False)
6666
await hub.connect()
6767

pynobo.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import datetime
55
import errno
66
import logging
7-
import time
87
import threading
98
import warnings
109
import socket
@@ -342,7 +341,7 @@ def datagram_received(self, data: bytes, addr):
342341
if discover_ip and discover_serial:
343342
self.hubs.add( (discover_ip, discover_serial) )
344343

345-
def __init__(self, serial, ip=None, discover=True, loop=None, synchronous=True):
344+
def __init__(self, serial, ip=None, discover=True, loop=None, synchronous=True, timezone: datetime.tzinfo=None):
346345
"""
347346
Initialize logger and dictionaries.
348347
@@ -359,6 +358,7 @@ def __init__(self, serial, ip=None, discover=True, loop=None, synchronous=True):
359358
if loop is not None:
360359
_LOGGER.warning("loop is deprecated. Use synchronous=False instead.")
361360
synchronous=False
361+
self.timezone = timezone
362362

363363
self._callbacks = []
364364
self._reader = None
@@ -491,7 +491,8 @@ async def async_connect_hub(self, ip, serial):
491491
self._reader, self._writer = await asyncio.wait_for(asyncio.open_connection(ip, 27779), timeout=5)
492492

493493
# start handshake: "HELLO <version of command set> <Hub s.no.> <date and time in format 'yyyyMMddHHmmss'>\r"
494-
await self.async_send_command([nobo.API.START, nobo.API.VERSION, serial, time.strftime('%Y%m%d%H%M%S')])
494+
now = datetime.datetime.now(self.timezone).strftime('%Y%m%d%H%M%S')
495+
await self.async_send_command([nobo.API.START, nobo.API.VERSION, serial, now])
495496

496497
# receive the response data (4096 is recommended buffer size)
497498
response = await asyncio.wait_for(self.get_response(), timeout=5)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# For a discussion on single-sourcing the version across setup.py and the
2929
# project code, see
3030
# https://packaging.python.org/en/latest/single_source_version.html
31-
version='1.7.0',
31+
version='1.8.0',
3232
description='Nobø Hub / Nobø Energy Control TCP/IP Interface',
3333

3434
license='GPLv3+',

0 commit comments

Comments
 (0)