Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pyhilo/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_device_attributes() -> list[DeviceAttribute]:

class HiloDevice:
def __init__(
self, api: API, **kwargs: Dict[str, Union[str, int, Dict[Any, Any]]]
self, api: API, **kwargs: Dict[str, str | int | Dict[Any, Any]]
) -> None:
self._api = api
self.id = 0
Expand Down Expand Up @@ -85,7 +85,8 @@ def update(self, **kwargs: Dict[str, Union[str, int, Dict]]) -> None:
new_val.append(DeviceAttribute("Disconnected", "null"))
elif att == "provider":
att = "manufacturer"
new_val = HILO_PROVIDERS.get(int(val), f"Unknown ({val})") # type: ignore
new_val = HILO_PROVIDERS.get(
int(val), f"Unknown ({val})") # type: ignore
else:
if att == "serial":
att = "identifier"
Expand Down Expand Up @@ -230,7 +231,8 @@ def __init__(self, **kwargs: Dict[str, Any]):
# attr='intensity',
# value_type='%')
# }
kwargs["timeStamp"] = from_utc_timestamp(kwargs.pop("timeStampUTC", "")) # type: ignore
kwargs["timeStamp"] = from_utc_timestamp(
kwargs.pop("timeStampUTC", "")) # type: ignore
self.id = 0
self.value: Union[int, bool, str] = 0
self.device_id = 0
Expand All @@ -242,7 +244,8 @@ def __init__(self, **kwargs: Dict[str, Any]):
else ""
)
if not self.device_attribute:
LOG.warning(f"Received invalid reading for {self.device_id}: {kwargs}")
LOG.warning(
f"Received invalid reading for {self.device_id}: {kwargs}")

def __repr__(self) -> str:
return f"<Reading {self.device_attribute.attr} {self.value}{self.unit_of_measurement}>"
Expand Down
70 changes: 59 additions & 11 deletions pyhilo/device/climate.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,58 @@
"""Climate object """

from typing import Union, cast
"""Climate object."""
from __future__ import annotations
from typing import Any, cast

from pyhilo import API
from pyhilo.const import LOG
from pyhilo.device import HiloDevice


class Climate(HiloDevice):
def __init__(self, api: API, **kwargs: dict[str, Union[str, int]]):
super().__init__(api, **kwargs) # type: ignore
LOG.debug(f"Setting up Climate device: {self.name}")
"""
Represents a climate device within the Hilo ecosystem.

This class provides methods to interact with and control climate-related
devices such as thermostats.
"""

def __init__(self, api: API, **kwargs: dict[str, str | int | dict[Any, Any]]) -> None:
"""Initialize the Climate object.

Args:
api: The Hilo API instance.
**kwargs: Keyword arguments containing device data.
"""
super().__init__(api, **kwargs)
LOG.debug("Setting up Climate device: %s", self.name)

@property
def current_temperature(self) -> float:
"""
Gets the current temperature reported by the device.

Returns:
float: The current temperature.
"""
return cast(float, self.get_value("current_temperature", 0))

@property
def target_temperature(self) -> float:
"""
Gets the target temperature set for the device.

Returns:
float: The target temperature.
"""
return cast(float, self.get_value("target_temperature", 0))

@property
def max_temp(self) -> float:
"""
Gets the maximum temperature setpoint allowed for the device.

Returns:
float: The maximum temperature. Defaults to 36.0 if not defined.
"""
value = self.get_value("max_temp_setpoint", 0)

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

@property
def min_temp(self) -> float:
"""
Gets the minimum temperature setpoint allowed for the device.

Returns:
float: The minimum temperature. Defaults to 5.0 if not defined.
"""
value = self.get_value("min_temp_setpoint", 0)

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

@property
def hvac_action(self) -> str:
"""
Gets the current HVAC action of the device.

Returns:
str: 'heating' if heating is active, 'idle' otherwise.
"""
attr = self.get_value("heating", 0)
return "heating" if attr > 0 else "idle"

async def async_set_temperature(self, **kwargs: dict[str, int]) -> None:
temperature = kwargs.get("temperature", 0)
if temperature:
LOG.info(f"{self._tag} Setting temperature to {temperature}")
await self.set_attribute("target_temperature", temperature) # type: ignore
async def async_set_temperature(self, temperature: float) -> None:
"""
Sets the target temperature of the device.

Args:
temperature: The desired target temperature.
"""
if temperature != self.target_temperature:
LOG.info("%s Setting temperature to %s", self._tag, temperature)
await self.set_attribute("target_temperature", str(temperature))
Loading