Fix PEP257 issues

This commit is contained in:
Fabian Affolter 2016-03-07 23:01:34 +01:00
parent 1b8b2acb51
commit 91731c7234
5 changed files with 58 additions and 59 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,38 +34,38 @@ 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)
def move_up(hass, entity_id=None): def move_up(hass, entity_id=None):
""" Move up all or specified rollershutter. """ """Move up 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_MOVE_UP, data) hass.services.call(DOMAIN, SERVICE_MOVE_UP, data)
def move_down(hass, entity_id=None): def move_down(hass, entity_id=None):
""" Move down all or specified rollershutter. """ """Move down 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_MOVE_DOWN, data) hass.services.call(DOMAIN, SERVICE_MOVE_DOWN, data)
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)
def setup(hass, config): def setup(hass, config):
""" Track states and offer events for rollershutters. """ """Track states and offer events for roller shutters."""
component = EntityComponent( component = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL, DISCOVERY_PLATFORMS, _LOGGER, DOMAIN, hass, SCAN_INTERVAL, DISCOVERY_PLATFORMS,
GROUP_NAME_ALL_ROLLERSHUTTERS) GROUP_NAME_ALL_ROLLERSHUTTERS)
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:
@ -121,7 +119,7 @@ class RollershutterDevice(Entity):
@property @property
def state_attributes(self): def state_attributes(self):
""" Return the state attributes. """ """Return the state attributes."""
current = self.current_position current = self.current_position
if current is None: if current is None:
@ -132,13 +130,13 @@ class RollershutterDevice(Entity):
} }
def move_up(self, **kwargs): def move_up(self, **kwargs):
""" Move the rollershutter down. """ """Move the roller shutter down."""
raise NotImplementedError() raise NotImplementedError()
def move_down(self, **kwargs): def move_down(self, **kwargs):
""" Move the rollershutter up. """ """Move the roller shutter up."""
raise NotImplementedError() raise NotImplementedError()
def stop(self, **kwargs): def stop(self, **kwargs):
""" Stop the rollershutter. """ """Stop the roller shutter."""
raise NotImplementedError() raise NotImplementedError()

View file

@ -15,8 +15,7 @@ _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 rollershutter 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
@ -52,7 +51,7 @@ class CommandRollershutter(RollershutterDevice):
@staticmethod @staticmethod
def _move_rollershutter(command): def _move_rollershutter(command):
""" Execute the actual commands. """ """Execute the actual commands."""
_LOGGER.info('Running command: %s', command) _LOGGER.info('Running command: %s', command)
success = (subprocess.call(command, shell=True) == 0) success = (subprocess.call(command, shell=True) == 0)
@ -64,7 +63,7 @@ class CommandRollershutter(RollershutterDevice):
@staticmethod @staticmethod
def _query_state_value(command): def _query_state_value(command):
""" Execute state command for return value. """ """Execute state command for return value."""
_LOGGER.info('Running state command: %s', command) _LOGGER.info('Running state command: %s', command)
try: try:
@ -75,31 +74,31 @@ 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
return self._query_state_value(self._command_state) return self._query_state_value(self._command_state)
def update(self): def update(self):
""" Update device state. """ """Update device state."""
if self._command_state: if self._command_state:
payload = str(self._query_state()) payload = str(self._query_state())
if self._value_template: if self._value_template:
@ -108,13 +107,13 @@ class CommandRollershutter(RollershutterDevice):
self._state = int(payload) self._state = int(payload)
def move_up(self, **kwargs): def move_up(self, **kwargs):
""" Move the rollershutter up. """ """Move the roller shutter up."""
self._move_rollershutter(self._command_up) self._move_rollershutter(self._command_up)
def move_down(self, **kwargs): def move_down(self, **kwargs):
""" Move the rollershutter down. """ """Move the roller shutter down."""
self._move_rollershutter(self._command_down) self._move_rollershutter(self._command_down)
def stop(self, **kwargs): def stop(self, **kwargs):
""" Stop the device. """ """Stop the device."""
self._move_rollershutter(self._command_stop) self._move_rollershutter(self._command_stop)

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,24 +81,24 @@ 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
def move_up(self, **kwargs): def move_up(self, **kwargs):
"""Move the rollershutter up.""" """Move the roller shutter up."""
mqtt.publish(self.hass, self._command_topic, self._payload_up, mqtt.publish(self.hass, self._command_topic, self._payload_up,
self._qos) self._qos)
def move_down(self, **kwargs): def move_down(self, **kwargs):
"""Move the rollershutter down.""" """Move the roller shutter down."""
mqtt.publish(self.hass, self._command_topic, self._payload_down, mqtt.publish(self.hass, self._command_topic, self._payload_down,
self._qos) self._qos)

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,57 +39,59 @@ 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
def move_up(self, **kwargs): def move_up(self, **kwargs):
""" Move the rollershutter up. """ """Move the roller shutter up."""
from scsgate.tasks import RaiseRollerShutterTask from scsgate.tasks import RaiseRollerShutterTask
scsgate.SCSGATE.append_task( scsgate.SCSGATE.append_task(
RaiseRollerShutterTask(target=self._scs_id)) RaiseRollerShutterTask(target=self._scs_id))
def move_down(self, **kwargs): def move_down(self, **kwargs):
""" Move the rollershutter down. """ """Move the rollers hutter down."""
from scsgate.tasks import LowerRollerShutterTask from scsgate.tasks import LowerRollerShutterTask
scsgate.SCSGATE.append_task( scsgate.SCSGATE.append_task(
LowerRollerShutterTask(target=self._scs_id)) LowerRollerShutterTask(target=self._scs_id))
def stop(self, **kwargs): def stop(self, **kwargs):
""" Stop the device. """ """Stop the device."""
from scsgate.tasks import HaltRollerShutterTask from scsgate.tasks import HaltRollerShutterTask
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)