Skip to content

Commit adb820e

Browse files
author
Vilppu Vuorinen
committed
Add a guard against zero energy meter readings
1 parent 89b6540 commit adb820e

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- Guard against zero Ata device energy meter reading. Latest firmware returns occasional zeroes breaking energy consumption integrations.
810

911
## [2.11.0] - 2021-10-03
1012
### Added

pymelcloud/ata_device.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""Air-To-Air (DeviceType=0) device definition."""
2+
from datetime import timedelta
23
from typing import Any, Dict, List, Optional
34

45
from pymelcloud.device import EFFECTIVE_FLAGS, Device
6+
from pymelcloud.client import Client
57

68
PROPERTY_TARGET_TEMPERATURE = "target_temperature"
79
PROPERTY_OPERATION_MODE = "operation_mode"
@@ -136,6 +138,16 @@ def _vertical_vane_to(position: str) -> int:
136138
class AtaDevice(Device):
137139
"""Air-to-Air device."""
138140

141+
def __init__(
142+
self,
143+
device_conf: Dict[str, Any],
144+
client: Client,
145+
set_debounce=timedelta(seconds=1),
146+
):
147+
"""Initialize an ATA device."""
148+
super().__init__(device_conf, client, set_debounce)
149+
self.last_energy_value = None
150+
139151
def apply_write(self, state: Dict[str, Any], key: str, value: Any):
140152
"""Apply writes to state object.
141153
@@ -173,15 +185,20 @@ def total_energy_consumed(self) -> Optional[float]:
173185
"""Return total consumed energy as kWh.
174186
175187
The update interval is extremely slow and inconsistent. Empirical evidence
176-
suggests can vary between 1h 30min and 3h.
188+
suggests that it can vary between 1h 30min and 3h.
177189
"""
178190
if self._device_conf is None:
179191
return None
180192
device = self._device_conf.get("Device", {})
181-
reading = device.get("CurrentEnergyConsumed", None)
182-
if reading is None:
193+
value = device.get("CurrentEnergyConsumed", None)
194+
if value is None:
183195
return None
184-
return reading / 1000.0
196+
197+
if value == 0.0:
198+
return self.last_energy_value
199+
200+
self.last_energy_value = value / 1000.0
201+
return self.last_energy_value
185202

186203
@property
187204
def room_temperature(self) -> Optional[float]:

0 commit comments

Comments
 (0)