Merge branch 'pep257-scene-mqtt' into dev

This commit is contained in:
Fabian Affolter 2016-03-08 08:11:30 +01:00
commit 5423252a52
7 changed files with 73 additions and 75 deletions

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.rollershutter Support for Roller shutters.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rollershutter component.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/rollershutter/ https://home-assistant.io/components/rollershutter/
@ -36,7 +34,7 @@ ATTR_CURRENT_POSITION = 'current_position'
def is_open(hass, entity_id=None): def is_open(hass, entity_id=None):
""" Returns if the rollershutter is open based on the statemachine. """ """Return if the roller shutter is open based on the statemachine."""
entity_id = entity_id or ENTITY_ID_ALL_ROLLERSHUTTERS entity_id = entity_id or ENTITY_ID_ALL_ROLLERSHUTTERS
return hass.states.is_state(entity_id, STATE_OPEN) return hass.states.is_state(entity_id, STATE_OPEN)
@ -54,7 +52,7 @@ def move_down(hass, entity_id=None):
def stop(hass, entity_id=None): def stop(hass, entity_id=None):
""" Stops all or specified rollershutter. """ """Stop all or specified roller shutter."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.services.call(DOMAIN, SERVICE_STOP, data) hass.services.call(DOMAIN, SERVICE_STOP, data)
@ -67,7 +65,7 @@ def setup(hass, config):
component.setup(config) component.setup(config)
def handle_rollershutter_service(service): def handle_rollershutter_service(service):
""" Handles calls to the rollershutter services. """ """Handle calls to the roller shutter services."""
target_rollershutters = component.extract_from_service(service) target_rollershutters = component.extract_from_service(service)
for rollershutter in target_rollershutters: for rollershutter in target_rollershutters:
@ -98,20 +96,20 @@ def setup(hass, config):
class RollershutterDevice(Entity): class RollershutterDevice(Entity):
""" Represents a rollershutter within Home Assistant. """ """Representation a rollers hutter."""
# pylint: disable=no-self-use
# pylint: disable=no-self-use
@property @property
def current_position(self): def current_position(self):
""" """Return current position of roller shutter.
Return current position of rollershutter.
None is unknown, 0 is closed, 100 is fully open. None is unknown, 0 is closed, 100 is fully open.
""" """
raise NotImplementedError() raise NotImplementedError()
@property @property
def state(self): def state(self):
""" Returns the state of the rollershutter. """ """Return the state of the roller shutter."""
current = self.current_position current = self.current_position
if current is None: if current is None:

View File

@ -16,7 +16,6 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Setup roller shutter controlled by shell commands.""" """Setup roller shutter controlled by shell commands."""
rollershutters = config.get('rollershutters', {}) rollershutters = config.get('rollershutters', {})
devices = [] devices = []
@ -35,15 +34,15 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
# pylint: disable=too-many-arguments, too-many-instance-attributes # pylint: disable=too-many-arguments, too-many-instance-attributes
class CommandRollershutter(RollershutterDevice): class CommandRollershutter(RollershutterDevice):
""" Represents a rollershutter - can be controlled using shell cmd. """ """Representation a command line roller shutter."""
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def __init__(self, hass, name, command_up, command_down, command_stop, def __init__(self, hass, name, command_up, command_down, command_stop,
command_state, value_template): command_state, value_template):
"""Initialize the roller shutter."""
self._hass = hass self._hass = hass
self._name = name self._name = name
self._state = None # Unknown self._state = None
self._command_up = command_up self._command_up = command_up
self._command_down = command_down self._command_down = command_down
self._command_stop = command_stop self._command_stop = command_stop
@ -75,24 +74,24 @@ class CommandRollershutter(RollershutterDevice):
@property @property
def should_poll(self): def should_poll(self):
""" Only poll if we have statecmd. """ """Only poll if we have state command."""
return self._command_state is not None return self._command_state is not None
@property @property
def name(self): def name(self):
""" The name of the rollershutter. """ """Return the name of the roller shutter."""
return self._name return self._name
@property @property
def current_position(self): def current_position(self):
""" """Return current position of roller shutter.
Return current position of rollershutter.
None is unknown, 0 is closed, 100 is fully open. None is unknown, 0 is closed, 100 is fully open.
""" """
return self._state return self._state
def _query_state(self): def _query_state(self):
""" Query for state. """ """Query for the state."""
if not self._command_state: if not self._command_state:
_LOGGER.error('No state command specified') _LOGGER.error('No state command specified')
return return

