diff --git a/examples/async_serial.py b/examples/async_serial.py index d7ae719..2d4cba2 100644 --- a/examples/async_serial.py +++ b/examples/async_serial.py @@ -2,7 +2,6 @@ import serial_asyncio import threading from functools import partial -from pyzigate.interface import ZiGate class AsyncSerialConnection(object): @@ -41,17 +40,24 @@ def data_received(self, data): def connection_lost(self, exc): pass + def start_loop(loop): loop.run_forever() loop.close() if __name__ == "__main__": + import logging + from pyzigate.interface import ZiGate + + # Setup logging on screen, debug mode + l = logging.getLogger('zigate') + l.setLevel(logging.DEBUG) + l.addHandler(logging.StreamHandler()) + # Asyncio based connection zigate = ZiGate() - loop = asyncio.get_event_loop() - # Asyncio based connection connection = AsyncSerialConnection(loop, zigate) # Adding loop in a thread for testing purposes (i.e non blocking ipython console) diff --git a/examples/async_wifi.py b/examples/async_wifi.py index 683c195..31713ca 100644 --- a/examples/async_wifi.py +++ b/examples/async_wifi.py @@ -1,7 +1,6 @@ import asyncio import threading from functools import partial -from pyzigate.interface import ZiGate class AsyncWiFiConnection(object): @@ -42,20 +41,29 @@ def data_received(self, data): def connection_lost(self, exc): pass + def start_loop(loop): loop.run_forever() loop.close() if __name__ == "__main__": + import logging + from pyzigate.interface import ZiGate + + # Setup logging on screen, debug mode + l = logging.getLogger('zigate') + l.setLevel(logging.DEBUG) + l.addHandler(logging.StreamHandler()) - zigate = ZiGate() - loop = asyncio.get_event_loop() # Asyncio based connection + zigate = ZiGate() + loop = asyncio.get_event_loop() connection = AsyncWiFiConnection(zigate) # Adding loop in a thread for testing purposes (i.e non blocking ipython console) + # not needed when full program is run within the event loop t = threading.Thread(target=start_loop, args=(loop,)) t.start() diff --git a/examples/threaded_serial.py b/examples/threaded_serial.py index c442892..097c35a 100644 --- a/examples/threaded_serial.py +++ b/examples/threaded_serial.py @@ -1,6 +1,3 @@ -from pyzigate.interface import ZiGate - - # Functions when used with serial & threads class ThreadedConnection(object): def __init__(self, device, port='/dev/ttyUSB0'): @@ -23,8 +20,15 @@ def send(self, data): if __name__ == "__main__": - zigate = ZiGate() + import logging + from pyzigate.interface import ZiGate + + # Setup logging on screen, debug mode + l = logging.getLogger('zigate') + l.setLevel(logging.DEBUG) + l.addHandler(logging.StreamHandler()) # Thread base connection + zigate = ZiGate() connection = ThreadedConnection(zigate) zigate.send_data('0010') diff --git a/pyzigate/attributes_helpers.py b/pyzigate/attributes_helpers.py index 25cbf57..5980fc1 100644 --- a/pyzigate/attributes_helpers.py +++ b/pyzigate/attributes_helpers.py @@ -1,9 +1,11 @@ #! /usr/bin/python3 +import logging from binascii import hexlify, unhexlify from collections import OrderedDict from time import strftime from .zgt_parameters import * +ZGT_LOG = logging.getLogger('zigate') class Mixin: """ diff --git a/pyzigate/interface.py b/pyzigate/interface.py index d6dd9ab..6297824 100644 --- a/pyzigate/interface.py +++ b/pyzigate/interface.py @@ -1,8 +1,8 @@ #! /usr/bin/python3 +import logging from binascii import hexlify from time import strftime from collections import OrderedDict -import logging from . import commands_helpers, attributes_helpers from .zgt_parameters import * @@ -38,6 +38,8 @@ b'FF02': 'Xiaomi private' } +ZGT_LOG = logging.getLogger('zigate') + class ZiGate(commands_helpers.Mixin, attributes_helpers.Mixin): @@ -549,32 +551,3 @@ def decode_data(self, data): ZGT_LOG.debug(' - Data : {}'.format(hexlify(msg_data))) ZGT_LOG.debug(' - RSSI : {}'.format(hexlify(data[-1:]))) - -# Functions when used with serial & threads -# (to be removed once examples tested) -class ThreadedConnection(object): - - def __init__(self, device, port='/dev/ttyUSB0'): - import serial - import threading - - self.device = device - self.cnx = serial.Serial(port, 115200, timeout=0) - self.thread = threading.Thread(target=self.read).start() - device.send_to_transport = self.send - - def read(self): - while True: - bytesavailable = self.cnx.inWaiting() - if bytesavailable > 0: - self.device.read_data(self.cnx.read(bytesavailable)) - - def send(self, data): - self.cnx.write(data) - - -if __name__ == "__main__": - - zigate = ZiGate() - connection = ThreadedConnection(zigate) - zigate.send_data('0010') diff --git a/pyzigate/zgt_parameters.py b/pyzigate/zgt_parameters.py index 70b4a9e..ed7d67d 100644 --- a/pyzigate/zgt_parameters.py +++ b/pyzigate/zgt_parameters.py @@ -1,12 +1,4 @@ #! /usr/bin/python3 -# Logging -import logging -ZGT_LOG = logging.getLogger('zigate') -ZGT_LOG.setLevel(logging.DEBUG) -# Force logging output to console -_LOGSTREAM = logging.StreamHandler() -_LOGSTREAM.setLevel(logging.DEBUG) -ZGT_LOG.addHandler(_LOGSTREAM) # states & properties ZGT_TEMPERATURE = 'temperature' diff --git a/setup.py b/setup.py index 7648b35..0dd9050 100644 --- a/setup.py +++ b/setup.py @@ -3,12 +3,12 @@ setup( name='pyzigate', packages=['pyzigate'], - version='0.1', + version='0.1.0', description='Interface library for ZiGate (http://zigate./fr)', author='Frédéric HARS & Vesa YLIKYLÄ', author_email='frederic.hars@gmail.com', url='https://github.com/elric91/ZiGate', - download_url='https://github.com/elric91/ZiGate/archive/0.1.tar.gz', + download_url='https://github.com/elric91/ZiGate/archive/v0.1.0-beta.tar.gz', keywords=['zigate', 'zigbee', 'python3'], classifiers=[ 'Development Status :: 4 - Beta',