diff --git a/homeassistant/components/daikin/__init__.py b/homeassistant/components/daikin/__init__.py index c757185a5cf..a09991e3b72 100644 --- a/homeassistant/components/daikin/__init__.py +++ b/homeassistant/components/daikin/__init__.py @@ -17,16 +17,16 @@ from homeassistant.util import Throttle from . import config_flow # noqa pylint_disable=unused-import from .const import KEY_HOST -REQUIREMENTS = ['pydaikin==1.2.0'] +REQUIREMENTS = ['pydaikin==1.3.1'] _LOGGER = logging.getLogger(__name__) DOMAIN = 'daikin' - +PARALLEL_UPDATES = 0 MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60) -COMPONENT_TYPES = ['climate', 'sensor'] +COMPONENT_TYPES = ['climate', 'sensor', 'switch'] CONFIG_SCHEMA = vol.Schema({ DOMAIN: vol.Schema({ diff --git a/homeassistant/components/daikin/switch.py b/homeassistant/components/daikin/switch.py new file mode 100644 index 00000000000..29159c60fe9 --- /dev/null +++ b/homeassistant/components/daikin/switch.py @@ -0,0 +1,77 @@ +"""Support for Daikin AirBase zones.""" +import logging + +from homeassistant.helpers.entity import ToggleEntity + +from . import DOMAIN as DAIKIN_DOMAIN + +_LOGGER = logging.getLogger(__name__) + +ZONE_ICON = 'mdi:home-circle' + + +def setup_platform(hass, config, add_entities, discovery_info=None): + """Old way of setting up the platform. + + Can only be called when a user accidentally mentions the platform in their + config. But even in that case it would have been ignored. + """ + pass + + +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] + zones = daikin_api.device.zones + if zones: + async_add_entities([ + DaikinZoneSwitch(daikin_api, zone_id) + for zone_id in range(len(zones)) + ]) + + +class DaikinZoneSwitch(ToggleEntity): + """Representation of a zone.""" + + def __init__(self, daikin_api, zone_id): + """Initialize the zone.""" + self._api = daikin_api + self._zone_id = zone_id + + @property + def unique_id(self): + """Return a unique ID.""" + return "{}-zone{}".format(self._api.mac, self._zone_id) + + @property + def icon(self): + """Icon to use in the frontend, if any.""" + return ZONE_ICON + + @property + def name(self): + """Return the name of the sensor.""" + return "{} {}".format(self._api.name, + self._api.device.zones[self._zone_id][0]) + + @property + def is_on(self): + """Return the state of the sensor.""" + return self._api.device.zones[self._zone_id][1] == '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_zone(self._zone_id, '1') + + async def async_turn_off(self, **kwargs): + """Turn the zone off.""" + await self._api.device.set_zone(self._zone_id, '0') diff --git a/requirements_all.txt b/requirements_all.txt index 4b4b2570d50..21d2e0365d7 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -991,7 +991,7 @@ pycoolmasternet==0.0.4 # pycups==1.9.73 # homeassistant.components.daikin -pydaikin==1.2.0 +pydaikin==1.3.1 # homeassistant.components.danfoss_air pydanfossair==0.0.7