1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-07 23:06:34 +01:00
Files
core/homeassistant/components/trane/switch.py
T
2026-06-22 20:52:27 +02:00

54 lines
1.7 KiB
Python

"""Switch platform for the Trane Local integration."""
from typing import Any, override
from steamloop import HoldType, ThermostatConnection
from homeassistant.components.switch import SwitchEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .entity import TraneZoneEntity
from .types import TraneConfigEntry
PARALLEL_UPDATES = 0
async def async_setup_entry(
hass: HomeAssistant,
config_entry: TraneConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up Trane Local switch entities."""
conn = config_entry.runtime_data
async_add_entities(
TraneHoldSwitch(conn, config_entry.entry_id, zone_id)
for zone_id in conn.state.zones
)
class TraneHoldSwitch(TraneZoneEntity, SwitchEntity):
"""Switch to control the hold mode of a thermostat zone."""
_attr_translation_key = "hold"
def __init__(self, conn: ThermostatConnection, entry_id: str, zone_id: str) -> None:
"""Initialize the hold switch."""
super().__init__(conn, entry_id, zone_id, "hold")
@property
@override
def is_on(self) -> bool:
"""Return true if the zone is in permanent hold."""
return self._zone.hold_type == HoldType.MANUAL
@override
async def async_turn_on(self, **kwargs: Any) -> None:
"""Enable permanent hold."""
self._conn.set_temperature_setpoint(self._zone_id, hold_type=HoldType.MANUAL)
@override
async def async_turn_off(self, **kwargs: Any) -> None:
"""Return to schedule."""
self._conn.set_temperature_setpoint(self._zone_id, hold_type=HoldType.SCHEDULE)