Skip to content

Commit

Permalink
add default value to get_property_value
Browse files Browse the repository at this point in the history
  • Loading branch information
doudz committed Jul 4, 2018
1 parent afa60b4 commit 229f18e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
2 changes: 1 addition & 1 deletion zigate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .const import *
from pydispatch import dispatcher

__version__ = '0.16.4'
__version__ = '0.16.5'

__all__ = ['ZiGate', 'ZiGateWiFi',
'dispatcher']
36 changes: 10 additions & 26 deletions zigate/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,23 +889,10 @@ def touchlink_factory_reset(self):
return self.send_data(0x00D2)

def read_attribute_request(self, addr, endpoint, cluster, attribute):
"""
'''
Read Attribute request
:param str addr: length 4. Example "AB01"
:param int endpoint: length 2. Example "01"
:param int cluster: length 4. Example "0000"
:param int attribute: length 4. Example "0005"
attribute can be a unique int or a list of int
Examples:
========
Replace device_address AB01 with your devices address.
All clusters and parameters are not available on every device.
- Get device manufacturer name: read_attribute('AB01', '01', '0000', '0004')
- Get device name: read_attribute('AB01', '01', '0000', '0005')
- Get device battery voltage: read_attribute('AB01', '01', '0001', '0006')
"""
'''
addr = self.__addr(addr)
direction = 0
manufacturer_specific = 0
Expand All @@ -919,24 +906,20 @@ def read_attribute_request(self, addr, endpoint, cluster, attribute):
self.send_data(0x0100, data)

def write_attribute_request(self, addr, endpoint, cluster, attribute):
"""
'''
Write Attribute request
:param str addr: length 4. Example "AB01"
:param int endpoint: length 2. Example "01"
:param int cluster: length 4. Example "0000"
:param int attribute: length 4. Example "0005"
attribute can be a unique int or a list of int
"""
'''
addr = self.__addr(addr)
direction = 0
manufacturer_specific = 0
manufacturer_id = 0
if not isinstance(attribute, list):
attribute = [attribute]
length = len(attribute)
data = struct.pack('!BHBBHBBHB{}H'.format(length), 2, addr, 1, endpoint, cluster,
direction, manufacturer_specific,
data = struct.pack('!BHBBHBBHB{}H'.format(length), 2, addr, 1,
endpoint, cluster,
direction, manufacturer_specific,
manufacturer_id, length, *attribute)
self.send_data(0x0110, data)

Expand Down Expand Up @@ -1604,13 +1587,14 @@ def get_property(self, name, extended_info=False):
return attr
return attribute

def get_property_value(self, name):
def get_property_value(self, name, default=None):
'''
return attribute value matching name
'''
prop = self.get_property(name)
if prop:
return prop['value']
return prop.get('value', default)
return default

@property
def properties(self):
Expand Down

0 comments on commit 229f18e

Please sign in to comment.