Add switches to control Daikin Airbase zones (#22417)

* initial AirBase zone support

* fix zone name

* version bump pydaikin

* don't use get()
This commit is contained in:
Fredrik Erlandsson 2019-03-27 21:37:21 +01:00 committed by Charles Garwood
parent c3f090af17
commit 71b800457b
3 changed files with 81 additions and 4 deletions

View File

@ -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({

View File

@ -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')

View File

@ -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