From 5dc48df0938a699001c2ca3d6987290b154aad93 Mon Sep 17 00:00:00 2001 From: Arto Jantunen Date: Sun, 20 Dec 2020 05:53:01 +0200 Subject: [PATCH] Add support for toggling Daikin streamers (#40418) * pydaikin version bump to 2.4.0 Add support for controlling the streamer feature. * Add switch for toggling Daikin streamer on and off * Have DaikinStreamerSwitch inherit from SwitchEntity instead of ToggleEntity --- homeassistant/components/daikin/manifest.json | 2 +- homeassistant/components/daikin/switch.py | 61 ++++++++++++++++++- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/daikin/manifest.json b/homeassistant/components/daikin/manifest.json index a69871a1ef6..ebf31967cc7 100644 --- a/homeassistant/components/daikin/manifest.json +++ b/homeassistant/components/daikin/manifest.json @@ -3,7 +3,7 @@ "name": "Daikin AC", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/daikin", - "requirements": ["pydaikin==2.3.1"], + "requirements": ["pydaikin==2.4.0"], "codeowners": ["@fredrike"], "zeroconf": ["_dkapi._tcp.local."], "quality_scale": "platinum" diff --git a/homeassistant/components/daikin/switch.py b/homeassistant/components/daikin/switch.py index b39d7f27c55..5e0e1b5761a 100644 --- a/homeassistant/components/daikin/switch.py +++ b/homeassistant/components/daikin/switch.py @@ -1,9 +1,13 @@ """Support for Daikin AirBase zones.""" +from homeassistant.components.switch import SwitchEntity from homeassistant.helpers.entity import ToggleEntity from . import DOMAIN as DAIKIN_DOMAIN ZONE_ICON = "mdi:home-circle" +STREAMER_ICON = "mdi:air-filter" +DAIKIN_ATTR_ADVANCED = "adv" +DAIKIN_ATTR_STREAMER = "streamer" async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): @@ -17,15 +21,23 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= async def async_setup_entry(hass, entry, async_add_entities): """Set up Daikin climate based on config_entry.""" daikin_api = hass.data[DAIKIN_DOMAIN][entry.entry_id] + switches = [] zones = daikin_api.device.zones if zones: - async_add_entities( + switches.extend( [ DaikinZoneSwitch(daikin_api, zone_id) for zone_id, zone in enumerate(zones) if zone != ("-", "0") ] ) + if daikin_api.device.support_advanced_modes: + # It isn't possible to find out from the API responses if a specific + # device supports the streamer, so assume so if it does support + # advanced modes. + switches.append(DaikinStreamerSwitch(daikin_api)) + if switches: + async_add_entities(switches) class DaikinZoneSwitch(ToggleEntity): @@ -72,3 +84,50 @@ class DaikinZoneSwitch(ToggleEntity): async def async_turn_off(self, **kwargs): """Turn the zone off.""" await self._api.device.set_zone(self._zone_id, "0") + + +class DaikinStreamerSwitch(SwitchEntity): + """Streamer state.""" + + def __init__(self, daikin_api): + """Initialize streamer switch.""" + self._api = daikin_api + + @property + def unique_id(self): + """Return a unique ID.""" + return f"{self._api.device.mac}-streamer" + + @property + def icon(self): + """Icon to use in the frontend, if any.""" + return STREAMER_ICON + + @property + def name(self): + """Return the name of the sensor.""" + return f"{self._api.name} streamer" + + @property + def is_on(self): + """Return the state of the sensor.""" + return ( + DAIKIN_ATTR_STREAMER in self._api.device.represent(DAIKIN_ATTR_ADVANCED)[1] + ) + + @property + def device_info(self): + """Return a device description for device registry.""" + return self._api.device_info + + async def async_update(self): + """Retrieve latest state.""" + await self._api.async_update() + + async def async_turn_on(self, **kwargs): + """Turn the zone on.""" + await self._api.device.set_streamer("on") + + async def async_turn_off(self, **kwargs): + """Turn the zone off.""" + await self._api.device.set_streamer("off") diff --git a/requirements_all.txt b/requirements_all.txt index 6b4b5d676e1..dac983b1acd 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1331,7 +1331,7 @@ pycsspeechtts==1.0.4 # pycups==1.9.73 # homeassistant.components.daikin -pydaikin==2.3.1 +pydaikin==2.4.0 # homeassistant.components.danfoss_air pydanfossair==0.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 77351567f3f..bf0074d3191 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -670,7 +670,7 @@ pycoolmasternet-async==0.1.2 pycountry==19.8.18 # homeassistant.components.daikin -pydaikin==2.3.1 +pydaikin==2.4.0 # homeassistant.components.deconz pydeconz==76