2017-02-11 19:29:37 +00:00
|
|
|
"""
|
|
|
|
Support for Rflink switches.
|
2017-01-31 16:11:52 +00:00
|
|
|
|
2017-02-11 19:29:37 +00:00
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/switch.rflink/
|
2017-01-31 16:11:52 +00:00
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
2018-10-21 11:05:02 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice
|
|
|
|
from homeassistant.const import CONF_NAME
|
|
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
|
|
|
|
from . import (
|
2017-07-06 13:59:54 +00:00
|
|
|
CONF_ALIASES, CONF_ALIASSES, CONF_DEVICE_DEFAULTS, CONF_DEVICES,
|
|
|
|
CONF_FIRE_EVENT, CONF_GROUP, CONF_GROUP_ALIASES, CONF_GROUP_ALIASSES,
|
|
|
|
CONF_NOGROUP_ALIASES, CONF_NOGROUP_ALIASSES, CONF_SIGNAL_REPETITIONS,
|
2018-10-21 11:05:02 +00:00
|
|
|
DEVICE_DEFAULTS_SCHEMA, SwitchableRflinkDevice, remove_deprecated)
|
2017-01-31 16:11:52 +00:00
|
|
|
|
|
|
|
DEPENDENCIES = ['rflink']
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2018-10-15 13:35:33 +00:00
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
2017-02-01 09:42:50 +00:00
|
|
|
vol.Optional(CONF_DEVICE_DEFAULTS, default=DEVICE_DEFAULTS_SCHEMA({})):
|
2018-10-15 13:35:33 +00:00
|
|
|
DEVICE_DEFAULTS_SCHEMA,
|
|
|
|
vol.Optional(CONF_DEVICES, default={}): {
|
|
|
|
cv.string: vol.Schema({
|
2017-01-31 16:11:52 +00:00
|
|
|
vol.Optional(CONF_NAME): cv.string,
|
2017-07-06 13:59:54 +00:00
|
|
|
vol.Optional(CONF_ALIASES, default=[]):
|
2017-01-31 16:11:52 +00:00
|
|
|
vol.All(cv.ensure_list, [cv.string]),
|
2017-07-06 13:59:54 +00:00
|
|
|
vol.Optional(CONF_GROUP_ALIASES, default=[]):
|
2017-06-02 07:05:34 +00:00
|
|
|
vol.All(cv.ensure_list, [cv.string]),
|
2017-07-06 13:59:54 +00:00
|
|
|
vol.Optional(CONF_NOGROUP_ALIASES, default=[]):
|
2017-06-02 07:05:34 +00:00
|
|
|
vol.All(cv.ensure_list, [cv.string]),
|
2017-09-24 22:47:59 +00:00
|
|
|
vol.Optional(CONF_FIRE_EVENT): cv.boolean,
|
2017-01-31 16:11:52 +00:00
|
|
|
vol.Optional(CONF_SIGNAL_REPETITIONS): vol.Coerce(int),
|
2017-06-02 07:05:34 +00:00
|
|
|
vol.Optional(CONF_GROUP, default=True): cv.boolean,
|
2017-07-06 13:59:54 +00:00
|
|
|
# deprecated config options
|
|
|
|
vol.Optional(CONF_ALIASSES):
|
|
|
|
vol.All(cv.ensure_list, [cv.string]),
|
|
|
|
vol.Optional(CONF_GROUP_ALIASSES):
|
|
|
|
vol.All(cv.ensure_list, [cv.string]),
|
|
|
|
vol.Optional(CONF_NOGROUP_ALIASSES):
|
|
|
|
vol.All(cv.ensure_list, [cv.string]),
|
2018-10-15 13:35:33 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
}, extra=vol.ALLOW_EXTRA)
|
2017-01-31 16:11:52 +00:00
|
|
|
|
|
|
|
|
2018-10-15 13:35:33 +00:00
|
|
|
def devices_from_config(domain_config):
|
2017-02-11 19:29:37 +00:00
|
|
|
"""Parse configuration and add Rflink switch devices."""
|
2017-01-31 16:11:52 +00:00
|
|
|
devices = []
|
|
|
|
for device_id, config in domain_config[CONF_DEVICES].items():
|
|
|
|
device_config = dict(domain_config[CONF_DEVICE_DEFAULTS], **config)
|
2017-07-06 13:59:54 +00:00
|
|
|
remove_deprecated(device_config)
|
2018-10-15 13:35:33 +00:00
|
|
|
device = RflinkSwitch(device_id, **device_config)
|
2017-01-31 16:11:52 +00:00
|
|
|
devices.append(device)
|
|
|
|
|
|
|
|
return devices
|
|
|
|
|
|
|
|
|
2018-10-01 06:55:00 +00:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities,
|
|
|
|
discovery_info=None):
|
2017-02-11 19:29:37 +00:00
|
|
|
"""Set up the Rflink platform."""
|
2018-10-15 13:35:33 +00:00
|
|
|
async_add_entities(devices_from_config(config))
|
2017-01-31 16:11:52 +00:00
|
|
|
|
|
|
|
|
2018-12-11 16:20:30 +00:00
|
|
|
# pylint: disable=too-many-ancestors
|
2017-01-31 16:11:52 +00:00
|
|
|
class RflinkSwitch(SwitchableRflinkDevice, SwitchDevice):
|
|
|
|
"""Representation of a Rflink switch."""
|
|
|
|
|
|
|
|
pass
|