From 1b8b2acb51c8f6d5e64d42244ba578ada2cbe61b Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Mon, 7 Mar 2016 22:50:56 +0100 Subject: [PATCH 1/2] Fix PEP257 issues --- homeassistant/components/scene/__init__.py | 17 ++++++++--------- homeassistant/components/scene/homeassistant.py | 14 +++++++------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/scene/__init__.py b/homeassistant/components/scene/__init__.py index ee6f9b1bd5d..c67a522d9d2 100644 --- a/homeassistant/components/scene/__init__.py +++ b/homeassistant/components/scene/__init__.py @@ -1,7 +1,5 @@ """ -homeassistant.components.scene -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Allows users to set and activate scenes. +Allow users to set and activate scenes. For more details about this component, please refer to the documentation at https://home-assistant.io/components/scene/ @@ -25,7 +23,7 @@ SceneConfig = namedtuple('SceneConfig', ['name', 'states']) def activate(hass, entity_id=None): - """ Activate a scene. """ + """Activate a scene.""" data = {} if entity_id: @@ -35,8 +33,7 @@ def activate(hass, entity_id=None): def setup(hass, config): - """ Sets up scenes. """ - + """Setup the scenes.""" logger = logging.getLogger(__name__) # You are not allowed to mutate the original config so make a copy @@ -58,7 +55,7 @@ def setup(hass, config): component.setup(config) def handle_scene_service(service): - """ Handles calls to the switch services. """ + """Handle calls to the switch services.""" target_scenes = component.extract_from_service(service) for scene in target_scenes: @@ -70,16 +67,18 @@ def setup(hass, config): class Scene(Entity): - """ 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.""" @property def should_poll(self): + """No polling needed.""" return False @property def state(self): + """Return the state.""" return STATE def activate(self): - """ Activates scene. Tries to get entities into requested state. """ + """Activate scene. Tries to get entities into requested state.""" raise NotImplementedError diff --git a/homeassistant/components/scene/homeassistant.py b/homeassistant/components/scene/homeassistant.py index 0d6c2191133..e0ccad08a76 100644 --- a/homeassistant/components/scene/homeassistant.py +++ b/homeassistant/components/scene/homeassistant.py @@ -1,6 +1,4 @@ """ -homeassistant.components.scene -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Allows users to set and activate scenes. 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 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") if not isinstance(scene_config, list): @@ -37,7 +35,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): def _process_config(scene_config): - """ Process passed in config into a format to work with. """ + """Process passed in config into a format to work with.""" name = scene_config.get('name') states = {} @@ -65,23 +63,25 @@ def _process_config(scene_config): 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): + """Initialize the scene.""" self.hass = hass self.scene_config = scene_config @property def name(self): + """Return the name of the scene.""" return self.scene_config.name @property def device_state_attributes(self): - """ Scene state attributes. """ + """Return the scene state attributes.""" return { ATTR_ENTITY_ID: list(self.scene_config.states.keys()), } 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) From 91731c72344c5c2b7cc785109199b27eb8addc88 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Mon, 7 Mar 2016 23:01:34 +0100 Subject: [PATCH 2/2] Fix PEP257 issues --- .../components/rollershutter/__init__.py | 34 +++++++++---------- .../components/rollershutter/command_line.py | 31 ++++++++--------- .../components/rollershutter/demo.py | 8 +++-- .../components/rollershutter/mqtt.py | 15 ++++---- .../components/rollershutter/scsgate.py | 29 ++++++++-------- 5 files changed, 58 insertions(+), 59 deletions(-) diff --git a/homeassistant/components/rollershutter/__init__.py b/homeassistant/components/rollershutter/__init__.py index 517ebf97b25..109302708b2 100644 --- a/homeassistant/components/rollershutter/__init__.py +++ b/homeassistant/components/rollershutter/__init__.py @@ -1,7 +1,5 @@ """ -homeassistant.components.rollershutter -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Rollershutter component. +Support for Roller shutters. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/rollershutter/ @@ -36,38 +34,38 @@ ATTR_CURRENT_POSITION = 'current_position' 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 return hass.states.is_state(entity_id, STATE_OPEN) 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 hass.services.call(DOMAIN, SERVICE_MOVE_UP, data) 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 hass.services.call(DOMAIN, SERVICE_MOVE_DOWN, data) 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 hass.services.call(DOMAIN, SERVICE_STOP, data) def setup(hass, config): - """ Track states and offer events for rollershutters. """ + """Track states and offer events for roller shutters.""" component = EntityComponent( _LOGGER, DOMAIN, hass, SCAN_INTERVAL, DISCOVERY_PLATFORMS, GROUP_NAME_ALL_ROLLERSHUTTERS) component.setup(config) 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) for rollershutter in target_rollershutters: @@ -98,20 +96,20 @@ def setup(hass, config): class RollershutterDevice(Entity): - """ Represents a rollershutter within Home Assistant. """ - # pylint: disable=no-self-use + """Representation a rollers hutter.""" + # pylint: disable=no-self-use @property def current_position(self): - """ - Return current position of rollershutter. + """Return current position of roller shutter. + None is unknown, 0 is closed, 100 is fully open. """ raise NotImplementedError() @property def state(self): - """ Returns the state of the rollershutter. """ + """Return the state of the roller shutter.""" current = self.current_position if current is None: @@ -121,7 +119,7 @@ class RollershutterDevice(Entity): @property def state_attributes(self): - """ Return the state attributes. """ + """Return the state attributes.""" current = self.current_position if current is None: @@ -132,13 +130,13 @@ class RollershutterDevice(Entity): } def move_up(self, **kwargs): - """ Move the rollershutter down. """ + """Move the roller shutter down.""" raise NotImplementedError() def move_down(self, **kwargs): - """ Move the rollershutter up. """ + """Move the roller shutter up.""" raise NotImplementedError() def stop(self, **kwargs): - """ Stop the rollershutter. """ + """Stop the roller shutter.""" raise NotImplementedError() diff --git a/homeassistant/components/rollershutter/command_line.py b/homeassistant/components/rollershutter/command_line.py index 1808901ef3a..148c93335ac 100644 --- a/homeassistant/components/rollershutter/command_line.py +++ b/homeassistant/components/rollershutter/command_line.py @@ -15,8 +15,7 @@ _LOGGER = logging.getLogger(__name__) 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', {}) 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 class CommandRollershutter(RollershutterDevice): - """ Represents a rollershutter - can be controlled using shell cmd. """ + """Representation a command line roller shutter.""" # pylint: disable=too-many-arguments def __init__(self, hass, name, command_up, command_down, command_stop, command_state, value_template): - + """Initialize the roller shutter.""" self._hass = hass self._name = name - self._state = None # Unknown + self._state = None self._command_up = command_up self._command_down = command_down self._command_stop = command_stop @@ -52,7 +51,7 @@ class CommandRollershutter(RollershutterDevice): @staticmethod def _move_rollershutter(command): - """ Execute the actual commands. """ + """Execute the actual commands.""" _LOGGER.info('Running command: %s', command) success = (subprocess.call(command, shell=True) == 0) @@ -64,7 +63,7 @@ class CommandRollershutter(RollershutterDevice): @staticmethod def _query_state_value(command): - """ Execute state command for return value. """ + """Execute state command for return value.""" _LOGGER.info('Running state command: %s', command) try: @@ -75,31 +74,31 @@ class CommandRollershutter(RollershutterDevice): @property def should_poll(self): - """ Only poll if we have statecmd. """ + """Only poll if we have state command.""" return self._command_state is not None @property def name(self): - """ The name of the rollershutter. """ + """Return the name of the roller shutter.""" return self._name @property def current_position(self): - """ - Return current position of rollershutter. + """Return current position of roller shutter. + None is unknown, 0 is closed, 100 is fully open. """ return self._state def _query_state(self): - """ Query for state. """ + """Query for the state.""" if not self._command_state: _LOGGER.error('No state command specified') return return self._query_state_value(self._command_state) def update(self): - """ Update device state. """ + """Update device state.""" if self._command_state: payload = str(self._query_state()) if self._value_template: @@ -108,13 +107,13 @@ class CommandRollershutter(RollershutterDevice): self._state = int(payload) def move_up(self, **kwargs): - """ Move the rollershutter up. """ + """Move the roller shutter up.""" self._move_rollershutter(self._command_up) def move_down(self, **kwargs): - """ Move the rollershutter down. """ + """Move the roller shutter down.""" self._move_rollershutter(self._command_down) def stop(self, **kwargs): - """ Stop the device. """ + """Stop the device.""" self._move_rollershutter(self._command_stop) diff --git a/homeassistant/components/rollershutter/demo.py b/homeassistant/components/rollershutter/demo.py index 2910f102d11..ebdc3907a59 100644 --- a/homeassistant/components/rollershutter/demo.py +++ b/homeassistant/components/rollershutter/demo.py @@ -18,9 +18,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class DemoRollershutter(RollershutterDevice): - """Represents a roller shutter.""" + """Representation of a demo roller shutter.""" + # pylint: disable=no-self-use def __init__(self, hass, name, position): + """Initialize the roller shutter.""" self.hass = hass self._name = name self._position = position @@ -29,7 +31,7 @@ class DemoRollershutter(RollershutterDevice): @property def name(self): - """Returns the name of the roller shutter.""" + """Return the name of the roller shutter.""" return self._name @property @@ -59,7 +61,7 @@ class DemoRollershutter(RollershutterDevice): self._moving_up = False def stop(self, **kwargs): - """Stops the roller shutter.""" + """Stop the roller shutter.""" if self._listener is not None: self.hass.bus.remove_listener(EVENT_TIME_CHANGED, self._listener) self._listener = None diff --git a/homeassistant/components/rollershutter/mqtt.py b/homeassistant/components/rollershutter/mqtt.py index d5d5a7acb97..45ca9f6d631 100644 --- a/homeassistant/components/rollershutter/mqtt.py +++ b/homeassistant/components/rollershutter/mqtt.py @@ -24,7 +24,6 @@ DEFAULT_PAYLOAD_STOP = "STOP" def setup_platform(hass, config, add_devices_callback, discovery_info=None): """Add MQTT Rollershutter.""" - if config.get('command_topic') is None: _LOGGER.error("Missing required variable: command_topic") 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 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, payload_up, payload_down, payload_stop, value_template): + """Initialize the roller shutter.""" self._state = None self._hass = hass self._name = name @@ -80,24 +81,24 @@ class MqttRollershutter(RollershutterDevice): @property def name(self): - """The name of the rollershutter.""" + """Return the name of the roller shutter.""" return self._name @property def current_position(self): - """ - Return current position of rollershutter. + """Return current position of roller shutter. + None is unknown, 0 is closed, 100 is fully open. """ return self._state def move_up(self, **kwargs): - """Move the rollershutter up.""" + """Move the roller shutter up.""" mqtt.publish(self.hass, self._command_topic, self._payload_up, self._qos) def move_down(self, **kwargs): - """Move the rollershutter down.""" + """Move the roller shutter down.""" mqtt.publish(self.hass, self._command_topic, self._payload_down, self._qos) diff --git a/homeassistant/components/rollershutter/scsgate.py b/homeassistant/components/rollershutter/scsgate.py index 55261a2a617..078173e1924 100644 --- a/homeassistant/components/rollershutter/scsgate.py +++ b/homeassistant/components/rollershutter/scsgate.py @@ -1,7 +1,5 @@ """ -homeassistant.components.rollershutter.scsgate -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Allows to configure a SCSGate rollershutter. +Allow to configure a SCSGate roller shutter. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/rollershutter.scsgate/ @@ -15,8 +13,7 @@ DEPENDENCIES = ['scsgate'] 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') rollershutters = [] 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 class SCSGateRollerShutter(RollershutterDevice): - """ Represents a rollershutter that can be controlled using SCSGate. """ + """Representation of SCSGate rollershutter.""" + def __init__(self, scs_id, name, logger): + """Initialize the roller shutter.""" self._scs_id = scs_id self._name = name self._logger = logger @property def scs_id(self): - """ SCSGate ID """ + """Return the SCSGate ID.""" return self._scs_id @property def should_poll(self): - """ No polling needed """ + """No polling needed.""" return False @property def name(self): - """ The name of the rollershutter. """ + """Return the name of the roller shutter.""" return self._name @property def current_position(self): - """ - Return current position of rollershutter. + """Return current position of roller shutter. + None is unknown, 0 is closed, 100 is fully open. """ return None def move_up(self, **kwargs): - """ Move the rollershutter up. """ + """Move the roller shutter up.""" from scsgate.tasks import RaiseRollerShutterTask scsgate.SCSGATE.append_task( RaiseRollerShutterTask(target=self._scs_id)) def move_down(self, **kwargs): - """ Move the rollershutter down. """ + """Move the rollers hutter down.""" from scsgate.tasks import LowerRollerShutterTask scsgate.SCSGATE.append_task( LowerRollerShutterTask(target=self._scs_id)) def stop(self, **kwargs): - """ Stop the device. """ + """Stop the device.""" 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 rollershutter """ + """Handle a SCSGate message related with this roller shutter.""" self._logger.debug( "Rollershutter %s, got message %s", self._scs_id, message.toggled)