From 95cfe41f8727bfd262b4d73d681bb316ea8412a1 Mon Sep 17 00:00:00 2001 From: disforw Date: Fri, 24 Nov 2023 12:53:59 -0500 Subject: [PATCH] Add toggle switch to Daikin HVAC units (#95954) Co-authored-by: Franck Nijhof --- homeassistant/components/daikin/switch.py | 35 ++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/daikin/switch.py b/homeassistant/components/daikin/switch.py index 8dd75916685..7acd234e397 100644 --- a/homeassistant/components/daikin/switch.py +++ b/homeassistant/components/daikin/switch.py @@ -13,8 +13,10 @@ from . import DOMAIN as DAIKIN_DOMAIN, DaikinApi ZONE_ICON = "mdi:home-circle" STREAMER_ICON = "mdi:air-filter" +TOGGLE_ICON = "mdi:power" DAIKIN_ATTR_ADVANCED = "adv" DAIKIN_ATTR_STREAMER = "streamer" +DAIKIN_ATTR_MODE = "mode" async def async_setup_platform( @@ -35,7 +37,7 @@ async def async_setup_entry( ) -> None: """Set up Daikin climate based on config_entry.""" daikin_api: DaikinApi = hass.data[DAIKIN_DOMAIN][entry.entry_id] - switches: list[DaikinZoneSwitch | DaikinStreamerSwitch] = [] + switches: list[DaikinZoneSwitch | DaikinStreamerSwitch | DaikinToggleSwitch] = [] if zones := daikin_api.device.zones: switches.extend( [ @@ -49,6 +51,7 @@ async def async_setup_entry( # device supports the streamer, so assume so if it does support # advanced modes. switches.append(DaikinStreamerSwitch(daikin_api)) + switches.append(DaikinToggleSwitch(daikin_api)) async_add_entities(switches) @@ -119,3 +122,33 @@ class DaikinStreamerSwitch(SwitchEntity): async def async_turn_off(self, **kwargs: Any) -> None: """Turn the zone off.""" await self._api.device.set_streamer("off") + + +class DaikinToggleSwitch(SwitchEntity): + """Switch state.""" + + _attr_icon = TOGGLE_ICON + _attr_has_entity_name = True + + def __init__(self, api: DaikinApi) -> None: + """Initialize switch.""" + self._api = api + self._attr_device_info = api.device_info + self._attr_unique_id = f"{self._api.device.mac}-toggle" + + @property + def is_on(self) -> bool: + """Return the state of the sensor.""" + return "off" not in self._api.device.represent(DAIKIN_ATTR_MODE) + + async def async_update(self) -> None: + """Retrieve latest state.""" + await self._api.async_update() + + async def async_turn_on(self, **kwargs: Any) -> None: + """Turn the zone on.""" + await self._api.device.set({}) + + async def async_turn_off(self, **kwargs: Any) -> None: + """Turn the zone off.""" + await self._api.device.set({DAIKIN_ATTR_MODE: "off"})