1 """Support for Vallox ventilation units."""
3 from __future__
import annotations
7 from typing
import NamedTuple
9 from vallox_websocket_api
import Profile, Vallox, ValloxApiException
10 import voluptuous
as vol
18 DEFAULT_FAN_SPEED_AWAY,
19 DEFAULT_FAN_SPEED_BOOST,
20 DEFAULT_FAN_SPEED_HOME,
23 I18N_KEY_TO_VALLOX_PROFILE,
25 from .coordinator
import ValloxDataUpdateCoordinator
27 _LOGGER = logging.getLogger(__name__)
29 CONFIG_SCHEMA = vol.Schema(
31 cv.deprecated(DOMAIN),
35 vol.Required(CONF_HOST): vol.All(ipaddress.ip_address, cv.string),
36 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
41 extra=vol.ALLOW_EXTRA,
44 PLATFORMS: list[str] = [
45 Platform.BINARY_SENSOR,
53 ATTR_PROFILE_FAN_SPEED =
"fan_speed"
55 SERVICE_SCHEMA_SET_PROFILE_FAN_SPEED = vol.Schema(
57 vol.Required(ATTR_PROFILE_FAN_SPEED): vol.All(
58 vol.Coerce(int), vol.Clamp(min=0, max=100)
63 ATTR_PROFILE =
"profile"
64 ATTR_DURATION =
"duration"
66 SERVICE_SCHEMA_SET_PROFILE = vol.Schema(
68 vol.Required(ATTR_PROFILE): vol.In(I18N_KEY_TO_VALLOX_PROFILE),
69 vol.Optional(ATTR_DURATION): vol.All(
70 vol.Coerce(int), vol.Clamp(min=1, max=65535)
77 """Details for SERVICE_TO_METHOD mapping."""
83 SERVICE_SET_PROFILE_FAN_SPEED_HOME =
"set_profile_fan_speed_home"
84 SERVICE_SET_PROFILE_FAN_SPEED_AWAY =
"set_profile_fan_speed_away"
85 SERVICE_SET_PROFILE_FAN_SPEED_BOOST =
"set_profile_fan_speed_boost"
86 SERVICE_SET_PROFILE =
"set_profile"
90 method=
"async_set_profile_fan_speed_home",
91 schema=SERVICE_SCHEMA_SET_PROFILE_FAN_SPEED,
94 method=
"async_set_profile_fan_speed_away",
95 schema=SERVICE_SCHEMA_SET_PROFILE_FAN_SPEED,
98 method=
"async_set_profile_fan_speed_boost",
99 schema=SERVICE_SCHEMA_SET_PROFILE_FAN_SPEED,
102 method=
"async_set_profile", schema=SERVICE_SCHEMA_SET_PROFILE
108 """Set up the client and boot the platforms."""
109 host = entry.data[CONF_HOST]
110 name = entry.data[CONF_NAME]
112 client = Vallox(host)
116 await coordinator.async_config_entry_first_refresh()
119 for vallox_service, service_details
in SERVICE_TO_METHOD.items():
120 hass.services.async_register(
123 service_handler.async_handle,
124 schema=service_details.schema,
127 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
129 "coordinator": coordinator,
133 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
139 """Unload a config entry."""
140 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
141 hass.data[DOMAIN].pop(entry.entry_id)
143 if hass.data[DOMAIN]:
146 for service
in SERVICE_TO_METHOD:
147 hass.services.async_remove(DOMAIN, service)
153 """Services implementation."""
156 self, client: Vallox, coordinator: ValloxDataUpdateCoordinator
158 """Initialize the proxy."""
163 self, fan_speed: int = DEFAULT_FAN_SPEED_HOME
165 """Set the fan speed in percent for the Home profile."""
166 _LOGGER.debug(
"Setting Home fan speed to: %d%%", fan_speed)
169 await self.
_client_client.set_fan_speed(Profile.HOME, fan_speed)
170 except ValloxApiException
as err:
171 _LOGGER.error(
"Error setting fan speed for Home profile: %s", err)
176 self, fan_speed: int = DEFAULT_FAN_SPEED_AWAY
178 """Set the fan speed in percent for the Away profile."""
179 _LOGGER.debug(
"Setting Away fan speed to: %d%%", fan_speed)
182 await self.
_client_client.set_fan_speed(Profile.AWAY, fan_speed)
183 except ValloxApiException
as err:
184 _LOGGER.error(
"Error setting fan speed for Away profile: %s", err)
189 self, fan_speed: int = DEFAULT_FAN_SPEED_BOOST
191 """Set the fan speed in percent for the Boost profile."""
192 _LOGGER.debug(
"Setting Boost fan speed to: %d%%", fan_speed)
195 await self.
_client_client.set_fan_speed(Profile.BOOST, fan_speed)
196 except ValloxApiException
as err:
197 _LOGGER.error(
"Error setting fan speed for Boost profile: %s", err)
202 self, profile: str, duration: int |
None =
None
204 """Activate profile for given duration."""
205 _LOGGER.debug(
"Activating profile %s for %s min", profile, duration)
207 await self.
_client_client.set_profile(
208 I18N_KEY_TO_VALLOX_PROFILE[profile], duration
210 except ValloxApiException
as err:
212 "Error setting profile %d for duration %s: %s", profile, duration, err
218 """Dispatch a service call."""
219 service_details = SERVICE_TO_METHOD.get(call.service)
220 params = call.data.copy()
222 if service_details
is None:
225 if not hasattr(self, service_details.method):
226 _LOGGER.error(
"Service not implemented: %s", service_details.method)
229 result = await getattr(self, service_details.method)(**params)
234 await self.
_coordinator_coordinator.async_request_refresh()
bool async_set_profile_fan_speed_boost(self, int fan_speed=DEFAULT_FAN_SPEED_BOOST)
bool async_set_profile_fan_speed_home(self, int fan_speed=DEFAULT_FAN_SPEED_HOME)
bool async_set_profile(self, str profile, int|None duration=None)
None __init__(self, Vallox client, ValloxDataUpdateCoordinator coordinator)
bool async_set_profile_fan_speed_away(self, int fan_speed=DEFAULT_FAN_SPEED_AWAY)
None async_handle(self, ServiceCall call)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)