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

Commit

Permalink
release 0.40.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Sébastien RAMAGE committed Aug 25, 2020
2 parents f01e226 + 1c5c33c commit d1ec44f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
13 changes: 11 additions & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import shutil
import tempfile
import datetime
from zigate import responses, transport, core, clusters
from binascii import hexlify, unhexlify
import time
Expand Down Expand Up @@ -751,14 +752,22 @@ def test_refresh(self):
device.set_attribute(1, 0x0006, {'attribute': 0, 'lqi': 255, 'data': '0'})
device.set_attribute(1, 0x0006, {'attribute': 2, 'lqi': 255, 'data': '0'})
self.zigate._devices['1234'] = device
device.refresh_device()
device.refresh_device(force=True)
self.assertEqual(hexlify(self.zigate.connection.get_last_cmd()),
b'0212340101000600000000010000'
)
device.refresh_device(True)
device.refresh_device(full=True, force=True)
self.assertEqual(hexlify(self.zigate.connection.get_last_cmd()),
b'02123401010006000000000200000002'
)
self.zigate.connection.sent = []
device.refresh_device()
self.assertIsNone(self.zigate.connection.get_last_cmd())
device.info['last_seen'] = datetime.datetime(2020, 1 , 1).strftime('%Y-%m-%d %H:%M:%S')
device.refresh_device()
self.assertEqual(hexlify(self.zigate.connection.get_last_cmd()),
b'0212340101000600000000010000'
)

def test_write_attribute(self):
self.zigate.write_attribute_request('abcd', 1, 0xfc01, [(0, 0x09, b'\x01\x01')])
Expand Down
32 changes: 28 additions & 4 deletions zigate/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,14 +1308,19 @@ def _neighbours_table2(self):
LOGGER.debug('Gathered neighbours table: %s', neighbours)
return neighbours

def refresh_device(self, addr, full=False):
def refresh_device(self, addr, full=False, force=False):
'''
convenient function to refresh device attribute
if full is true, try to read all known attributes
else only some specific attributes related to known clusters.
if force is false, only refresh if the device has not been seen
for more than an one hour
'''
device = self.get_device_from_addr(addr)
if not device:
return
device.refresh_device(full)
return
device.refresh_device(full, force)

def discover_device(self, addr, force=False):
'''
Expand Down Expand Up @@ -2830,8 +2835,14 @@ def get_type(self, wait=True):
typ = self.get_value('type')
return typ

def refresh_device(self, full=False):
def refresh_device(self, full=False, force=False):
to_read = {}
if not force:
last_1h = datetime.datetime.now() - datetime.timedelta(hours=1)
last_1h = last_1h.strftime('%Y-%m-%d %H:%M:%S')
if self.last_seen > last_1h:
LOGGER.debug('Last seen less than an hour, ignoring refresh')
return
if full:
for attribute in self.attributes:
k = (attribute['endpoint'], attribute['cluster'])
Expand All @@ -2841,6 +2852,12 @@ def refresh_device(self, full=False):
else:
endpoints_list = list(self.endpoints.items())
for endpoint_id, endpoint in endpoints_list:
# tries to read the type as a kind of ping
if 0x0000 in endpoint['in_clusters']:
k = (endpoint_id, 0x0000)
if k not in to_read:
to_read[k] = []
to_read[k].append(0x0005)
if 0x0006 in endpoint['in_clusters']:
k = (endpoint_id, 0x0006)
if k not in to_read:
Expand Down Expand Up @@ -3090,6 +3107,13 @@ def _handle_quirks(self, attribute):
(0x01, 0x0403, 0x0000, int(values[102] / 100)),
(0x01, 0x0403, 0x0010, values[102] / 10),
]
elif self.get_type(False) == 'lumi.ctrl_neutral1':
data_map += [(0x02, 0x0006, 0x0000, values[100]),
]
elif self.get_type(False) == 'lumi.ctrl_neutral2':
data_map += [(0x02, 0x0006, 0x0000, values[100]),
(0x03, 0x0006, 0x0000, values[101]),
]
for endpoint_id, cluster_id, attribute_id, value in data_map:
self.set_attribute(endpoint_id, cluster_id, {'attribute': attribute_id, 'data': value})

Expand Down
2 changes: 1 addition & 1 deletion zigate/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
#


__version__ = '0.40.5'
__version__ = '0.40.6'

0 comments on commit d1ec44f

Please sign in to comment.