1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-29 11:45:35 +01:00
Files
2026-04-30 21:14:48 +02:00

82 lines
2.5 KiB
Python

"""Support for the for Danfoss Air HRV sswitches."""
import logging
from typing import Any
from pydanfossair.commands import ReadCommand, UpdateCommand
from homeassistant.components.switch import SwitchEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import DOMAIN
_LOGGER = logging.getLogger(__name__)
def setup_platform(
hass: HomeAssistant,
config: ConfigType,
add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the Danfoss Air HRV switch platform."""
data = hass.data[DOMAIN]
switches = [
[
"Danfoss Air Boost",
ReadCommand.boost,
UpdateCommand.boost_activate,
UpdateCommand.boost_deactivate,
],
[
"Danfoss Air Bypass",
ReadCommand.bypass,
UpdateCommand.bypass_activate,
UpdateCommand.bypass_deactivate,
],
[
"Danfoss Air Automatic Bypass",
ReadCommand.automatic_bypass,
UpdateCommand.bypass_activate,
UpdateCommand.bypass_deactivate,
],
]
add_entities(
DanfossAir(data, switch[0], switch[1], switch[2], switch[3])
for switch in switches
)
class DanfossAir(SwitchEntity):
"""Representation of a Danfoss Air HRV Switch."""
def __init__(self, data, name, state_command, on_command, off_command):
"""Initialize the switch."""
self._data = data
self._attr_name = name
self._state_command = state_command
self._on_command = on_command
self._off_command = off_command
def turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on."""
_LOGGER.debug("Turning on switch with command %s", self._on_command)
self._data.update_state(self._on_command, self._state_command)
def turn_off(self, **kwargs: Any) -> None:
"""Turn the switch off."""
_LOGGER.debug("Turning off switch with command %s", self._off_command)
self._data.update_state(self._off_command, self._state_command)
def update(self) -> None:
"""Update the switch's state."""
self._data.update()
self._attr_is_on = self._data.get_value(self._state_command)
if self._attr_is_on is None:
_LOGGER.debug("Could not get data for %s", self._state_command)