Skip to content

Commit 47316a7

Browse files
committed
Black auto-update
1 parent 90a76b6 commit 47316a7

File tree

10 files changed

+94
-89
lines changed

10 files changed

+94
-89
lines changed

plugwise_usb/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,7 @@ def _pass_message_to_node(self, message, mac, discover=True):
538538
return False
539539

540540
def _watchdog_loop(self):
541-
"""Main worker loop to watch all other worker threads
542-
"""
541+
"""Main worker loop to watch all other worker threads"""
543542
time.sleep(5)
544543
circle_plus_retry_counter = 0
545544
while self._run_watchdog:

plugwise_usb/controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ 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
330+
# Still save it to try and get it back into sync
331331
self.last_seq_id = seq_id
332332
if resend_request:
333333
self.resend(seq_id)

plugwise_usb/messages/responses.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323

2424

2525
class NodeResponse(PlugwiseMessage):
26-
"""Base class for response messages received by USB-Stick.
27-
"""
26+
"""Base class for response messages received by USB-Stick."""
2827

2928
def __init__(self, format_size=None):
3029
super().__init__()
@@ -561,8 +560,7 @@ def __init__(self):
561560

562561

563562
def get_message_response(message_id, length, seq_id):
564-
"""Return message class based on sequence ID, Length of message or message ID.
565-
"""
563+
"""Return message class based on sequence ID, Length of message or message ID."""
566564
# First check for known sequence ID's
567565
if seq_id == b"FFFD":
568566
return NodeJoinAckResponse()

plugwise_usb/nodes/circle.py

Lines changed: 82 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -221,28 +221,31 @@ def request_power_update(self, callback=None):
221221
if self._energy_last_collected_timestamp < _timestamp_utcnow.replace(
222222
minute=0, second=0, microsecond=0
223223
):
224-
_LOGGER.info("Queue _last_log_address for %s at %s last_collected %s",
225-
str(self.mac),str(self._last_log_address),
226-
self._energy_last_collected_timestamp
224+
_LOGGER.info(
225+
"Queue _last_log_address for %s at %s last_collected %s",
226+
str(self.mac),
227+
str(self._last_log_address),
228+
self._energy_last_collected_timestamp,
227229
)
228230
self._request_info(self.push_last_log_address)
229231

230232
if len(self._energy_history_failed_address) > 0:
231-
_mem_address = self._energy_history_failed_address.pop(0)
232-
if self._energy_memory.get(_mem_address, 0) < 4:
233-
_LOGGER.info("Collect EnergyCounters for %s at %s",
234-
str(self.mac),
235-
str(_mem_address),
236-
)
237-
self.request_energy_counters(_mem_address)
238-
self._energy_ratelimit_collection_timestamp = _timestamp_utcnow
239-
else:
240-
_LOGGER.info(
241-
"Drop known request_energy_counters for %s at %s and clock sync",
242-
str(self.mac),
243-
str(_mem_address),
244-
)
245-
self.get_clock(self.sync_clock)
233+
_mem_address = self._energy_history_failed_address.pop(0)
234+
if self._energy_memory.get(_mem_address, 0) < 4:
235+
_LOGGER.info(
236+
"Collect EnergyCounters for %s at %s",
237+
str(self.mac),
238+
str(_mem_address),
239+
)
240+
self.request_energy_counters(_mem_address)
241+
self._energy_ratelimit_collection_timestamp = _timestamp_utcnow
242+
else:
243+
_LOGGER.info(
244+
"Drop known request_energy_counters for %s at %s and clock sync",
245+
str(self.mac),
246+
str(_mem_address),
247+
)
248+
self.get_clock(self.sync_clock)
246249
if datetime.now().day != self._last_clock_sync_day:
247250
self._last_clock_sync_day = datetime.now().day
248251
self.get_clock(self.sync_clock)
@@ -252,8 +255,7 @@ def push_last_log_address(self):
252255
self._energy_history_failed_address.append(self._last_log_address)
253256

254257
def message_for_circle(self, message):
255-
"""Process received message
256-
"""
258+
"""Process received message"""
257259
if isinstance(message, CirclePowerUsageResponse):
258260
if self.calibration:
259261
self._response_power_usage(message)
@@ -387,8 +389,7 @@ def _response_calibration(self, message: CircleCalibrationResponse):
387389
self.calibration = True
388390

389391
def pulses_to_kws(self, pulses, seconds=1):
390-
"""Converts the amount of pulses to kWs using the calaboration offsets
391-
"""
392+
"""Converts the amount of pulses to kWs using the calaboration offsets"""
392393
if pulses is None:
393394
return None
394395
if pulses == 0 or not self.calibration:
@@ -428,7 +429,7 @@ def _collect_energy_pulses(self, start_utc: datetime, end_utc: datetime):
428429
)
429430
else:
430431
_mem_address = self._energy_timestamp_memory_address(_log_timestamp)
431-
if (_mem_address is not None and _mem_address >= 0):
432+
if _mem_address is not None and _mem_address >= 0:
432433
_LOGGER.info(
433434
"_collect_energy_pulses for %s at %s | %s not found",
434435
str(self.mac),
@@ -443,7 +444,6 @@ def _collect_energy_pulses(self, start_utc: datetime, end_utc: datetime):
443444
str(_mem_address),
444445
)
445446

