-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
/
Copy pathswitch.py
56 lines (42 loc) · 1.85 KB
/
switch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Support for using switch with ecoNet thermostats."""
from __future__ import annotations
import logging
from typing import Any
from pyeconet.equipment import EquipmentType
from pyeconet.equipment.thermostat import Thermostat, ThermostatOperationMode
from homeassistant.components.switch import SwitchEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from . import EconetConfigEntry
from .entity import EcoNetEntity
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(
hass: HomeAssistant,
entry: EconetConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the ecobee thermostat switch entity."""
equipment = entry.runtime_data
async_add_entities(
EcoNetSwitchAuxHeatOnly(thermostat)
for thermostat in equipment[EquipmentType.THERMOSTAT]
)
class EcoNetSwitchAuxHeatOnly(EcoNetEntity[Thermostat], SwitchEntity):
"""Representation of a aux_heat_only EcoNet switch."""
def __init__(self, thermostat: Thermostat) -> None:
"""Initialize EcoNet ventilator platform."""
super().__init__(thermostat)
self._attr_name = f"{thermostat.device_name} emergency heat"
self._attr_unique_id = (
f"{thermostat.device_id}_{thermostat.device_name}_auxheat"
)
def turn_on(self, **kwargs: Any) -> None:
"""Set the hvacMode to auxHeatOnly."""
self._econet.set_mode(ThermostatOperationMode.EMERGENCY_HEAT)
def turn_off(self, **kwargs: Any) -> None:
"""Set the hvacMode back to the prior setting."""
self._econet.set_mode(ThermostatOperationMode.HEATING)
@property
def is_on(self) -> bool:
"""Return true if auxHeatOnly mode is active."""
return self._econet.mode == ThermostatOperationMode.EMERGENCY_HEAT