Skip to content

Commit 9b14c9e

Browse files
authored
Merge pull request #247 from Moustachauve/lint-fix-2
Fix multiple linting error in climate.py
2 parents 11f1574 + 67b1ee0 commit 9b14c9e

File tree

2 files changed

+66
-15
lines changed

2 files changed

+66
-15
lines changed

pyhilo/device/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def get_device_attributes() -> list[DeviceAttribute]:
3232

3333
class HiloDevice:
3434
def __init__(
35-
self, api: API, **kwargs: Dict[str, Union[str, int, Dict[Any, Any]]]
35+
self, api: API, **kwargs: Dict[str, str | int | Dict[Any, Any]]
3636
) -> None:
3737
self._api = api
3838
self.id = 0
@@ -85,7 +85,8 @@ def update(self, **kwargs: Dict[str, Union[str, int, Dict]]) -> None:
8585
new_val.append(DeviceAttribute("Disconnected", "null"))
8686
elif att == "provider":
8787
att = "manufacturer"
88-
new_val = HILO_PROVIDERS.get(int(val), f"Unknown ({val})") # type: ignore
88+
new_val = HILO_PROVIDERS.get(
89+
int(val), f"Unknown ({val})") # type: ignore
8990
else:
9091
if att == "serial":
9192
att = "identifier"
@@ -230,7 +231,8 @@ def __init__(self, **kwargs: Dict[str, Any]):
230231
# attr='intensity',
231232
# value_type='%')
232233
# }
233-
kwargs["timeStamp"] = from_utc_timestamp(kwargs.pop("timeStampUTC", "")) # type: ignore
234+
kwargs["timeStamp"] = from_utc_timestamp(
235+
kwargs.pop("timeStampUTC", "")) # type: ignore
234236
self.id = 0
235237
self.value: Union[int, bool, str] = 0
236238
self.device_id = 0
@@ -242,7 +244,8 @@ def __init__(self, **kwargs: Dict[str, Any]):
242244
else ""
243245
)
244246
if not self.device_attribute:
245-
LOG.warning(f"Received invalid reading for {self.device_id}: {kwargs}")
247+
LOG.warning(
248+
f"Received invalid reading for {self.device_id}: {kwargs}")
246249

247250
def __repr__(self) -> str:
248251
return f"<Reading {self.device_attribute.attr} {self.value}{self.unit_of_measurement}>"

pyhilo/device/climate.py

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,58 @@
1-
"""Climate object """
2-
3-
from typing import Union, cast
1+
"""Climate object."""
2+
from __future__ import annotations
3+
from typing import Any, cast
44

55
from pyhilo import API
66
from pyhilo.const import LOG
77
from pyhilo.device import HiloDevice
88

99

1010
class Climate(HiloDevice):
11-
def __init__(self, api: API, **kwargs: dict[str, Union[str, int]]):
12-
super().__init__(api, **kwargs) # type: ignore
13-
LOG.debug(f"Setting up Climate device: {self.name}")
11+
"""
12+
Represents a climate device within the Hilo ecosystem.
13+
14+
This class provides methods to interact with and control climate-related
15+
devices such as thermostats.
16+
"""
17+
18+
def __init__(self, api: API, **kwargs: dict[str, str | int | dict[Any, Any]]) -> None:
19+
"""Initialize the Climate object.
20+
21+
Args:
22+
api: The Hilo API instance.
23+
**kwargs: Keyword arguments containing device data.
24+
"""
25+
super().__init__(api, **kwargs)
26+
LOG.debug("Setting up Climate device: %s", self.name)
1427

1528
@property
1629
def current_temperature(self) -> float:
30+
"""
31+
Gets the current temperature reported by the device.
32+
33+
Returns:
34+
float: The current temperature.
35+
"""
1736
return cast(float, self.get_value("current_temperature", 0))
1837

1938
@property
2039
def target_temperature(self) -> float:
40+
"""
41+
Gets the target temperature set for the device.
42+
43+
Returns:
44+
float: The target temperature.
45+
"""
2146
return cast(float, self.get_value("target_temperature", 0))
2247

2348
@property
2449
def max_temp(self) -> float:
50+
"""
51+
Gets the maximum temperature setpoint allowed for the device.
52+
53+
Returns:
54+
float: The maximum temperature. Defaults to 36.0 if not defined.
55+
"""
2556
value = self.get_value("max_temp_setpoint", 0)
2657

2758
if value is None or value == 0:
@@ -30,6 +61,12 @@ def max_temp(self) -> float:
3061

3162
@property
3263
def min_temp(self) -> float:
64+
"""
65+
Gets the minimum temperature setpoint allowed for the device.
66+
67+
Returns:
68+
float: The minimum temperature. Defaults to 5.0 if not defined.
69+
"""
3370
value = self.get_value("min_temp_setpoint", 0)
3471

3572
if value is None or value == 0:
@@ -38,11 +75,22 @@ def min_temp(self) -> float:
3875

3976
@property
4077
def hvac_action(self) -> str:
78+
"""
79+
Gets the current HVAC action of the device.
80+
81+
Returns:
82+
str: 'heating' if heating is active, 'idle' otherwise.
83+
"""
4184
attr = self.get_value("heating", 0)
4285
return "heating" if attr > 0 else "idle"
4386

44-
async def async_set_temperature(self, **kwargs: dict[str, int]) -> None:
45-
temperature = kwargs.get("temperature", 0)
46-
if temperature:
47-
LOG.info(f"{self._tag} Setting temperature to {temperature}")
48-
await self.set_attribute("target_temperature", temperature) # type: ignore
87+
async def async_set_temperature(self, temperature: float) -> None:
88+
"""
89+
Sets the target temperature of the device.
90+
91+
Args:
92+
temperature: The desired target temperature.
93+
"""
94+
if temperature != self.target_temperature:
95+
LOG.info("%s Setting temperature to %s", self._tag, temperature)
96+
await self.set_attribute("target_temperature", str(temperature))

0 commit comments

Comments
 (0)