Home Assistant Unofficial Reference 2024.12.1
switch.py
Go to the documentation of this file.
1 """Support for using switch with ecoNet thermostats."""
2 
3 from __future__ import annotations
4 
5 import logging
6 from typing import Any
7 
8 from pyeconet.equipment import EquipmentType
9 from pyeconet.equipment.thermostat import ThermostatOperationMode
10 
11 from homeassistant.components.switch import SwitchEntity
12 from homeassistant.config_entries import ConfigEntry
13 from homeassistant.core import HomeAssistant
14 from homeassistant.helpers.entity_platform import AddEntitiesCallback
15 
16 from .const import DOMAIN, EQUIPMENT
17 from .entity import EcoNetEntity
18 
19 _LOGGER = logging.getLogger(__name__)
20 
21 
23  hass: HomeAssistant,
24  entry: ConfigEntry,
25  async_add_entities: AddEntitiesCallback,
26 ) -> None:
27  """Set up the ecobee thermostat switch entity."""
28  equipment = hass.data[DOMAIN][EQUIPMENT][entry.entry_id]
30  EcoNetSwitchAuxHeatOnly(thermostat)
31  for thermostat in equipment[EquipmentType.THERMOSTAT]
32  )
33 
34 
36  """Representation of a aux_heat_only EcoNet switch."""
37 
38  def __init__(self, thermostat) -> None:
39  """Initialize EcoNet ventilator platform."""
40  super().__init__(thermostat)
41  self._attr_name_attr_name_attr_name = f"{thermostat.device_name} emergency heat"
42  self._attr_unique_id_attr_unique_id_attr_unique_id = (
43  f"{thermostat.device_id}_{thermostat.device_name}_auxheat"
44  )
45 
46  def turn_on(self, **kwargs: Any) -> None:
47  """Set the hvacMode to auxHeatOnly."""
48  self._econet_econet.set_mode(ThermostatOperationMode.EMERGENCY_HEAT)
49 
50  def turn_off(self, **kwargs: Any) -> None:
51  """Set the hvacMode back to the prior setting."""
52  self._econet_econet.set_mode(ThermostatOperationMode.HEATING)
53 
54  @property
55  def is_on(self) -> bool:
56  """Return true if auxHeatOnly mode is active."""
57  return self._econet_econet.mode == ThermostatOperationMode.EMERGENCY_HEAT
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: switch.py:26