Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions plugwise_usb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,30 +598,20 @@ def _update_loop(self):
"""
self._run_update_thread = True
_discover_counter = 0
_sync_clock = False
day_of_month = datetime.now().day
try:
while self._run_update_thread:
if datetime.now().day != day_of_month:
day_of_month = datetime.now().day
_sync_clock = True
for mac, device in self._device_nodes.items():
if device:
if device.battery_powered:
# Check availability state of SED's
self._check_availability_of_seds(mac)
elif device.measures_power:
# Request current power usage of those that reply on ping
device.do_ping(device.request_power_update)
else:
# Do ping request for all non SED's
device.do_ping()

if device.measures_power:
# Request current power usage
device.request_power_update()
# Sync internal clock of power measure nodes once a day
if _sync_clock:
device.sync_clock()
_sync_clock = False

# Do a single ping for undiscovered nodes once per 10 update cycles
if _discover_counter == 10:
for mac in self._nodes_not_discovered:
Expand Down
2 changes: 2 additions & 0 deletions plugwise_usb/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ def _post_message_action(self, seq_id, ack_response=None, request="unknown"):
request,
str(seq_id),
)
#Still save it to try and get it back into sync
self.last_seq_id = seq_id
if resend_request:
self.resend(seq_id)

Expand Down
7 changes: 5 additions & 2 deletions plugwise_usb/messages/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,18 @@ class CircleClockSetRequest(NodeRequest):

ID = b"0016"

def __init__(self, mac, dt):
def __init__(self, mac, dt, reset=False):
super().__init__(mac)
passed_days = dt.day - 1
month_minutes = (passed_days * 24 * 60) + (dt.hour * 60) + dt.minute
this_date = DateTime(dt.year, dt.month, month_minutes)
this_time = Time(dt.hour, dt.minute, dt.second)
day_of_week = Int(dt.weekday(), 2)
# FIXME: use LogAddr instead
log_buf_addr = String("FFFFFFFF", 8)
if reset:
log_buf_addr = String("00044000", 8)
else:
log_buf_addr = String("FFFFFFFF", 8)
self.args += [this_date, log_buf_addr, this_time, day_of_week]


Expand Down
8 changes: 4 additions & 4 deletions plugwise_usb/nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ def available(self, state: bool):
if state:
if not self._available:
self._available = True
_LOGGER.debug(
"Mark node %s available",
_LOGGER.info(
"Marking node %s available",
self.mac,
)
self.do_callback(FEATURE_AVAILABLE["id"])
else:
if self._available:
self._available = False
_LOGGER.debug(
"Mark node %s unavailable",
_LOGGER.info(
"Marking node %s unavailable",
self.mac,
)
self.do_callback(FEATURE_AVAILABLE["id"])
Expand Down
Loading