Add Renson services

pull/94490/head
jimmyd-be 2023-06-12 17:22:51 +00:00
parent 6568c387ea
commit d862976c81
2 changed files with 296 additions and 2 deletions

View File

@ -6,11 +6,11 @@ from datetime import timedelta
import logging
import async_timeout
from renson_endura_delta.renson import RensonVentilation
from renson_endura_delta.renson import Level, RensonVentilation
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, Platform
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
@ -49,6 +49,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
setup_hass_services(hass, api)
return True
@ -86,3 +87,80 @@ class RensonCoordinator(DataUpdateCoordinator):
"""Fetch data from API endpoint."""
async with async_timeout.timeout(30):
return await self.hass.async_add_executor_job(self.api.get_all_data)
@callback
def setup_hass_services(hass: HomeAssistant, renson_api: RensonVentilation) -> None:
"""Set up the Renson platforms."""
async def set_timer_level(call: ServiceCall) -> None:
"""Set timer level."""
level_string = call.data.get("timer_level", "Level1")
time = call.data.get("time", 0)
level = Level[level_string.upper()]
await hass.async_add_executor_job(renson_api.set_timer_level, level, time)
async def sync_time(call: ServiceCall) -> None:
"""Sync time of device."""
await hass.async_add_executor_job(renson_api.sync_time)
async def set_manual_level(call: ServiceCall) -> None:
"""Set manual level."""
level_string = call.data.get("manual_level", "Off")
level = Level[level_string.upper()]
await hass.async_add_executor_job(renson_api.set_manual_level, level)
async def set_breeze(call: ServiceCall) -> None:
"""Configure breeze feature."""
level = call.data.get("breeze_level", "")
temperature = call.data.get("temperature", 0)
activated = call.data.get("activate", False)
await hass.async_add_executor_job(
renson_api.set_breeze, level, temperature, activated
)
async def set_day_night_time(call: ServiceCall) -> None:
"""Configure day night times."""
day = call.data.get("day", "7:00")
night = call.data.get("night", "22:00")
await hass.async_add_executor_job(renson_api.set_time, day, night)
async def set_pollution_settings(call: ServiceCall) -> None:
"""Configure pollutions settings."""
day = call.data.get("day_pollution_level", "")
night = call.data.get("night_pollution_level", "")
humidity_control = call.data.get("humidity_control", "")
airquality_control = call.data.get("airquality_control", "")
co2_control = call.data.get("co2_control", "")
co2_threshold = call.data.get("co2_threshold", 0)
co2_hysteresis = call.data.get("co2_hysteresis", 0)
await renson_api.set_pollution(
day,
night,
humidity_control,
airquality_control,
co2_control,
co2_threshold,
co2_hysteresis,
)
async def set_filter_days(call: ServiceCall) -> None:
"""Set filter dayes."""
days = call.data.get("days", 90)
await hass.async_add_executor_job(renson_api.set_filter_days, days)
hass.services.async_register(DOMAIN, "set_manual_level", set_manual_level)
hass.services.async_register(DOMAIN, "set_breeze", set_breeze)
hass.services.async_register(DOMAIN, "set_day_night_time", set_day_night_time)
hass.services.async_register(
DOMAIN, "set_pollution_settings", set_pollution_settings
)
hass.services.async_register(DOMAIN, "set_filter_days", set_filter_days)
hass.services.async_register(DOMAIN, "set_timer_level", set_timer_level)
hass.services.async_register(DOMAIN, "sync_time", sync_time)

View File

@ -0,0 +1,216 @@
set_manual_level:
name: Set Manual Level
description: Sets manual level
fields:
manual_level:
name: Manual level
description: Manual level setting
required: true
advanced: false
default: "Off"
selector:
select:
options:
- "Off"
- "Level1"
- "Level2"
- "Level3"
- "Level4"
- "Breeze"
- "Holiday"
sync_time:
name: Synchronize time and date
description: Synchronize time and date with device
set_timer_level:
name: Set timer
description: Set the ventilation timer
fields:
timer_level:
name: Level
description: Level setting
required: true
advanced: false
default: "Level1"
selector:
select:
options:
- "Level1"
- "Level2"
- "Level3"
- "Level4"
- "Holiday"
- "Breeze"
time:
name: Time
description: Time of the timer (0 will disable the timer)
required: true
advanced: false
default: 0
selector:
number:
min: 0
max: 1440
step: 10
unit_of_measurement: "min"
mode: slider
set_breeze:
name: Set breeze
description: Set the breeze function of the ventilation system
fields:
breeze_level:
name: Level
description: Ventilation level when breeze function is activated
required: false
advanced: false
default: "Level3"
selector:
select:
options:
- "Level1"
- "Level2"
- "Level3"
- "Level4"
temperature:
name: Temperature
description: Temperature when the breeze function should be activated
required: false
advanced: false
default: 18
selector:
number:
min: 15
max: 35
step: 1
unit_of_measurement: "°C"
mode: slider
activate:
name: Activate
description: Activate or disable the breeze feature
required: true
advanced: false
default: false
selector:
boolean:
set_day_night_time:
name: Set day and night time
description: Set the day and night time of the system
fields:
day:
name: Start day
description: Start time of the day
required: true
advanced: false
default: false
selector:
time:
night:
name: Start night
description: Start time of the night
required: true
advanced: false
default: false
selector:
time:
set_pollution_settings:
name: Set pollution settings
description: Set all the pollution settings of the ventilation system
fields:
day_pollution_level:
name: Day pollution Level
description: Ventilation level when pollution is detected in the day
required: false
advanced: false
default: "Level3"
selector:
select:
options:
- "Level1"
- "Level2"
- "Level3"
- "Level4"
night_pollution_level:
name: Night pollution Level
description: Ventilation level when pollution is detected in the night
required: false
advanced: false
default: "Level2"
selector:
select:
options:
- "Level1"
- "Level2"
- "Level3"
- "Level4"
humidity_control:
name: Enable humidity control
description: Activate or disable the humidity control
required: false
advanced: false
default: true
selector:
boolean:
airquality_control:
name: Enable air quality control
description: Activate or disable the air quality control
required: false
advanced: false
default: true
selector:
boolean:
co2_control:
name: Enable CO2 control
description: Activate or disable the CO2 control
required: false
advanced: false
default: true
selector:
boolean:
co2_threshold:
name: co2 threshold
description: Sets the CO2 pollution threshold level in ppm
required: false
advanced: false
default: 600
selector:
number:
min: 400
max: 2000
step: 50
unit_of_measurement: "ppm"
mode: slider
co2_hysteresis:
name: co2 hysteresis
description: Sets the CO2 pollution threshold hysteresis level in ppm
required: false
advanced: false
default: 100
selector:
number:
min: 50
max: 400
step: 50
unit_of_measurement: "ppm"
mode: slider
set_filter_days:
name: Set filter days
description: Indicates the recommended filter remaining time in case of filter change, in days
fields:
days:
name: Days
description: Indicates the recommended filter remaining time in case of filter change, in days
required: true
advanced: false
default: 90
selector:
number:
min: 0
max: 360
step: 1
unit_of_measurement: "days"
mode: slider