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-09-28 18:14:31 +00:00
|
|
|
from typing import Literal
|
2024-02-22 22:09:38 +00:00
|
|
|
|
2024-04-24 16:38:52 +00:00
|
|
|
from ...feature import Feature
|
2024-02-22 22:09:38 +00:00
|
|
|
from ..smartmodule import SmartModule
|
|
|
|
|
|
|
|
|
|
|
|
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-09-28 18:14:31 +00:00
|
|
|
def _initialize_features(self):
|
|
|
|
"""Initialize features after the initial update."""
|
2024-02-22 22:09:38 +00:00
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
2024-09-28 18:14:31 +00:00
|
|
|
self._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-06-21 12:51:56 +00:00
|
|
|
unit_getter="temperature_unit",
|
2024-06-25 16:30:36 +00:00
|
|
|
type=Feature.Type.Sensor,
|
2024-02-22 22:09:38 +00:00
|
|
|
)
|
|
|
|
)
|
2024-09-28 18:14:31 +00:00
|
|
|
if "current_temp_exception" in self._device.sys_info:
|
2024-04-22 14:24:15 +00:00
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
2024-09-28 18:14:31 +00:00
|
|
|
self._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(
|
2024-09-28 18:14:31 +00:00
|
|
|
self._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-07-30 18:23:07 +00:00
|
|
|
choices_getter=lambda: ["celsius", "fahrenheit"],
|
2024-02-23 23:05:06 +00:00
|
|
|
)
|
|
|
|
)
|
2024-02-22 22:09:38 +00:00
|
|
|
|
2024-07-04 07:02:50 +00:00
|
|
|
def query(self) -> dict:
|
|
|
|
"""Query to execute during the update cycle."""
|
|
|
|
return {}
|
|
|
|
|
2024-02-22 22:09:38 +00:00
|
|
|
@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
|
2024-06-21 12:51:56 +00:00
|
|
|
def temperature_unit(self) -> Literal["celsius", "fahrenheit"]:
|
2024-02-22 22:09:38 +00:00
|
|
|
"""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})
|