11"""Energy counter."""
2+
23from __future__ import annotations
34
45from datetime import datetime , timedelta
@@ -81,21 +82,17 @@ def add_empty_log(self, address: int, slot: int) -> None:
8182 """Add empty energy log record to mark any start of beginning of energy log collection."""
8283 self ._pulse_collection .add_empty_log (address , slot )
8384
84- def add_pulse_log (
85+ def add_pulse_log ( # pylint: disable=too-many-arguments
8586 self ,
8687 address : int ,
8788 slot : int ,
8889 timestamp : datetime ,
8990 pulses : int ,
90- import_only : bool = False
91- ) -> None : # pylint: disable=too-many-arguments
91+ import_only : bool = False ,
92+ ) -> None :
9293 """Add pulse log."""
9394 if self ._pulse_collection .add_log (
94- address ,
95- slot ,
96- timestamp ,
97- pulses ,
98- import_only
95+ address , slot , timestamp , pulses , import_only
9996 ):
10097 if not import_only :
10198 self .update ()
@@ -160,45 +157,37 @@ def update(self) -> None:
160157 self ._pulse_collection .recalculate_missing_log_addresses ()
161158 if self ._calibration is None :
162159 return
163- self ._energy_statistics .log_interval_consumption = self ._pulse_collection .log_interval_consumption
164- self ._energy_statistics .log_interval_production = self ._pulse_collection .log_interval_production
160+ self ._energy_statistics .log_interval_consumption = (
161+ self ._pulse_collection .log_interval_consumption
162+ )
163+ self ._energy_statistics .log_interval_production = (
164+ self ._pulse_collection .log_interval_production
165+ )
165166 (
166167 self ._energy_statistics .hour_consumption ,
167168 self ._energy_statistics .hour_consumption_reset ,
168- ) = self ._counters [EnergyType .CONSUMPTION_HOUR ].update (
169- self ._pulse_collection
170- )
169+ ) = self ._counters [EnergyType .CONSUMPTION_HOUR ].update (self ._pulse_collection )
171170 (
172171 self ._energy_statistics .day_consumption ,
173172 self ._energy_statistics .day_consumption_reset ,
174- ) = self ._counters [EnergyType .CONSUMPTION_DAY ].update (
175- self ._pulse_collection
176- )
173+ ) = self ._counters [EnergyType .CONSUMPTION_DAY ].update (self ._pulse_collection )
177174 (
178175 self ._energy_statistics .week_consumption ,
179176 self ._energy_statistics .week_consumption_reset ,
180- ) = self ._counters [EnergyType .CONSUMPTION_WEEK ].update (
181- self ._pulse_collection
182- )
177+ ) = self ._counters [EnergyType .CONSUMPTION_WEEK ].update (self ._pulse_collection )
183178
184179 (
185180 self ._energy_statistics .hour_production ,
186181 self ._energy_statistics .hour_production_reset ,
187- ) = self ._counters [EnergyType .PRODUCTION_HOUR ].update (
188- self ._pulse_collection
189- )
182+ ) = self ._counters [EnergyType .PRODUCTION_HOUR ].update (self ._pulse_collection )
190183 (
191184 self ._energy_statistics .day_production ,
192185 self ._energy_statistics .day_production_reset ,
193- ) = self ._counters [EnergyType .PRODUCTION_DAY ].update (
194- self ._pulse_collection
195- )
186+ ) = self ._counters [EnergyType .PRODUCTION_DAY ].update (self ._pulse_collection )
196187 (
197188 self ._energy_statistics .week_production ,
198189 self ._energy_statistics .week_production_reset ,
199- ) = self ._counters [EnergyType .PRODUCTION_WEEK ].update (
200- self ._pulse_collection
201- )
190+ ) = self ._counters [EnergyType .PRODUCTION_WEEK ].update (self ._pulse_collection )
202191
203192 @property
204193 def timestamp (self ) -> datetime | None :
@@ -223,9 +212,7 @@ def __init__(
223212 """Initialize energy counter based on energy id."""
224213 self ._mac = mac
225214 if energy_id not in ENERGY_COUNTERS :
226- raise EnergyError (
227- f"Invalid energy id '{ energy_id } ' for Energy counter"
228- )
215+ raise EnergyError (f"Invalid energy id '{ energy_id } ' for Energy counter" )
229216 self ._calibration : EnergyCalibration | None = None
230217 self ._duration = "hour"
231218 if energy_id in ENERGY_DAY_COUNTERS :
@@ -311,9 +298,7 @@ def update(
311298 if self ._energy_id in ENERGY_HOUR_COUNTERS :
312299 last_reset = last_reset .replace (minute = 0 , second = 0 , microsecond = 0 )
313300 elif self ._energy_id in ENERGY_DAY_COUNTERS :
314- last_reset = last_reset .replace (
315- hour = 0 , minute = 0 , second = 0 , microsecond = 0
316- )
301+ last_reset = last_reset .replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
317302 elif self ._energy_id in ENERGY_WEEK_COUNTERS :
318303 last_reset = last_reset - timedelta (days = last_reset .weekday ())
319304 last_reset = last_reset .replace (
0 commit comments