2024-02-22 22:09:38 +00:00
|
|
|
"""Implementation of temperature module."""
|
2024-04-16 18:21:20 +00:00
|
|
|
|
2024-04-17 13:39:24 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-02-22 22:09:38 +00:00
|
|
|
from typing import TYPE_CHECKING, Literal
|
|
|
|
|
2024-04-24 16:38:52 +00:00
|
|
|
from ...feature import Feature
|
2024-02-22 22:09:38 +00:00
|
|
|
from ..smartmodule import SmartModule
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ..smartdevice import SmartDevice
|
|
|
|
|
|
|
|
|
|
|
|
class TemperatureSensor(SmartModule):
|
|
|
|
"""Implementation of temperature module."""
|
|
|
|
|
2024-03-06 18:04:09 +00:00
|
|
|
REQUIRED_COMPONENT = "temperature"
|
2024-02-22 22:09:38 +00:00
|
|
|
QUERY_GETTER_NAME = "get_comfort_temp_config"
|
|
|
|
|
2024-04-17 13:39:24 +00:00
|
|
|
def __init__(self, device: SmartDevice, module: str):
|
2024-02-22 22:09:38 +00:00
|
|
|
super().__init__(device, module)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
2024-05-07 09:13:35 +00:00
|
|
|
id="temperature",
|
|
|
|
name="Temperature",
|
2024-02-22 22:09:38 +00:00
|
|
|
container=self,
|
|
|
|
attribute_getter="temperature",
|
|
|
|
icon="mdi:thermometer",
|
2024-05-02 13:05:26 +00:00
|
|
|
category=Feature.Category.Primary,
|
2024-02-22 22:09:38 +00:00
|
|
|
)
|
|
|
|
)
|
2024-04-22 14:24:15 +00:00
|
|
|
if "current_temp_exception" in device.sys_info:
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
2024-05-07 09:13:35 +00:00
|
|
|
id="temperature_warning",
|
|
|
|
name="Temperature warning",
|
2024-04-22 14:24:15 +00:00
|
|
|
container=self,
|
|
|
|
attribute_getter="temperature_warning",
|
2024-04-24 16:38:52 +00:00
|
|
|
type=Feature.Type.BinarySensor,
|
2024-04-22 14:24:15 +00:00
|
|
|
icon="mdi:alert",
|
2024-05-07 09:13:35 +00:00
|
|
|
category=Feature.Category.Debug,
|
2024-04-22 14:24:15 +00:00
|
|
|
)
|
2024-02-22 22:09:38 +00:00
|
|
|
)
|
2024-02-23 23:05:06 +00:00
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
2024-05-07 09:13:35 +00:00
|
|
|
id="temperature_unit",
|
|
|
|
name="Temperature unit",
|
2024-02-23 23:05:06 +00:00
|
|
|
container=self,
|
|
|
|
attribute_getter="temperature_unit",
|
|
|
|
attribute_setter="set_temperature_unit",
|
2024-04-24 16:38:52 +00:00
|
|
|
type=Feature.Type.Choice,
|
2024-05-02 13:32:06 +00:00
|
|
|
choices=["celsius", "fahrenheit"],
|
2024-02-23 23:05:06 +00:00
|
|
|
)
|
|
|
|
)
|
2024-02-22 22:09:38 +00:00
|
|
|
# TODO: use temperature_unit for feature creation
|
|
|
|
|
|
|
|
@property
|
|
|
|
def temperature(self):
|
|
|
|
"""Return current humidity in percentage."""
|
|
|
|
return self._device.sys_info["current_temp"]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def temperature_warning(self) -> bool:
|
2024-03-06 18:04:09 +00:00
|
|
|
"""Return True if temperature is outside of the wanted range."""
|
2024-04-22 14:24:15 +00:00
|
|
|
return self._device.sys_info.get("current_temp_exception", 0) != 0
|
2024-02-22 22:09:38 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def temperature_unit(self):
|
|
|
|
"""Return current temperature unit."""
|
|
|
|
return self._device.sys_info["temp_unit"]
|
|
|
|
|
|
|
|
async def set_temperature_unit(self, unit: Literal["celsius", "fahrenheit"]):
|
|
|
|
"""Set the device temperature unit."""
|
|
|
|
return await self.call("set_temperature_unit", {"temp_unit": unit})
|