Skip to content

Commit 4963f43

Browse files
authored
Merge pull request #136 from plugwise/energyloop
Update to get network more stable (at startup and looping)
2 parents 68a0039 + f8ba0ce commit 4963f43

File tree

6 files changed

+193
-264
lines changed

6 files changed

+193
-264
lines changed

plugwise_usb/__init__.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -598,30 +598,20 @@ def _update_loop(self):
598598
"""
599599
self._run_update_thread = True
600600
_discover_counter = 0
601-
_sync_clock = False
602-
day_of_month = datetime.now().day
603601
try:
604602
while self._run_update_thread:
605-
if datetime.now().day != day_of_month:
606-
day_of_month = datetime.now().day
607-
_sync_clock = True
608603
for mac, device in self._device_nodes.items():
609604
if device:
610605
if device.battery_powered:
611606
# Check availability state of SED's
612607
self._check_availability_of_seds(mac)
608+
elif device.measures_power:
609+
# Request current power usage of those that reply on ping
610+
device.do_ping(device.request_power_update)
613611
else:
614612
# Do ping request for all non SED's
615613
device.do_ping()
616614

617-
if device.measures_power:
618-
# Request current power usage
619-
device.request_power_update()
620-
# Sync internal clock of power measure nodes once a day
621-
if _sync_clock:
622-
device.sync_clock()
623-
_sync_clock = False
624-
625615
# Do a single ping for undiscovered nodes once per 10 update cycles
626616
if _discover_counter == 10:
627617
for mac in self._nodes_not_discovered:

plugwise_usb/controller.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ def _post_message_action(self, seq_id, ack_response=None, request="unknown"):
327327
request,
328328
str(seq_id),
329329
)
330+
#Still save it to try and get it back into sync
331+
self.last_seq_id = seq_id
330332
if resend_request:
331333
self.resend(seq_id)
332334

plugwise_usb/messages/requests.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,18 @@ class CircleClockSetRequest(NodeRequest):
151151

152152
ID = b"0016"
153153

154-
def __init__(self, mac, dt):
154+
def __init__(self, mac, dt, reset=False):
155155
super().__init__(mac)
156156
passed_days = dt.day - 1
157157
month_minutes = (passed_days * 24 * 60) + (dt.hour * 60) + dt.minute
158158
this_date = DateTime(dt.year, dt.month, month_minutes)
159159
this_time = Time(dt.hour, dt.minute, dt.second)
160160
day_of_week = Int(dt.weekday(), 2)
161161
# FIXME: use LogAddr instead
162-
log_buf_addr = String("FFFFFFFF", 8)
162+
if reset:
163+
log_buf_addr = String("00044000", 8)
164+
else:
165+
log_buf_addr = String("FFFFFFFF", 8)
163166
self.args += [this_date, log_buf_addr, this_time, day_of_week]
164167

165168

plugwise_usb/nodes/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ def available(self, state: bool):
6363
if state:
6464
if not self._available:
6565
self._available = True
66-
_LOGGER.debug(
67-
"Mark node %s available",
66+
_LOGGER.info(
67+
"Marking node %s available",
6868
self.mac,
6969
)
7070
self.do_callback(FEATURE_AVAILABLE["id"])
7171
else:
7272
if self._available:
7373
self._available = False
74-
_LOGGER.debug(
75-
"Mark node %s unavailable",
74+
_LOGGER.info(
75+
"Marking node %s unavailable",
7676
self.mac,
7777
)
7878
self.do_callback(FEATURE_AVAILABLE["id"])

0 commit comments

Comments
 (0)