1 """Platform to control a Renson ventilation unit."""
3 from __future__
import annotations
9 from renson_endura_delta.field_enum
import (
11 BREEZE_TEMPERATURE_FIELD,
15 from renson_endura_delta.renson
import Level, RensonVentilation
16 import voluptuous
as vol
26 percentage_to_ranged_value,
27 ranged_value_to_percentage,
31 from .const
import DOMAIN
32 from .coordinator
import RensonCoordinator
33 from .entity
import RensonEntity
35 _LOGGER = logging.getLogger(__name__)
47 Level.HOLIDAY.value: 0,
48 Level.BREEZE.value: 0,
49 Level.LEVEL1.value: 1,
50 Level.LEVEL2.value: 2,
51 Level.LEVEL3.value: 3,
52 Level.LEVEL4.value: 4,
55 SET_TIMER_LEVEL_SCHEMA: VolDictType = {
56 vol.Required(
"timer_level"): vol.In(
57 [
"level1",
"level2",
"level3",
"level4",
"holiday",
"breeze"]
59 vol.Required(
"minutes"): cv.positive_int,
62 SET_BREEZE_SCHEMA: VolDictType = {
63 vol.Required(
"breeze_level"): vol.In([
"level1",
"level2",
"level3",
"level4"]),
64 vol.Required(
"temperature"): cv.positive_int,
65 vol.Required(
"activate"): bool,
68 SET_POLLUTION_SETTINGS_SCHEMA: VolDictType = {
69 vol.Required(
"day_pollution_level"): vol.In(
70 [
"level1",
"level2",
"level3",
"level4"]
72 vol.Required(
"night_pollution_level"): vol.In(
73 [
"level1",
"level2",
"level3",
"level4"]
75 vol.Optional(
"humidity_control", default=
True): bool,
76 vol.Optional(
"airquality_control", default=
True): bool,
77 vol.Optional(
"co2_control", default=
True): bool,
78 vol.Optional(
"co2_threshold", default=600): cv.positive_int,
79 vol.Optional(
"co2_hysteresis", default=100): cv.positive_int,
83 SPEED_RANGE: tuple[float, float] = (1, 4)
88 config_entry: ConfigEntry,
89 async_add_entities: AddEntitiesCallback,
91 """Set up the Renson fan platform."""
93 api: RensonVentilation = hass.data[DOMAIN][config_entry.entry_id].api
94 coordinator: RensonCoordinator = hass.data[DOMAIN][
100 platform = entity_platform.async_get_current_platform()
102 platform.async_register_entity_service(
104 SET_TIMER_LEVEL_SCHEMA,
108 platform.async_register_entity_service(
109 "set_breeze", SET_BREEZE_SCHEMA,
"set_breeze"
112 platform.async_register_entity_service(
113 "set_pollution_settings",
114 SET_POLLUTION_SETTINGS_SCHEMA,
115 "set_pollution_settings",
120 """Representation of the Renson fan platform."""
122 _attr_has_entity_name =
True
124 _attr_translation_key =
"fan"
125 _attr_supported_features = (
126 FanEntityFeature.SET_SPEED
127 | FanEntityFeature.TURN_OFF
128 | FanEntityFeature.TURN_ON
130 _enable_turn_on_off_backwards_compatibility =
False
132 def __init__(self, api: RensonVentilation, coordinator: RensonCoordinator) ->
None:
133 """Initialize the Renson fan."""
134 super().
__init__(
"fan", api, coordinator)
139 """Handle updated data from the coordinator."""
140 level = self.
apiapiapi.parse_value(
141 self.
apiapiapi.get_field_value(self.coordinator.data, CURRENT_LEVEL_FIELD.name),
145 if level == Level.BREEZE.value:
146 level = self.
apiapiapi.parse_value(
147 self.
apiapiapi.get_field_value(
148 self.coordinator.data, BREEZE_LEVEL_FIELD.name
153 level = self.
apiapiapi.parse_value(
154 self.
apiapiapi.get_field_value(
155 self.coordinator.data, CURRENT_LEVEL_FIELD.name
161 SPEED_RANGE, SPEED_MAPPING[level]
168 percentage: int |
None =
None,
169 preset_mode: str |
None =
None,
172 """Turn on the fan."""
173 if percentage
is None:
179 """Turn off the fan (to away)."""
183 """Set fan speed percentage."""
184 _LOGGER.debug(
"Changing fan speed percentage to %s", percentage)
186 level = self.
apiapiapi.parse_value(
187 self.
apiapiapi.get_field_value(self.coordinator.data, CURRENT_LEVEL_FIELD.name),
195 cmd = CMD_MAPPING[speed]
197 if level == Level.BREEZE.value:
198 all_data = self.coordinator.data
199 breeze_temp = self.
apiapiapi.get_field_value(all_data, BREEZE_TEMPERATURE_FIELD)
200 await self.
hasshasshass.async_add_executor_job(
201 self.
apiapiapi.set_breeze, cmd.name, breeze_temp,
True
204 await self.
hasshasshass.async_add_executor_job(self.
apiapiapi.set_manual_level, cmd)
209 """Set timer level."""
210 level = Level[
str(timer_level).upper()]
212 await self.
hasshasshass.async_add_executor_job(self.
apiapiapi.set_timer_level, level, minutes)
215 self, breeze_level: str, temperature: int, activate: bool
217 """Configure breeze feature."""
218 level = Level[
str(breeze_level).upper()]
220 await self.
hasshasshass.async_add_executor_job(
221 self.
apiapiapi.set_breeze, level, temperature, activate
226 day_pollution_level: str,
227 night_pollution_level: str,
228 humidity_control: bool,
229 airquality_control: bool,
234 """Configure pollutions settings."""
235 day = Level[
str(day_pollution_level).upper()]
236 night = Level[
str(night_pollution_level).upper()]
238 await self.
apiapiapi.set_pollution(
None async_set_percentage(self, int percentage)
None set_breeze(self, str breeze_level, int temperature, bool activate)
None async_turn_off(self, **Any kwargs)
None set_pollution_settings(self, str day_pollution_level, str night_pollution_level, bool humidity_control, bool airquality_control, str co2_control, int co2_threshold, int co2_hysteresis)
None __init__(self, RensonVentilation api, RensonCoordinator coordinator)
None _handle_coordinator_update(self)
None async_set_percentage(self, int percentage)
None async_turn_on(self, int|None percentage=None, str|None preset_mode=None, **Any kwargs)
None set_timer_level(self, str timer_level, int minutes)
None async_request_refresh(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
float percentage_to_ranged_value(tuple[float, float] low_high_range, float percentage)
int ranged_value_to_percentage(tuple[float, float] low_high_range, float value)
int int_states_in_range(tuple[float, float] low_high_range)