View File

@ -18,9 +18,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class DemoRollershutter(RollershutterDevice): class DemoRollershutter(RollershutterDevice):
"""Represents a roller shutter.""" """Representation of a demo roller shutter."""
# pylint: disable=no-self-use # pylint: disable=no-self-use
def __init__(self, hass, name, position): def __init__(self, hass, name, position):
"""Initialize the roller shutter."""
self.hass = hass self.hass = hass
self._name = name self._name = name
self._position = position self._position = position
@ -29,7 +31,7 @@ class DemoRollershutter(RollershutterDevice):
@property @property
def name(self): def name(self):
"""Returns the name of the roller shutter.""" """Return the name of the roller shutter."""
return self._name return self._name
@property @property
@ -59,7 +61,7 @@ class DemoRollershutter(RollershutterDevice):
self._moving_up = False self._moving_up = False
def stop(self, **kwargs): def stop(self, **kwargs):
"""Stops the roller shutter.""" """Stop the roller shutter."""
if self._listener is not None: if self._listener is not None:
self.hass.bus.remove_listener(EVENT_TIME_CHANGED, self._listener) self.hass.bus.remove_listener(EVENT_TIME_CHANGED, self._listener)
self._listener = None self._listener = None

View File

@ -24,7 +24,6 @@ DEFAULT_PAYLOAD_STOP = "STOP"
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Add MQTT Rollershutter.""" """Add MQTT Rollershutter."""
if config.get('command_topic') is None: if config.get('command_topic') is None:
_LOGGER.error("Missing required variable: command_topic") _LOGGER.error("Missing required variable: command_topic")
return False return False
@ -43,9 +42,11 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
# pylint: disable=too-many-arguments, too-many-instance-attributes # pylint: disable=too-many-arguments, too-many-instance-attributes
class MqttRollershutter(RollershutterDevice): class MqttRollershutter(RollershutterDevice):
"""Represents a rollershutter that can be controlled using MQTT.""" """Representation of a roller shutter that can be controlled using MQTT."""
def __init__(self, hass, name, state_topic, command_topic, qos, def __init__(self, hass, name, state_topic, command_topic, qos,
payload_up, payload_down, payload_stop, value_template): payload_up, payload_down, payload_stop, value_template):
"""Initialize the roller shutter."""
self._state = None self._state = None
self._hass = hass self._hass = hass
self._name = name self._name = name
@ -80,13 +81,13 @@ class MqttRollershutter(RollershutterDevice):
@property @property
def name(self): def name(self):
"""The name of the rollershutter.""" """Return the name of the roller shutter."""
return self._name return self._name
@property @property
def current_position(self): def current_position(self):
""" """Return current position of roller shutter.
Return current position of rollershutter.
None is unknown, 0 is closed, 100 is fully open. None is unknown, 0 is closed, 100 is fully open.
""" """
return self._state return self._state

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.rollershutter.scsgate Allow to configure a SCSGate roller shutter.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to configure a SCSGate rollershutter.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/rollershutter.scsgate/ https://home-assistant.io/components/rollershutter.scsgate/
@ -15,8 +13,7 @@ DEPENDENCIES = ['scsgate']
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Add the SCSGate swiches defined inside of the configuration file. """ """Setup the SCSGate roller shutter."""
devices = config.get('devices') devices = config.get('devices')
rollershutters = [] rollershutters = []
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -42,31 +39,33 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
# pylint: disable=too-many-arguments, too-many-instance-attributes # pylint: disable=too-many-arguments, too-many-instance-attributes
class SCSGateRollerShutter(RollershutterDevice): class SCSGateRollerShutter(RollershutterDevice):
""" Represents a rollershutter that can be controlled using SCSGate. """ """Representation of SCSGate rollershutter."""
def __init__(self, scs_id, name, logger): def __init__(self, scs_id, name, logger):
"""Initialize the roller shutter."""
self._scs_id = scs_id self._scs_id = scs_id
self._name = name self._name = name
self._logger = logger self._logger = logger
@property @property
def scs_id(self): def scs_id(self):
""" SCSGate ID """ """Return the SCSGate ID."""
return self._scs_id return self._scs_id
@property @property
def should_poll(self): def should_poll(self):
""" No polling needed """ """No polling needed."""
return False return False
@property @property
def name(self): def name(self):
""" The name of the rollershutter. """ """Return the name of the roller shutter."""
return self._name return self._name
@property @property
def current_position(self): def current_position(self):
""" """Return current position of roller shutter.
Return current position of rollershutter.
None is unknown, 0 is closed, 100 is fully open. None is unknown, 0 is closed, 100 is fully open.
""" """
return None return None
@ -92,7 +91,7 @@ class SCSGateRollerShutter(RollershutterDevice):
scsgate.SCSGATE.append_task(HaltRollerShutterTask(target=self._scs_id)) scsgate.SCSGATE.append_task(HaltRollerShutterTask(target=self._scs_id))
def process_event(self, message): def process_event(self, message):
""" Handle a SCSGate message related with this rollershutter """ """Handle a SCSGate message related with this roller shutter."""
self._logger.debug( self._logger.debug(
"Rollershutter %s, got message %s", "Rollershutter %s, got message %s",
self._scs_id, message.toggled) self._scs_id, message.toggled)

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.scene Allow users to set and activate scenes.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows users to set and activate scenes.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/scene/ https://home-assistant.io/components/scene/
@ -35,8 +33,7 @@ def activate(hass, entity_id=None):
def setup(hass, config): def setup(hass, config):
""" Sets up scenes. """ """Setup the scenes."""
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# You are not allowed to mutate the original config so make a copy # You are not allowed to mutate the original config so make a copy
@ -58,7 +55,7 @@ def setup(hass, config):
component.setup(config) component.setup(config)
def handle_scene_service(service): def handle_scene_service(service):
""" Handles calls to the switch services. """ """Handle calls to the switch services."""
target_scenes = component.extract_from_service(service) target_scenes = component.extract_from_service(service)
for scene in target_scenes: for scene in target_scenes:
@ -74,12 +71,14 @@ class Scene(Entity):
@property @property
def should_poll(self): def should_poll(self):
"""No polling needed."""
return False return False
@property @property
def state(self): def state(self):
"""Return the state."""
return STATE return STATE
def activate(self): def activate(self):
""" Activates scene. Tries to get entities into requested state. """ """Activate scene. Tries to get entities into requested state."""
raise NotImplementedError raise NotImplementedError

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.scene
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows users to set and activate scenes. Allows users to set and activate scenes.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
@ -24,7 +22,7 @@ SceneConfig = namedtuple('SceneConfig', ['name', 'states'])
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up home assistant scene entries. """ """Setup home assistant scene entries."""
scene_config = config.get("states") scene_config = config.get("states")
if not isinstance(scene_config, list): if not isinstance(scene_config, list):
@ -68,20 +66,22 @@ class HomeAssistantScene(Scene):
"""A scene is a group of entities and the states we want them to be.""" """A scene is a group of entities and the states we want them to be."""
def __init__(self, hass, scene_config): def __init__(self, hass, scene_config):
"""Initialize the scene."""
self.hass = hass self.hass = hass
self.scene_config = scene_config self.scene_config = scene_config
@property @property
def name(self): def name(self):
"""Return the name of the scene."""
return self.scene_config.name return self.scene_config.name
@property @property
def device_state_attributes(self): def device_state_attributes(self):
""" Scene state attributes. """ """Return the scene state attributes."""
return { return {
ATTR_ENTITY_ID: list(self.scene_config.states.keys()), ATTR_ENTITY_ID: list(self.scene_config.states.keys()),
} }
def activate(self): def activate(self):
""" Activates scene. Tries to get entities into requested state. """ """Activate scene. Tries to get entities into requested state."""
reproduce_state(self.hass, self.scene_config.states.values(), True) reproduce_state(self.hass, self.scene_config.states.values(), True)