|
1 | 1 | """Base MELCloud device.""" |
| 2 | + |
2 | 3 | import asyncio |
3 | 4 | from abc import ABC, abstractmethod |
4 | 5 | from datetime import datetime, timedelta, timezone |
5 | | -from decimal import Decimal, ROUND_HALF_UP |
| 6 | +from decimal import ROUND_HALF_UP, Decimal |
6 | 7 | from typing import Any, Dict, List, Optional |
7 | 8 |
|
8 | 9 | from pymelcloud.client import Client |
9 | 10 | from pymelcloud.const import ( |
| 11 | + ACCESS_LEVEL, |
10 | 12 | DEVICE_TYPE_LOOKUP, |
11 | 13 | DEVICE_TYPE_UNKNOWN, |
12 | 14 | UNIT_TEMP_CELSIUS, |
13 | 15 | UNIT_TEMP_FAHRENHEIT, |
14 | | - ACCESS_LEVEL, |
15 | 16 | ) |
16 | 17 |
|
17 | 18 | PROPERTY_POWER = "power" |
@@ -64,18 +65,21 @@ def get_state_prop(self, name: str) -> Optional[Any]: |
64 | 65 |
|
65 | 66 | def round_temperature(self, temperature: float) -> float: |
66 | 67 | """Round a temperature to the nearest temperature increment.""" |
67 | | - return float( |
68 | | - Decimal(str(temperature / self.temperature_increment)) |
69 | | - .quantize(Decimal('1'), rounding=ROUND_HALF_UP) |
70 | | - ) * self.temperature_increment |
| 68 | + return ( |
| 69 | + float( |
| 70 | + Decimal(str(temperature / self.temperature_increment)).quantize( |
| 71 | + Decimal("1"), rounding=ROUND_HALF_UP |
| 72 | + ) |
| 73 | + ) |
| 74 | + * self.temperature_increment |
| 75 | + ) |
71 | 76 |
|
72 | 77 | @abstractmethod |
73 | 78 | def apply_write(self, state: Dict[str, Any], key: str, value: Any): |
74 | 79 | """Apply writes to state object. |
75 | 80 |
|
76 | 81 | Used for property validation, do not modify device state. |
77 | 82 | """ |
78 | | - pass |
79 | 83 |
|
80 | 84 | async def update(self): |
81 | 85 | """Fetch state of the device from MELCloud. |
@@ -217,7 +221,7 @@ def daily_energy_consumed(self) -> Optional[float]: |
217 | 221 |
|
218 | 222 | consumption = 0 |
219 | 223 |
|
220 | | - for mode in ['Heating', 'Cooling', 'Auto', 'Dry', 'Fan', 'Other']: |
| 224 | + for mode in ["Heating", "Cooling", "Auto", "Dry", "Fan", "Other"]: |
221 | 225 | previous_reports = self._energy_report.get(mode, [0.0]) |
222 | 226 | if previous_reports: |
223 | 227 | last_report = previous_reports[-1] |
|
0 commit comments