Skip to content

Commit f2f5990

Browse files
committed
Disable week statistics, don't update production-statistics when no production
1 parent fac1ea9 commit f2f5990

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

plugwise_usb/nodes/helpers/counter.py

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class EnergyType(Enum):
3030
EnergyType.PRODUCTION_HOUR,
3131
EnergyType.CONSUMPTION_DAY,
3232
EnergyType.PRODUCTION_DAY,
33-
EnergyType.CONSUMPTION_WEEK,
34-
EnergyType.PRODUCTION_WEEK,
33+
# EnergyType.CONSUMPTION_WEEK,
34+
# EnergyType.PRODUCTION_WEEK,
3535
)
3636
ENERGY_HOUR_COUNTERS: Final = (
3737
EnergyType.CONSUMPTION_HOUR,
@@ -49,12 +49,12 @@ class EnergyType(Enum):
4949
ENERGY_CONSUMPTION_COUNTERS: Final = (
5050
EnergyType.CONSUMPTION_HOUR,
5151
EnergyType.CONSUMPTION_DAY,
52-
EnergyType.CONSUMPTION_WEEK,
52+
# EnergyType.CONSUMPTION_WEEK,
5353
)
5454
ENERGY_PRODUCTION_COUNTERS: Final = (
5555
EnergyType.PRODUCTION_HOUR,
5656
EnergyType.PRODUCTION_DAY,
57-
EnergyType.PRODUCTION_WEEK,
57+
# EnergyType.PRODUCTION_WEEK,
5858
)
5959

6060
_LOGGER = logging.getLogger(__name__)
@@ -154,12 +154,10 @@ def update(self) -> None:
154154
self._pulse_collection.recalculate_missing_log_addresses()
155155
if self._calibration is None:
156156
return
157+
157158
self._energy_statistics.log_interval_consumption = (
158159
self._pulse_collection.log_interval_consumption
159160
)
160-
self._energy_statistics.log_interval_production = (
161-
self._pulse_collection.log_interval_production
162-
)
163161
(
164162
self._energy_statistics.hour_consumption,
165163
self._energy_statistics.hour_consumption_reset,
@@ -168,23 +166,27 @@ def update(self) -> None:
168166
self._energy_statistics.day_consumption,
169167
self._energy_statistics.day_consumption_reset,
170168
) = self._counters[EnergyType.CONSUMPTION_DAY].update(self._pulse_collection)
171-
(
172-
self._energy_statistics.week_consumption,
173-
self._energy_statistics.week_consumption_reset,
174-
) = self._counters[EnergyType.CONSUMPTION_WEEK].update(self._pulse_collection)
175-
176-
(
177-
self._energy_statistics.hour_production,
178-
self._energy_statistics.hour_production_reset,
179-
) = self._counters[EnergyType.PRODUCTION_HOUR].update(self._pulse_collection)
180-
(
181-
self._energy_statistics.day_production,
182-
self._energy_statistics.day_production_reset,
183-
) = self._counters[EnergyType.PRODUCTION_DAY].update(self._pulse_collection)
184-
(
185-
self._energy_statistics.week_production,
186-
self._energy_statistics.week_production_reset,
187-
) = self._counters[EnergyType.PRODUCTION_WEEK].update(self._pulse_collection)
169+
# (
170+
# self._energy_statistics.week_consumption,
171+
# self._energy_statistics.week_consumption_reset,
172+
# ) = self._counters[EnergyType.CONSUMPTION_WEEK].update(self._pulse_collection)
173+
174+
if self.pulse_collection._log_production:
175+
self._energy_statistics.log_interval_production = (
176+
self._pulse_collection.log_interval_production
177+
)
178+
(
179+
self._energy_statistics.hour_production,
180+
self._energy_statistics.hour_production_reset,
181+
) = self._counters[EnergyType.PRODUCTION_HOUR].update(self._pulse_collection)
182+
(
183+
self._energy_statistics.day_production,
184+
self._energy_statistics.day_production_reset,
185+
) = self._counters[EnergyType.PRODUCTION_DAY].update(self._pulse_collection)
186+
# (
187+
# self._energy_statistics.week_production,
188+
# self._energy_statistics.week_production_reset,
189+
# ) = self._counters[EnergyType.PRODUCTION_WEEK].update(self._pulse_collection)
188190

189191
@property
190192
def timestamp(self) -> datetime | None:
@@ -214,8 +216,8 @@ def __init__(
214216
self._duration = "hour"
215217
if energy_id in ENERGY_DAY_COUNTERS:
216218
self._duration = "day"
217-
elif energy_id in ENERGY_WEEK_COUNTERS:
218-
self._duration = "week"
219+
#elif energy_id in ENERGY_WEEK_COUNTERS:
220+
# self._duration = "week"
219221
self._energy_id: EnergyType = energy_id
220222
self._is_consumption = True
221223
self._direction = "consumption"
@@ -301,14 +303,14 @@ def update(
301303
last_reset = last_reset.replace(minute=0, second=0, microsecond=0)
302304
elif self._energy_id in ENERGY_DAY_COUNTERS:
303305
last_reset = last_reset.replace(hour=0, minute=0, second=0, microsecond=0)
304-
elif self._energy_id in ENERGY_WEEK_COUNTERS:
305-
last_reset = last_reset - timedelta(days=last_reset.weekday())
306-
last_reset = last_reset.replace(
307-
hour=0,
308-
minute=0,
309-
second=0,
310-
microsecond=0,
311-
)
306+
# elif self._energy_id in ENERGY_WEEK_COUNTERS:
307+
# last_reset = last_reset - timedelta(days=last_reset.weekday())
308+
# last_reset = last_reset.replace(
309+
# hour=0,
310+
# minute=0,
311+
# second=0,
312+
# microsecond=0,
313+
# )
312314

313315
pulses, last_update = pulse_collection.collected_pulses(
314316
last_reset, self._is_consumption

0 commit comments

Comments
 (0)