1
mirror of https://github.com/home-assistant/core synced 2024-09-28 03:04:04 +02:00

Add toggle switch to Daikin HVAC units (#95954)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
disforw 2023-11-24 12:53:59 -05:00 committed by GitHub
parent b14a7edb55
commit 95cfe41f87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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"})