Remove global variable from scsgate (#33719)

* Remove global variable from scsgate

* Import CONF_SCS_ID in light.py

* Run isort

* Remove constant ATTR_STATE
This commit is contained in:
springstan 2020-04-05 23:47:11 +02:00 committed by GitHub
parent 40ce8f8c9c
commit 00e67fb2c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 49 deletions

View file

@ -8,15 +8,16 @@ from scsgate.tasks import (
)
import voluptuous as vol
from homeassistant.components import scsgate
from homeassistant.components.cover import PLATFORM_SCHEMA, CoverDevice
from homeassistant.const import CONF_DEVICES, CONF_NAME
import homeassistant.helpers.config_validation as cv
from . import CONF_SCS_ID, DOMAIN, SCSGATE_SCHEMA
_LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{vol.Required(CONF_DEVICES): cv.schema_with_slug_keys(scsgate.SCSGATE_SCHEMA)}
{vol.Required(CONF_DEVICES): cv.schema_with_slug_keys(SCSGATE_SCHEMA)}
)
@ -25,19 +26,22 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
devices = config.get(CONF_DEVICES)
covers = []
logger = logging.getLogger(__name__)
scsgate = hass.data[DOMAIN]
if devices:
for _, entity_info in devices.items():
if entity_info[scsgate.CONF_SCS_ID] in scsgate.SCSGATE.devices:
if entity_info[CONF_SCS_ID] in scsgate.devices:
continue
name = entity_info[CONF_NAME]
scs_id = entity_info[scsgate.CONF_SCS_ID]
scs_id = entity_info[CONF_SCS_ID]
logger.info("Adding %s scsgate.cover", name)
cover = SCSGateCover(name=name, scs_id=scs_id, logger=logger)
scsgate.SCSGATE.add_device(cover)
cover = SCSGateCover(
name=name, scs_id=scs_id, logger=logger, scsgate=scsgate
)
scsgate.add_device(cover)
covers.append(cover)
add_entities(covers)
@ -46,11 +50,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
class SCSGateCover(CoverDevice):
"""Representation of SCSGate cover."""
def __init__(self, scs_id, name, logger):
def __init__(self, scs_id, name, logger, scsgate):
"""Initialize the cover."""
self._scs_id = scs_id
self._name = name
self._logger = logger
self._scsgate = scsgate
@property
def scs_id(self):
@ -74,15 +79,15 @@ class SCSGateCover(CoverDevice):
def open_cover(self, **kwargs):
"""Move the cover."""
scsgate.SCSGATE.append_task(RaiseRollerShutterTask(target=self._scs_id))
self._scsgate.append_task(RaiseRollerShutterTask(target=self._scs_id))
def close_cover(self, **kwargs):
"""Move the cover down."""
scsgate.SCSGATE.append_task(LowerRollerShutterTask(target=self._scs_id))
self._scsgate.append_task(LowerRollerShutterTask(target=self._scs_id))
def stop_cover(self, **kwargs):
"""Stop the cover."""
scsgate.SCSGATE.append_task(HaltRollerShutterTask(target=self._scs_id))
self._scsgate.append_task(HaltRollerShutterTask(target=self._scs_id))
def process_event(self, message):
"""Handle a SCSGate message related with this cover."""