|
1 | 1 | """Air-To-Air (DeviceType=0) device definition.""" |
| 2 | +from datetime import timedelta |
2 | 3 | from typing import Any, Dict, List, Optional |
3 | 4 |
|
4 | 5 | from pymelcloud.device import EFFECTIVE_FLAGS, Device |
| 6 | +from pymelcloud.client import Client |
5 | 7 |
|
6 | 8 | PROPERTY_TARGET_TEMPERATURE = "target_temperature" |
7 | 9 | PROPERTY_OPERATION_MODE = "operation_mode" |
@@ -136,6 +138,16 @@ def _vertical_vane_to(position: str) -> int: |
136 | 138 | class AtaDevice(Device): |
137 | 139 | """Air-to-Air device.""" |
138 | 140 |
|
| 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 | + |
139 | 151 | def apply_write(self, state: Dict[str, Any], key: str, value: Any): |
140 | 152 | """Apply writes to state object. |
141 | 153 |
|
@@ -173,15 +185,20 @@ def total_energy_consumed(self) -> Optional[float]: |
173 | 185 | """Return total consumed energy as kWh. |
174 | 186 |
|
175 | 187 | 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. |
177 | 189 | """ |
178 | 190 | if self._device_conf is None: |
179 | 191 | return None |
180 | 192 | 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: |
183 | 195 | 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 |
185 | 202 |
|
186 | 203 | @property |
187 | 204 | def room_temperature(self) -> Optional[float]: |
|
0 commit comments