Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add switches to control Daikin Airbase zones #22417

Merged
merged 4 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions homeassistant/components/daikin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
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({
Expand Down
77 changes: 77 additions & 0 deletions homeassistant/components/daikin/switch.py
Original file line number Diff line number Diff line change
@@ -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):
fredrike marked this conversation as resolved.
Show resolved Hide resolved
"""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)
fredrike marked this conversation as resolved.
Show resolved Hide resolved

@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
fredrike marked this conversation as resolved.
Show resolved Hide resolved

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')
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ pycsspeechtts==1.0.2
# pycups==1.9.73

# homeassistant.components.daikin
pydaikin==1.2.0
pydaikin==1.3.1

# homeassistant.components.danfoss_air
pydanfossair==0.0.7
Expand Down