Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
doudz committed Jul 31, 2018
1 parent 24e3a9d commit 5676537
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
9 changes: 6 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Usage
logging.root.setLevel(logging.DEBUG)
import zigate
z = zigate.ZiGate(port=None) # Leave None to auto-discover the port
z = zigate.connect(port=None) # Leave None to auto-discover the port
print(z.get_version())
OrderedDict([('major', 1), ('installer', '30c'), ('rssi', 0), ('version', '3.0c')])
Expand Down Expand Up @@ -100,7 +100,7 @@ We use pydispatcher for callback
dispatcher.connect(my_callback, zigate.ZIGATE_ATTRIBUTE_UPDATED)
z = zigate.ZiGate()
z = zigate.connect()
# to catch any events
dispatcher.connect(my_callback, dispatcher.Any)
Expand Down Expand Up @@ -142,7 +142,10 @@ WiFi ZiGate is also supported :
.. code-block:: python
import zigate
z = zigate.ZiGateWiFi(host='192.168.0.10', port=9999)
z = zigate.connect(host='192.168.0.10')
# or if you want to set the port
z = zigate.connect(host='192.168.0.10:1234')
Expand Down
32 changes: 28 additions & 4 deletions zigate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,33 @@
'dispatcher']


def connect(port=None, host=None):
def connect(port=None, host=None,
path='~/.zigate.json',
auto_start=True,
auto_save=True):
'''
connect to zigate USB or WiFi
specify USB port OR host IP
Example :
port='/dev/ttyS0'
host='192.168.0.10' OR '192.168.0.10:1234'
in both case you could set 'auto' to auto discover the zigate
'''
if host:
z = ZiGateWiFi(host)
port = None
host = host.split(':', 1)
if len(host) == 2:
port = int(host[1])
host = host[0]
z = ZiGateWiFi(host,
port,
path=path,
auto_start=auto_start,
auto_save=auto_save)
else:
z = ZiGate(port)
return z
z = ZiGate(port,
path=path,
auto_start=auto_start,
auto_save=auto_save)
return z

0 comments on commit 5676537

Please sign in to comment.