Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #59 from doudz/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
doudz authored Dec 21, 2018
2 parents 5cfb24d + 689b21c commit 61e16fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
27 changes: 19 additions & 8 deletions zigate/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class ZiGate(object):

def __init__(self, port='auto', path='~/.zigate.json',
auto_start=True,
auto_save=True):
auto_save=True,
channel=None):
self._devices = {}
self._groups = {}
self._scenes = {}
Expand All @@ -135,6 +136,7 @@ def __init__(self, port='auto', path='~/.zigate.json',
self._addr = None
self._ieee = None
self._started = False
self._no_response_count = 0

self._event_thread = threading.Thread(target=self._event_loop,
name='ZiGate-Event Loop')
Expand All @@ -146,7 +148,7 @@ def __init__(self, port='auto', path='~/.zigate.json',
self._ota_reset_local_variables()

if auto_start:
self.autoStart()
self.autoStart(channel)
if auto_save:
self.start_auto_save()

Expand Down Expand Up @@ -245,7 +247,7 @@ def start_auto_save(self):
def __del__(self):
self.close()

def autoStart(self):
def autoStart(self, channel=None):
'''
Auto Start sequence:
- Load persistent file
Expand All @@ -260,7 +262,7 @@ def autoStart(self):
self.load_state()
self.setup_connection()
version = self.get_version()
self.set_channel()
self.set_channel(channel)
self.set_type(TYPE_COORDINATOR)
LOGGER.debug('Check network state')
self.start_network()
Expand Down Expand Up @@ -394,7 +396,12 @@ def decode_data(self, packet):
computed_checksum))
return
LOGGER.debug('Received response 0x{:04x}: {}'.format(msg_type, hexlify(value)))
response = RESPONSES.get(msg_type, Response)(value, rssi)
try:
response = RESPONSES.get(msg_type, Response)(value, rssi)
except Exception:
LOGGER.error('Error decoding response 0x{:04x}: {}'.format(msg_type, hexlify(value)))
LOGGER.error(traceback.format_exc())
return
if msg_type != response.msg:
LOGGER.warning('Unknown response 0x{:04x}'.format(msg_type))
LOGGER.debug(response)
Expand Down Expand Up @@ -612,8 +619,10 @@ def _wait_status(self, cmd):
sleep(0.01)
t2 = time()
if t2 - t1 > 3: # no response timeout
LOGGER.warning('No response after command 0x{:04x}'.format(cmd))
self._no_response_count += 1
LOGGER.warning('No response after command 0x{:04x} ({})'.format(cmd, self._no_response_count))
return
self._no_response_count = 0
LOGGER.debug('STATUS code to command 0x{:04x}:{}'.format(cmd, self._last_status.get(cmd)))
return self._last_status.get(cmd)

Expand Down Expand Up @@ -1711,11 +1720,13 @@ def start_mqtt_broker(self, host='localhost:1883', username=None, password=None)
class ZiGateWiFi(ZiGate):
def __init__(self, host, port=None, path='~/.zigate.json',
auto_start=True,
auto_save=True):
auto_save=True,
channel=None):
self._host = host
ZiGate.__init__(self, port=port, path=path,
auto_start=auto_start,
auto_save=auto_save
auto_save=auto_save,
channel=channel
)

def setup_connection(self):
Expand Down
1 change: 1 addition & 0 deletions zigate/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def read_data(self, data):
'''
Read ZiGate output and split messages
'''
LOGGER.debug('Raw packet received, {}'.format(data))
self._buffer += data
# print(self._buffer)
endpos = self._buffer.find(b'\x03')
Expand Down
2 changes: 1 addition & 1 deletion zigate/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# file that was distributed with this source code.
#

__version__ = '0.24.1'
__version__ = '0.24.2'

0 comments on commit 61e16fa

Please sign in to comment.