446-
447447
# Validate all history values where present
448448
if len(self._energy_history_failed_address) == 0:
449449
return _energy_pulses
@@ -480,12 +480,11 @@ def _update_energy_today_now(self):
480480
and self._energy_pulses_current_hour is not None
481481
):
482482
_pulses_today_now = (
483-
self._energy_pulses_today_hourly
484-
+ self._energy_pulses_current_hour
483+
self._energy_pulses_today_hourly + self._energy_pulses_current_hour
485484
)
486485

487486
_utc_hour_timestamp = datetime.utcnow().replace(
488-
minute=0, second=0, microsecond=0
487+
minute=0, second=0, microsecond=0
489488
)
490489
_local_hour = datetime.now().hour
491490
_utc_midnight_timestamp = _utc_hour_timestamp - timedelta(hours=_local_hour)
@@ -500,9 +499,9 @@ def _update_energy_today_now(self):
500499
_utc_hour_timestamp,
501500
)
502501
elif (
503-
self._energy_pulses_today_now is not None
504-
and self._energy_pulses_today_now > _pulses_today_now
505-
and self._energy_pulses_midnight_rollover < _local_midnight_timestamp
502+
self._energy_pulses_today_now is not None
503+
and self._energy_pulses_today_now > _pulses_today_now
504+
and self._energy_pulses_midnight_rollover < _local_midnight_timestamp
506505
):
507506
_LOGGER.info(
508507
"_update_energy_today_now for %s midnight rollover started old=%s, new=%s",
@@ -518,9 +517,14 @@ def _update_energy_today_now(self):
518517
)
519518
self.do_callback(FEATURE_ENERGY_CONSUMPTION_TODAY["id"])
520519
elif (
521-
self._energy_pulses_today_now is not None
522-
and self._energy_pulses_today_now > _pulses_today_now
523-
and int((self._energy_pulses_today_now-_pulses_today_now)/(self._energy_pulses_today_now+1)*100) > 1
520+
self._energy_pulses_today_now is not None
521+
and self._energy_pulses_today_now > _pulses_today_now
522+
and int(
523+
(self._energy_pulses_today_now - _pulses_today_now)
524+
/ (self._energy_pulses_today_now + 1)
525+
* 100
526+
)
527+
> 1
524528
):
525529
_LOGGER.info(
526530
"_update_energy_today_now for %s hour rollover started old=%s, new=%s",
@@ -617,12 +621,14 @@ def _update_energy_today_hourly(self, start_today: datetime, end_today: datetime
617621
def request_energy_counters(self, log_address=None, callback=None):
618622
"""Request power log of specified address"""
619623
_LOGGER.debug(
620-
"request_energy_counters for %s of address %s", str(self.mac), str(log_address)
624+
"request_energy_counters for %s of address %s",
625+
str(self.mac),
626+
str(log_address),
621627
)
622628
if not self._available:
623629
_LOGGER.debug(
624-
"Skip request_energy_counters for % is unavailable",
625-
str(self.mac),
630+
"Skip request_energy_counters for % is unavailable",
631+
str(self.mac),
626632
)
627633
return
628634
if log_address is None:
@@ -687,11 +693,12 @@ def _response_energy_counters(self, message: CircleEnergyCountersResponse):
687693
message, "pulses%d" % (_slot,)
688694
).value
689695

690-
_LOGGER.info("push _energy_memory for %s address %s slot %s stamp %s",
691-
str(self.mac),
692-
str(message.logaddr.value),
693-
str(_slot),
694-
str(_log_timestamp),
696+
_LOGGER.info(
697+
"push _energy_memory for %s address %s slot %s stamp %s",
698+
str(self.mac),
699+
str(message.logaddr.value),
700+
str(_slot),
701+
str(_log_timestamp),
695702
)
696703

697704
# Store last populated _slot
@@ -710,9 +717,11 @@ def _response_energy_counters(self, message: CircleEnergyCountersResponse):
710717
self._last_collected_address_timestamp = _log_timestamp
711718

712719
# Trigger history rollover
713-
_LOGGER.info('history_rollover %s %s %s',str(_log_timestamp),
714-
str(_utc_hour_timestamp),
715-
str(self._energy_last_rollover_timestamp),
720+
_LOGGER.info(
721+
"history_rollover %s %s %s",
722+
str(_log_timestamp),
723+
str(_utc_hour_timestamp),
724+
str(self._energy_last_rollover_timestamp),
716725
)
717726
if (
718727
_log_timestamp == _utc_hour_timestamp
@@ -739,7 +748,7 @@ def _response_energy_counters(self, message: CircleEnergyCountersResponse):
739748
self._energy_consumption_today_reset = _local_midnight_timestamp
740749
_midnight_rollover = True
741750
if self._energy_last_collected_timestamp == datetime.utcnow().replace(
742-
minute=0, second=0, microsecond=0
751+
minute=0, second=0, microsecond=0
743752
):
744753
self._update_energy_previous_hour(_utc_hour_timestamp)
745754
self._update_energy_today_hourly(
@@ -751,24 +760,31 @@ def _response_energy_counters(self, message: CircleEnergyCountersResponse):
751760
_utc_midnight_timestamp,
752761
)
753762
else:
754-
_LOGGER.info("CircleEnergyCounter failed for %s at %s|%s count %s",
755-
str(self.mac),
756-
str(message.logaddr.value),
757-
str(self._last_log_address),
758-
str(self._energy_last_collected_count),
763+
_LOGGER.info(
764+
"CircleEnergyCounter failed for %s at %s|%s count %s",
765+
str(self.mac),
766+
str(message.logaddr.value),
767+
str(self._last_log_address),
768+
str(self._energy_last_collected_count),
759769
)
760-
self._energy_last_collected_count +=1
770+
self._energy_last_collected_count += 1
761771

762772
if (
763-
message.logaddr.value == self._last_log_address
764-
and self._energy_last_collected_count > 3
773+
message.logaddr.value == self._last_log_address
774+
and self._energy_last_collected_count > 3
765775
):
766-
if self._energy_history_failed_address.count(self._last_log_address-1) == 0:
767-
self._energy_history_failed_address.append(self._last_log_address-1)
776+
if (
777+
self._energy_history_failed_address.count(
778+
self._last_log_address - 1
779+
)
780+
== 0
781+
):
782+
self._energy_history_failed_address.append(
783+
self._last_log_address - 1
784+
)
768785
_LOGGER.info("Resetting CircleEnergyCounter due to logaddress offset")
769786

770-
771-
# Cleanup energy history for more than 48 hours
787+
# Cleanup energy history for more than 48 hours
772788
_48_hours_ago = datetime.utcnow().replace(
773789
minute=0, second=0, microsecond=0
774790
) - timedelta(hours=48)
@@ -814,7 +830,6 @@ def set_clock(self, callback=None):
814830
callback,
815831
)
816832

817-
818833
def sync_clock(self, max_drift=0):
819834
"""Resync clock of node if time has drifted more than MAX_TIME_DRIFT"""
820835
if self._clock_offset is not None:
@@ -832,7 +847,7 @@ def _energy_timestamp_memory_address(self, utc_timestamp: datetime):
832847
"""Return memory address for given energy counter timestamp"""
833848
if self._last_collected_address is None:
834849
return None
835-
#Should already be hour timestamp, but just to be sure.
850+
# Should already be hour timestamp, but just to be sure.
836851
_utc_now_timestamp = self._last_collected_address_timestamp.replace(
837852
minute=0, second=0, microsecond=0
838853
)
@@ -855,12 +870,13 @@ def _energy_timestamp_memory_address(self, utc_timestamp: datetime):
855870
_address -= 1
856871
_slot = 4
857872
_hours += 1
858-
_LOGGER.info("Calculated address %s at %s from %s at %s with %s|%s",
859-
_address,
860-
utc_timestamp,
861-
self._last_log_address,
862-
_utc_now_timestamp,
863-
_sslot,
864-
_hours_offset,
873+
_LOGGER.info(
874+
"Calculated address %s at %s from %s at %s with %s|%s",
875+
_address,
876+
utc_timestamp,
877+
self._last_log_address,
878+
_utc_now_timestamp,
879+
_sslot,
880+
_hours_offset,
865881
)
866882
return _address

plugwise_usb/nodes/circle_plus.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ def __init__(self, mac, address, message_sender):
2626
self.get_real_time_clock(self.sync_realtime_clock)
2727

2828
def message_for_circle_plus(self, message):
29-
"""Process received message
30-
"""
29+
"""Process received message"""
3130
if isinstance(message, CirclePlusRealTimeClockResponse):
3231
self._response_realtime_clock(message)
3332
elif isinstance(message, CirclePlusScanResponse):

plugwise_usb/nodes/scan.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ def motion(self) -> bool:
4545
return self._motion_state
4646

4747
def message_for_scan(self, message):
48-
"""Process received message
49-
"""
48+
"""Process received message"""
5049
if isinstance(message, NodeSwitchGroupResponse):
5150
_LOGGER.debug(
5251
"Switch group %s to state %s received from %s",

plugwise_usb/nodes/sed.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ def __init__(self, mac, address, message_sender):
4242
self._battery_powered = True
4343

4444
def message_for_sed(self, message):
45-
"""Process received message
46-
"""
45+
"""Process received message"""
4746
if isinstance(message, NodeAwakeResponse):
4847
self._process_awake_response(message)
4948
elif isinstance(message, NodeAckLargeResponse):

plugwise_usb/nodes/sense.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ def temperature(self) -> int:
4444
return self._temperature
4545

4646
def message_for_sense(self, message):
47-
"""Process received message
48-
"""
47+
"""Process received message"""
4948
if isinstance(message, SenseReportResponse):
5049
self._process_sense_report(message)
5150
else:

plugwise_usb/nodes/switch.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def switch(self) -> bool:
2727
return self._switch_state
2828

2929
def message_for_switch(self, message):
30-
"""Process received message
31-
"""
30+
"""Process received message"""
3231
if isinstance(message, NodeSwitchGroupResponse):
3332
_LOGGER.debug(
3433
"Switch group request %s received from %s for group id %s",

plugwise_usb/parser.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@ def __init__(self, message_processor):
3535
self._message = None
3636

3737
def feed(self, data):
38-
"""Add new incoming data to buffer and try to process
39-
"""
38+
"""Add new incoming data to buffer and try to process"""
4039
_LOGGER.debug("Feed data: %s", str(data))
4140
self._buffer += data
4241
if len(self._buffer) >= 8:
4342
if not self._parsing:
4443
self.parse_data()
4544

4645
def next_message(self, message):
47-
"""Process next packet if present
48-
"""
46+
"""Process next packet if present"""
4947
try:
5048
self.message_processor(message)
5149
# TODO: narrow exception
@@ -58,8 +56,7 @@ def next_message(self, message):
5856
_LOGGER.error(err, exc_info=True)
5957

6058
def parse_data(self):
61-
"""Process next set of packet data
62-
"""
59+
"""Process next set of packet data"""
6360
_LOGGER.debug("Parse data: %s ", str(self._buffer))
6461
if not self._parsing:
6562
self._parsing = True

0 commit comments

Comments
 (0)