2019-02-13 20:21:14 +00:00
|
|
|
"""Support for SCSGate covers."""
|
2016-08-24 01:23:18 +00:00
|
|
|
import logging
|
|
|
|
|
2016-09-13 05:23:53 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2018-07-18 09:54:27 +00:00
|
|
|
from homeassistant.components import scsgate
|
2016-09-13 05:23:53 +00:00
|
|
|
from homeassistant.components.cover import (CoverDevice, PLATFORM_SCHEMA)
|
|
|
|
from homeassistant.const import (CONF_DEVICES, CONF_NAME)
|
|
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2016-08-24 01:23:18 +00:00
|
|
|
|
2016-09-13 05:23:53 +00:00
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
2019-01-22 00:36:04 +00:00
|
|
|
vol.Required(CONF_DEVICES):
|
|
|
|
cv.schema_with_slug_keys(scsgate.SCSGATE_SCHEMA),
|
2016-09-13 05:23:53 +00:00
|
|
|
})
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up the SCSGate cover."""
|
2016-09-13 05:23:53 +00:00
|
|
|
devices = config.get(CONF_DEVICES)
|
2016-08-24 01:23:18 +00:00
|
|
|
covers = []
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
if devices:
|
|
|
|
for _, entity_info in devices.items():
|
2016-09-13 05:23:53 +00:00
|
|
|
if entity_info[scsgate.CONF_SCS_ID] in scsgate.SCSGATE.devices:
|
2016-08-24 01:23:18 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
name = entity_info[CONF_NAME]
|
2016-09-13 05:23:53 +00:00
|
|
|
scs_id = entity_info[scsgate.CONF_SCS_ID]
|
|
|
|
|
|
|
|
logger.info("Adding %s scsgate.cover", name)
|
|
|
|
|
|
|
|
cover = SCSGateCover(name=name, scs_id=scs_id, logger=logger)
|
2016-08-24 01:23:18 +00:00
|
|
|
scsgate.SCSGATE.add_device(cover)
|
|
|
|
covers.append(cover)
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(covers)
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SCSGateCover(CoverDevice):
|
|
|
|
"""Representation of SCSGate cover."""
|
|
|
|
|
|
|
|
def __init__(self, scs_id, name, logger):
|
|
|
|
"""Initialize the cover."""
|
|
|
|
self._scs_id = scs_id
|
|
|
|
self._name = name
|
|
|
|
self._logger = logger
|
|
|
|
|
|
|
|
@property
|
|
|
|
def scs_id(self):
|
|
|
|
"""Return the SCSGate ID."""
|
|
|
|
return self._scs_id
|
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self):
|
|
|
|
"""No polling needed."""
|
|
|
|
return False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the cover."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_closed(self):
|
|
|
|
"""Return if the cover is closed."""
|
|
|
|
return None
|
|
|
|
|
|
|
|
def open_cover(self, **kwargs):
|
|
|
|
"""Move the cover."""
|
|
|
|
from scsgate.tasks import RaiseRollerShutterTask
|
|
|
|
|
|
|
|
scsgate.SCSGATE.append_task(
|
|
|
|
RaiseRollerShutterTask(target=self._scs_id))
|
|
|
|
|
|
|
|
def close_cover(self, **kwargs):
|
|
|
|
"""Move the cover down."""
|
|
|
|
from scsgate.tasks import LowerRollerShutterTask
|
|
|
|
|
|
|
|
scsgate.SCSGATE.append_task(
|
|
|
|
LowerRollerShutterTask(target=self._scs_id))
|
|
|
|
|
|
|
|
def stop_cover(self, **kwargs):
|
|
|
|
"""Stop the cover."""
|
|
|
|
from scsgate.tasks import HaltRollerShutterTask
|
|
|
|
|
|
|
|
scsgate.SCSGATE.append_task(HaltRollerShutterTask(target=self._scs_id))
|
|
|
|
|
|
|
|
def process_event(self, message):
|
|
|
|
"""Handle a SCSGate message related with this cover."""
|
2016-09-13 05:23:53 +00:00
|
|
|
self._logger.debug("Cover %s, got message %s",
|
|
|
|
self._scs_id, message.toggled)
|