Skip to content

Commit

Permalink
Support providing timezone for handshake (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindwe authored Mar 27, 2024
1 parent b07910d commit a03d847
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
7 changes: 4 additions & 3 deletions pynobo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import datetime
import errno
import logging
import time
import threading
import warnings
import socket
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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 <version of command set> <Hub s.no.> <date and time in format 'yyyyMMddHHmmss'>\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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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+',
Expand Down

0 comments on commit a03d847

Please sign in to comment.