mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Add breeze switch to Renson integration (#101641)
* Add breeze switch * Cleanup code * Replace switch entity with new fan entity * Revert "Replace switch entity with new fan entity" This reverts commit 4fc1ac22e67091a7e980aefd217652f2a88bed17.
This commit is contained in:
parent
d449eadac3
commit
6f74ea9186
@ -1071,6 +1071,7 @@ omit =
|
||||
homeassistant/components/renson/sensor.py
|
||||
homeassistant/components/renson/button.py
|
||||
homeassistant/components/renson/fan.py
|
||||
homeassistant/components/renson/switch.py
|
||||
homeassistant/components/renson/binary_sensor.py
|
||||
homeassistant/components/renson/number.py
|
||||
homeassistant/components/renson/time.py
|
||||
|
@ -19,6 +19,7 @@ PLATFORMS = [
|
||||
Platform.FAN,
|
||||
Platform.NUMBER,
|
||||
Platform.SENSOR,
|
||||
Platform.SWITCH,
|
||||
Platform.TIME,
|
||||
]
|
||||
|
||||
|
@ -5,7 +5,12 @@ import logging
|
||||
import math
|
||||
from typing import Any
|
||||
|
||||
from renson_endura_delta.field_enum import CURRENT_LEVEL_FIELD, DataType
|
||||
from renson_endura_delta.field_enum import (
|
||||
BREEZE_LEVEL_FIELD,
|
||||
BREEZE_TEMPERATURE_FIELD,
|
||||
CURRENT_LEVEL_FIELD,
|
||||
DataType,
|
||||
)
|
||||
from renson_endura_delta.renson import Level, RensonVentilation
|
||||
import voluptuous as vol
|
||||
|
||||
@ -38,6 +43,7 @@ CMD_MAPPING = {
|
||||
SPEED_MAPPING = {
|
||||
Level.OFF.value: 0,
|
||||
Level.HOLIDAY.value: 0,
|
||||
Level.BREEZE.value: 0,
|
||||
Level.LEVEL1.value: 1,
|
||||
Level.LEVEL2.value: 2,
|
||||
Level.LEVEL3.value: 3,
|
||||
@ -129,6 +135,21 @@ class RensonFan(RensonEntity, FanEntity):
|
||||
DataType.LEVEL,
|
||||
)
|
||||
|
||||
if level == Level.BREEZE:
|
||||
level = self.api.parse_value(
|
||||
self.api.get_field_value(
|
||||
self.coordinator.data, BREEZE_LEVEL_FIELD.name
|
||||
),
|
||||
DataType.LEVEL,
|
||||
)
|
||||
else:
|
||||
level = self.api.parse_value(
|
||||
self.api.get_field_value(
|
||||
self.coordinator.data, CURRENT_LEVEL_FIELD.name
|
||||
),
|
||||
DataType.LEVEL,
|
||||
)
|
||||
|
||||
self._attr_percentage = ranged_value_to_percentage(
|
||||
SPEED_RANGE, SPEED_MAPPING[level]
|
||||
)
|
||||
@ -155,13 +176,25 @@ class RensonFan(RensonEntity, FanEntity):
|
||||
"""Set fan speed percentage."""
|
||||
_LOGGER.debug("Changing fan speed percentage to %s", percentage)
|
||||
|
||||
level = self.api.parse_value(
|
||||
self.api.get_field_value(self.coordinator.data, CURRENT_LEVEL_FIELD.name),
|
||||
DataType.LEVEL,
|
||||
)
|
||||
|
||||
if percentage == 0:
|
||||
cmd = Level.HOLIDAY
|
||||
else:
|
||||
speed = math.ceil(percentage_to_ranged_value(SPEED_RANGE, percentage))
|
||||
cmd = CMD_MAPPING[speed]
|
||||
|
||||
await self.hass.async_add_executor_job(self.api.set_manual_level, cmd)
|
||||
if level == Level.BREEZE.value:
|
||||
all_data = self.coordinator.data
|
||||
breeze_temp = self.api.get_field_value(all_data, BREEZE_TEMPERATURE_FIELD)
|
||||
await self.hass.async_add_executor_job(
|
||||
self.api.set_breeze, cmd.name, breeze_temp, True
|
||||
)
|
||||
else:
|
||||
await self.hass.async_add_executor_job(self.api.set_manual_level, cmd)
|
||||
|
||||
await self.coordinator.async_request_refresh()
|
||||
|
||||
|
@ -172,14 +172,12 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
|
||||
raw_format=False,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
RensonSensorEntityDescription(
|
||||
key="BREEZE_LEVEL_FIELD",
|
||||
translation_key="breeze_level",
|
||||
field=BREEZE_LEVEL_FIELD,
|
||||
raw_format=False,
|
||||
entity_registry_enabled_default=False,
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
options=["off", "level1", "level2", "level3", "level4", "breeze"],
|
||||
),
|
||||
|
@ -60,6 +60,11 @@
|
||||
"name": "Preheater"
|
||||
}
|
||||
},
|
||||
"switch": {
|
||||
"breeze": {
|
||||
"name": "Breeze"
|
||||
}
|
||||
},
|
||||
"sensor": {
|
||||
"co2_quality_category": {
|
||||
"name": "CO2 quality category",
|
||||
|
80
homeassistant/components/renson/switch.py
Normal file
80
homeassistant/components/renson/switch.py
Normal file
@ -0,0 +1,80 @@
|
||||
"""Breeze switch of the Renson ventilation unit."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from renson_endura_delta.field_enum import CURRENT_LEVEL_FIELD, DataType
|
||||
from renson_endura_delta.renson import Level, RensonVentilation
|
||||
|
||||
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import RensonCoordinator
|
||||
from .const import DOMAIN
|
||||
from .entity import RensonEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RensonBreezeSwitch(RensonEntity, SwitchEntity):
|
||||
"""Provide the breeze switch."""
|
||||
|
||||
_attr_icon = "mdi:weather-dust"
|
||||
_attr_device_class = SwitchDeviceClass.SWITCH
|
||||
_attr_has_entity_name = True
|
||||
_attr_translation_key = "breeze"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
api: RensonVentilation,
|
||||
coordinator: RensonCoordinator,
|
||||
) -> None:
|
||||
"""Initialize class."""
|
||||
super().__init__("breeze", api, coordinator)
|
||||
|
||||
self._attr_is_on = False
|
||||
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn on the switch."""
|
||||
_LOGGER.debug("Enable Breeze")
|
||||
|
||||
await self.hass.async_add_executor_job(self.api.set_manual_level, Level.BREEZE)
|
||||
await self.coordinator.async_request_refresh()
|
||||
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn off the switch."""
|
||||
_LOGGER.debug("Disable Breeze")
|
||||
|
||||
await self.hass.async_add_executor_job(self.api.set_manual_level, Level.OFF)
|
||||
await self.coordinator.async_request_refresh()
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self) -> None:
|
||||
"""Handle updated data from the coordinator."""
|
||||
|
||||
level = self.api.parse_value(
|
||||
self.api.get_field_value(self.coordinator.data, CURRENT_LEVEL_FIELD.name),
|
||||
DataType.LEVEL,
|
||||
)
|
||||
|
||||
self._attr_is_on = level == Level.BREEZE.value
|
||||
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Call the Renson integration to setup."""
|
||||
|
||||
api: RensonVentilation = hass.data[DOMAIN][config_entry.entry_id].api
|
||||
coordinator: RensonCoordinator = hass.data[DOMAIN][
|
||||
config_entry.entry_id
|
||||
].coordinator
|
||||
|
||||
async_add_entities([RensonBreezeSwitch(api, coordinator)])
|
Loading…
x
Reference in New Issue
Block a user