Skip to content

Commit 9bdae8a

Browse files
committed
Create helper _update_energy_current_hour
1 parent 91852f0 commit 9bdae8a

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

plugwise/nodes/circle.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,12 @@ def _response_power_usage(self, message: CirclePowerUsageResponse):
334334
self.do_callback(FEATURE_POWER_USE_LAST_8_SEC["id"])
335335
# Power consumption current hour
336336
if message.pulse_hour_consumed.value == -1:
337-
message.pulse_hour_consumed.value = 0
338337
_LOGGER.debug(
339-
"1 hour consumption power pulse counter for node %s has value of -1, corrected to 0",
338+
"1 hour consumption power pulse counter for node %s has value of -1, drop value",
340339
self.mac,
341340
)
342-
if self._energy_pulses_current_hour != message.pulse_hour_consumed.value:
343-
self._energy_pulses_current_hour = message.pulse_hour_consumed.value
344-
self.do_callback(FEATURE_POWER_CONSUMPTION_CURRENT_HOUR["id"])
341+
else:
342+
self._update_energy_current_hour(message.pulse_hour_consumed.value)
345343

346344
# Update energy consumption today
347345
self._update_energy_today_now()
@@ -500,8 +498,23 @@ def _calc_todays_energy_pulses(self):
500498
)
501499
return _energy_use
502500

501+
def _update_energy_current_hour(self, _pulses_cur_hour):
502+
"""Update energy consumption (pulses) of current hour"""
503+
_LOGGER.debug(
504+
"_update_energy_current_hour for %s | counter = %s, update= %s",
505+
self.mac,
506+
str(self._energy_pulses_current_hour),
507+
str(_pulses_cur_hour),
508+
)
509+
if (
510+
self._energy_pulses_current_hour is None
511+
or self._energy_pulses_current_hour != _pulses_cur_hour
512+
):
513+
self._energy_pulses_current_hour = _pulses_cur_hour
514+
self.do_callback(FEATURE_POWER_CONSUMPTION_CURRENT_HOUR["id"])
515+
503516
def _update_energy_today_now(self):
504-
"""Update energy consumption (kWh) of today up to now"""
517+
"""Update energy consumption (pulses) of today up to now"""
505518
_pulses_today_now = self._calc_todays_energy_pulses()
506519
_LOGGER.debug(
507520
"_update_energy_today_now for %s | counter = %s, update= %s",

0 commit comments

Comments
 (0)