Skip to content

Commit 496adbf

Browse files
committed
Clean it a bit...
1 parent 9a6bdbf commit 496adbf

21 files changed

+85
-69
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ availability issues.
2929

3030
* Air-to-air heat pumps (DeviceType=0)
3131
* Air-to-water heat pumps (DeviceType=1)
32-
* Energy Recovery Ventilators (DeviceType=3)
32+
* Energy Recovery Ventilators (DeviceType=3)
3333

3434
## Read
3535

src/pymelcloud/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
"""MELCloud client library."""
2+
23
from datetime import timedelta
34
from typing import Dict, List, Optional
45

56
from aiohttp import ClientSession
67

78
from pymelcloud.ata_device import AtaDevice
89
from pymelcloud.atw_device import AtwDevice
9-
from pymelcloud.erv_device import ErvDevice
1010
from pymelcloud.client import Client as _Client
1111
from pymelcloud.client import login as _login
1212
from pymelcloud.const import DEVICE_TYPE_ATA, DEVICE_TYPE_ATW, DEVICE_TYPE_ERV
1313
from pymelcloud.device import Device
14+
from pymelcloud.erv_device import ErvDevice
1415

1516

1617
async def login(
17-
email: str, password: str, session: Optional[ClientSession] = None,
18+
email: str,
19+
password: str,
20+
session: Optional[ClientSession] = None,
1821
) -> str:
1922
"""Log in to MELCloud with given credentials.
2023
2124
Returns access token.
2225
"""
23-
_client = await _login(email, password, session,)
26+
_client = await _login(email, password, session)
2427
return _client.token
2528

2629

@@ -37,9 +40,10 @@ async def get_devices(
3740
should be fetched only once during application life cycle to leverage the request
3841
pooling and rate limits.
3942
40-
Keyword arguments:
43+
Keyword Arguments:
4144
conf_update_interval -- rate limit for fetching device confs. (default = 5 min)
4245
device_set_debounce -- debounce time for writing device state. (default = 1 s)
46+
4347
"""
4448
_client = _Client(
4549
token,

src/pymelcloud/ata_device.py

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

5-
from pymelcloud.device import EFFECTIVE_FLAGS, Device
66
from pymelcloud.client import Client
7+
from pymelcloud.device import EFFECTIVE_FLAGS, Device
78

89
PROPERTY_TARGET_TEMPERATURE = "target_temperature"
910
PROPERTY_OPERATION_MODE = "operation_mode"

src/pymelcloud/atw_device.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Air-To-Water (DeviceType=1) device definition."""
2+
23
from typing import Any, Callable, Dict, List, Optional
34

45
from pymelcloud.device import EFFECTIVE_FLAGS, Device
@@ -209,7 +210,7 @@ async def set_target_flow_temperature(self, target_flow_temperature):
209210
"""Set target flow temperature for the currently active operation mode."""
210211
op_mode = self.operation_mode
211212
if op_mode is None:
212-
return None
213+
return
213214

214215
if op_mode in [
215216
ZONE_OPERATION_MODE_COOL_THERMOSTAT,

src/pymelcloud/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""MEL API access."""
2+
23
from datetime import datetime, timedelta
34
from typing import Any, Dict, List, Optional
45

@@ -209,7 +210,7 @@ async def fetch_energy_report(self, device) -> Optional[Dict[Any, Any]]:
209210
"DeviceId": device_id,
210211
"UseCurrency": False,
211212
"FromDate": f"{from_str}T00:00:00",
212-
"ToDate": f"{to_str}T00:00:00"
213+
"ToDate": f"{to_str}T00:00:00",
213214
},
214215
raise_for_status=True,
215216
) as resp:

src/pymelcloud/device.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
"""Base MELCloud device."""
2+
23
import asyncio
34
from abc import ABC, abstractmethod
45
from datetime import datetime, timedelta, timezone
5-
from decimal import Decimal, ROUND_HALF_UP
6+
from decimal import ROUND_HALF_UP, Decimal
67
from typing import Any, Dict, List, Optional
78

89
from pymelcloud.client import Client
910
from pymelcloud.const import (
11+
ACCESS_LEVEL,
1012
DEVICE_TYPE_LOOKUP,
1113
DEVICE_TYPE_UNKNOWN,
1214
UNIT_TEMP_CELSIUS,
1315
UNIT_TEMP_FAHRENHEIT,
14-
ACCESS_LEVEL,
1516
)
1617

1718
PROPERTY_POWER = "power"
@@ -64,18 +65,21 @@ def get_state_prop(self, name: str) -> Optional[Any]:
6465

6566
def round_temperature(self, temperature: float) -> float:
6667
"""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+
)
7176

7277
@abstractmethod
7378
def apply_write(self, state: Dict[str, Any], key: str, value: Any):
7479
"""Apply writes to state object.
7580
7681
Used for property validation, do not modify device state.
7782
"""
78-
pass
7983

8084
async def update(self):
8185
"""Fetch state of the device from MELCloud.
@@ -217,7 +221,7 @@ def daily_energy_consumed(self) -> Optional[float]:
217221

218222
consumption = 0
219223

220-
for mode in ['Heating', 'Cooling', 'Auto', 'Dry', 'Fan', 'Other']:
224+
for mode in ["Heating", "Cooling", "Auto", "Dry", "Fan", "Other"]:
221225
previous_reports = self._energy_report.get(mode, [0.0])
222226
if previous_reports:
223227
last_report = previous_reports[-1]

src/pymelcloud/erv_device.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Energy-Recovery-Ventilation (DeviceType=3) device definition."""
2+
23
from typing import Any, Dict, List, Optional
34

45
from pymelcloud.device import EFFECTIVE_FLAGS, Device

tests/samples/ata_get.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
"Offline": true,
3232
"Scene": null,
3333
"SceneOwner": null
34-
}
34+
}

tests/samples/ata_listdevice.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,4 @@
177177
"CanSetTemperatureIncrementOverride": true,
178178
"CanDisableLocalController": true
179179
}
180-
}
180+
}

tests/samples/atw_1zone_get.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,4 @@
151151
"Offline": false,
152152
"Units": [
153153
]
154-
}
154+
}

0 commit comments

Comments
 (0)