Fix PEP257 issues

This commit is contained in:
Fabian Affolter 2016-03-08 13:35:39 +01:00
parent 652f059d6a
commit 49ebc6d0b0
29 changed files with 294 additions and 309 deletions

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component to interface with various switches that can be controlled remotely. Component to interface with various switches that can be controlled remotely.
For more details about this component, please refer to the documentation For more details about this component, please refer to the documentation
@ -53,38 +51,38 @@ _LOGGER = logging.getLogger(__name__)
def is_on(hass, entity_id=None): def is_on(hass, entity_id=None):
""" Returns if the switch is on based on the statemachine. """ """Return if the switch is on based on the statemachine."""
entity_id = entity_id or ENTITY_ID_ALL_SWITCHES entity_id = entity_id or ENTITY_ID_ALL_SWITCHES
return hass.states.is_state(entity_id, STATE_ON) return hass.states.is_state(entity_id, STATE_ON)
def turn_on(hass, entity_id=None): def turn_on(hass, entity_id=None):
""" Turns all or specified switch on. """ """Turn all or specified switch on."""
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_TURN_ON, data) hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
def turn_off(hass, entity_id=None): def turn_off(hass, entity_id=None):
""" Turns all or specified switch off. """ """Turn all or specified switch off."""
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_TURN_OFF, data) hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
def toggle(hass, entity_id=None): def toggle(hass, entity_id=None):
""" Toggle all or specified switch. """ """Toggle all or specified switch."""
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_TOGGLE, data) hass.services.call(DOMAIN, SERVICE_TOGGLE, data)
def setup(hass, config): def setup(hass, config):
""" Track states and offer events for switches. """ """Track states and offer events for switches."""
component = EntityComponent( component = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL, DISCOVERY_PLATFORMS, _LOGGER, DOMAIN, hass, SCAN_INTERVAL, DISCOVERY_PLATFORMS,
GROUP_NAME_ALL_SWITCHES) GROUP_NAME_ALL_SWITCHES)
component.setup(config) component.setup(config)
def handle_switch_service(service): def handle_switch_service(service):
""" Handles calls to the switch services. """ """Handle calls to the switch services."""
target_switches = component.extract_from_service(service) target_switches = component.extract_from_service(service)
for switch in target_switches: for switch in target_switches:
@ -111,27 +109,27 @@ def setup(hass, config):
class SwitchDevice(ToggleEntity): class SwitchDevice(ToggleEntity):
""" Represents a switch within Home Assistant. """ """Representation of a switch."""
# pylint: disable=no-self-use
# pylint: disable=no-self-use
@property @property
def current_power_mwh(self): def current_power_mwh(self):
""" Current power usage in mwh. """ """Return the current power usage in mWh."""
return None return None
@property @property
def today_power_mw(self): def today_power_mw(self):
""" Today total power usage in mw. """ """Return the today total power usage in mW."""
return None return None
@property @property
def is_standby(self): def is_standby(self):
""" Is the device in standby. """ """Return true if device is in standby."""
return None return None
@property @property
def state_attributes(self): def state_attributes(self):
""" Returns optional state attributes. """ """Return the optional state attributes."""
data = {} data = {}
for prop, attr in PROP_TO_ATTR.items(): for prop, attr in PROP_TO_ATTR.items():

View file

@ -1,8 +1,7 @@
""" """
homeassistant.components.switch.arduino Support for switching Arduino pins on and off.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for switching Arduino pins on and off. So far only digital pins are So far only digital pins are supported.
supported.
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/switch.arduino/ https://home-assistant.io/components/switch.arduino/
@ -19,8 +18,7 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Arduino platform. """ """Setup the Arduino platform."""
# Verify that Arduino board is present # Verify that Arduino board is present
if arduino.BOARD is None: if arduino.BOARD is None:
_LOGGER.error('A connection has not been made to the Arduino board.') _LOGGER.error('A connection has not been made to the Arduino board.')
@ -37,8 +35,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ArduinoSwitch(SwitchDevice): class ArduinoSwitch(SwitchDevice):
""" Represents an Arduino switch. """ """Representation of an Arduino switch."""
def __init__(self, name, pin, pin_type): def __init__(self, name, pin, pin_type):
"""Initialize the Pin."""
self._pin = pin self._pin = pin
self._name = name or DEVICE_DEFAULT_NAME self._name = name or DEVICE_DEFAULT_NAME
self.pin_type = pin_type self.pin_type = pin_type
@ -49,20 +49,20 @@ class ArduinoSwitch(SwitchDevice):
@property @property
def name(self): def name(self):
""" Get the name of the pin. """ """Get the name of the pin."""
return self._name return self._name
@property @property
def is_on(self): def is_on(self):
""" Returns True if pin is high/on. """ """Return true if pin is high/on."""
return self._state return self._state
def turn_on(self): def turn_on(self):
""" Turns the pin to high/on. """ """Turn the pin to high/on."""
self._state = True self._state = True
arduino.BOARD.set_digital_out_high(self._pin) arduino.BOARD.set_digital_out_high(self._pin)
def turn_off(self): def turn_off(self):
""" Turns the pin to low/off. """ """Turn the pin to low/off."""
self._state = False self._state = False
arduino.BOARD.set_digital_out_low(self._pin) arduino.BOARD.set_digital_out_low(self._pin)

View file

@ -1,8 +1,5 @@
""" """
homeassistant.components.switch.arest Support for device running with the aREST RESTful framework.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The arest switch can control the digital pins of a device running with the
aREST RESTful framework for Arduino, the ESP8266, and the Raspberry Pi.
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/switch.arest/ https://home-assistant.io/components/switch.arest/
@ -18,8 +15,7 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Get the aREST switches. """ """Setup the aREST switches."""
resource = config.get('resource', None) resource = config.get('resource', None)
try: try:
@ -54,9 +50,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ArestSwitchBase(SwitchDevice): class ArestSwitchBase(SwitchDevice):
""" Implements an aREST switch. """ """representation of an aREST switch."""
def __init__(self, resource, location, name): def __init__(self, resource, location, name):
"""Initialize the switch."""
self._resource = resource self._resource = resource
self._name = '{} {}'.format(location.title(), name.title()) \ self._name = '{} {}'.format(location.title(), name.title()) \
or DEVICE_DEFAULT_NAME or DEVICE_DEFAULT_NAME
@ -64,19 +61,20 @@ class ArestSwitchBase(SwitchDevice):
@property @property
def name(self): def name(self):
""" The name of the switch. """ """Return the name of the switch."""
return self._name return self._name
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """Return true if device is on."""
return self._state return self._state
class ArestSwitchFunction(ArestSwitchBase): class ArestSwitchFunction(ArestSwitchBase):
""" Implements an aREST switch. Based on functions. """ """Representation of an aREST switch."""
def __init__(self, resource, location, name, func): def __init__(self, resource, location, name, func):
"""Initialize the switch."""
super().__init__(resource, location, name) super().__init__(resource, location, name)
self._func = func self._func = func
@ -96,7 +94,7 @@ class ArestSwitchFunction(ArestSwitchBase):
_LOGGER.error("Response invalid. Is the function name correct.") _LOGGER.error("Response invalid. Is the function name correct.")
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """Turn the device on."""
request = requests.get('{}/{}'.format(self._resource, self._func), request = requests.get('{}/{}'.format(self._resource, self._func),
timeout=10, params={"params": "1"}) timeout=10, params={"params": "1"})
@ -108,7 +106,7 @@ class ArestSwitchFunction(ArestSwitchBase):
self._func, self._resource) self._func, self._resource)
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off. """ """Turn the device off."""
request = requests.get('{}/{}'.format(self._resource, self._func), request = requests.get('{}/{}'.format(self._resource, self._func),
timeout=10, params={"params": "0"}) timeout=10, params={"params": "0"})
@ -120,16 +118,17 @@ class ArestSwitchFunction(ArestSwitchBase):
self._func, self._resource) self._func, self._resource)
def update(self): def update(self):
""" Gets the latest data from aREST API and updates the state. """ """Get the latest data from aREST API and update the state."""
request = requests.get('{}/{}'.format(self._resource, request = requests.get('{}/{}'.format(self._resource,
self._func), timeout=10) self._func), timeout=10)
self._state = request.json()['return_value'] != 0 self._state = request.json()['return_value'] != 0
class ArestSwitchPin(ArestSwitchBase): class ArestSwitchPin(ArestSwitchBase):
""" Implements an aREST switch. Based on digital I/O """ """Representation of an aREST switch. Based on digital I/O."""
def __init__(self, resource, location, name, pin): def __init__(self, resource, location, name, pin):
"""Initialize the switch."""
super().__init__(resource, location, name) super().__init__(resource, location, name)
self._pin = pin self._pin = pin
@ -139,7 +138,7 @@ class ArestSwitchPin(ArestSwitchBase):
_LOGGER.error("Can't set mode. Is device offline?") _LOGGER.error("Can't set mode. Is device offline?")
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """Turn the device on."""
request = requests.get('{}/digital/{}/1'.format(self._resource, request = requests.get('{}/digital/{}/1'.format(self._resource,
self._pin), timeout=10) self._pin), timeout=10)
if request.status_code == 200: if request.status_code == 200:
@ -149,7 +148,7 @@ class ArestSwitchPin(ArestSwitchBase):
self._pin, self._resource) self._pin, self._resource)
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off. """ """Turn the device off."""
request = requests.get('{}/digital/{}/0'.format(self._resource, request = requests.get('{}/digital/{}/0'.format(self._resource,
self._pin), timeout=10) self._pin), timeout=10)
if request.status_code == 200: if request.status_code == 200:
@ -159,7 +158,7 @@ class ArestSwitchPin(ArestSwitchBase):
self._pin, self._resource) self._pin, self._resource)
def update(self): def update(self):
""" Gets the latest data from aREST API and updates the state. """ """Get the latest data from aREST API and update the state."""
request = requests.get('{}/digital/{}'.format(self._resource, request = requests.get('{}/digital/{}'.format(self._resource,
self._pin), timeout=10) self._pin), timeout=10)
self._state = request.json()['return_value'] != 0 self._state = request.json()['return_value'] != 0

View file

@ -34,12 +34,12 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class CommandSwitch(SwitchDevice): class CommandSwitch(SwitchDevice):
"""Represents a switch that can be toggled using shell commands.""" """Representation a switch that can be toggled using shell commands."""
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def __init__(self, hass, name, command_on, command_off, def __init__(self, hass, name, command_on, command_off,
command_state, value_template): command_state, value_template):
"""Initialize the switch."""
self._hass = hass self._hass = hass
self._name = name self._name = name
self._state = False self._state = False
@ -84,12 +84,12 @@ class CommandSwitch(SwitchDevice):
@property @property
def name(self): def name(self):
"""The name of the switch.""" """Return the name of the switch."""
return self._name return self._name
@property @property
def is_on(self): def is_on(self):
"""True if device is on.""" """Return true if device is on."""
return self._state return self._state
def _query_state(self): def _query_state(self):

View file

@ -18,8 +18,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class DemoSwitch(SwitchDevice): class DemoSwitch(SwitchDevice):
"""Provide a demo switch.""" """represenation of a demo switch."""
def __init__(self, name, state, icon, assumed): def __init__(self, name, state, icon, assumed):
"""Initialize the Deom switch."""
self._name = name or DEVICE_DEFAULT_NAME self._name = name or DEVICE_DEFAULT_NAME
self._state = state self._state = state
self._icon = icon self._icon = icon
@ -47,13 +49,13 @@ class DemoSwitch(SwitchDevice):
@property @property
def current_power_mwh(self): def current_power_mwh(self):
"""Returns the current power usage in mwh.""" """Return the current power usage in mWh."""
if self._state: if self._state:
return 100 return 100
@property @property
def today_power_mw(self): def today_power_mw(self):
"""Return the today total power usage in mw.""" """Return the today total power usage in mW."""
return 1500 return 1500
@property @property

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.dlink
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for D-link W215 smart switch. Support for D-link W215 smart switch.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -26,7 +24,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return D-Link Smart Plugs. """ """Find and return D-Link Smart Plugs."""
from pyW215.pyW215 import SmartPlug from pyW215.pyW215 import SmartPlug
# check for required values in configuration file # check for required values in configuration file
@ -47,19 +45,21 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class SmartPlugSwitch(SwitchDevice): class SmartPlugSwitch(SwitchDevice):
""" Represents an d-link Smart Plug switch. """ """Representation of a D-link Smart Plug switch."""
def __init__(self, smartplug, name): def __init__(self, smartplug, name):
"""Initialize the switch."""
self.smartplug = smartplug self.smartplug = smartplug
self._name = name self._name = name
@property @property
def name(self): def name(self):
""" Returns the name of the Smart Plug, if any. """ """Return the name of the Smart Plug, if any."""
return self._name return self._name
@property @property
def current_power_watt(self): def current_power_watt(self):
""" Current power usage in watt. """ """Return the current power usage in Watt."""
try: try:
return float(self.smartplug.current_consumption) return float(self.smartplug.current_consumption)
except ValueError: except ValueError:
@ -67,13 +67,13 @@ class SmartPlugSwitch(SwitchDevice):
@property @property
def is_on(self): def is_on(self):
""" True if switch is on. """ """Return true if switch is on."""
return self.smartplug.state == 'ON' return self.smartplug.state == 'ON'
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turns the switch on. """ """Turn the switch on."""
self.smartplug.state = 'ON' self.smartplug.state = 'ON'
def turn_off(self): def turn_off(self):
""" Turns the switch off. """ """Turn the switch off."""
self.smartplug.state = 'OFF' self.smartplug.state = 'OFF'

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.edimax
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Edimax switches. Support for Edimax switches.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -20,13 +18,12 @@ DEVICE_DEFAULT_NAME = 'Edimax Smart Plug'
REQUIREMENTS = ['https://github.com/rkabadi/pyedimax/archive/' REQUIREMENTS = ['https://github.com/rkabadi/pyedimax/archive/'
'365301ce3ff26129a7910c501ead09ea625f3700.zip#pyedimax==0.1'] '365301ce3ff26129a7910c501ead09ea625f3700.zip#pyedimax==0.1']
# setup logger
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return Edimax Smart Plugs. """ """Find and return Edimax Smart Plugs."""
from pyedimax.smartplug import SmartPlug from pyedimax.smartplug import SmartPlug
# pylint: disable=global-statement # pylint: disable=global-statement
@ -45,19 +42,21 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class SmartPlugSwitch(SwitchDevice): class SmartPlugSwitch(SwitchDevice):
""" Represents an Edimax Smart Plug switch. """ """Representation an Edimax Smart Plug switch."""
def __init__(self, smartplug, name): def __init__(self, smartplug, name):
"""Initialize the switch."""
self.smartplug = smartplug self.smartplug = smartplug
self._name = name self._name = name
@property @property
def name(self): def name(self):
""" Returns the name of the Smart Plug, if any. """ """Return the name of the Smart Plug, if any."""
return self._name return self._name
@property @property
def current_power_mwh(self): def current_power_mwh(self):
""" Current power usage in mWh. """ """Return the current power usage in mWh."""
try: try:
return float(self.smartplug.now_power) / 1000000.0 return float(self.smartplug.now_power) / 1000000.0
except ValueError: except ValueError:
@ -65,7 +64,7 @@ class SmartPlugSwitch(SwitchDevice):
@property @property
def today_power_mw(self): def today_power_mw(self):
""" Today total power usage in mW. """ """Return the today total power usage in mW."""
try: try:
return float(self.smartplug.now_energy_day) / 1000.0 return float(self.smartplug.now_energy_day) / 1000.0
except ValueError: except ValueError:
@ -73,13 +72,13 @@ class SmartPlugSwitch(SwitchDevice):
@property @property
def is_on(self): def is_on(self):
""" True if switch is on. """ """Return true if switch is on."""
return self.smartplug.state == 'ON' return self.smartplug.state == 'ON'
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turns the switch on. """ """Turn the switch on."""
self.smartplug.state = 'ON' self.smartplug.state = 'ON'
def turn_off(self): def turn_off(self):
""" Turns the switch off. """ """Turn the switch off."""
self.smartplug.state = 'OFF' self.smartplug.state = 'OFF'

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.hikvision
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support turning on/off motion detection on Hikvision cameras. Support turning on/off motion detection on Hikvision cameras.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -19,7 +17,7 @@ REQUIREMENTS = ['hikvision==0.4']
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Setup Hikvision camera. """ """Setup Hikvision camera."""
import hikvision.api import hikvision.api
from hikvision.error import HikvisionError, MissingParamError from hikvision.error import HikvisionError, MissingParamError
@ -46,48 +44,46 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class HikvisionMotionSwitch(ToggleEntity): class HikvisionMotionSwitch(ToggleEntity):
"""Representation of a switch to toggle on/off motion detection."""
""" Provides a switch to toggle on/off motion detection. """
def __init__(self, name, hikvision_cam): def __init__(self, name, hikvision_cam):
"""Initialize the switch."""
self._name = name self._name = name
self._hikvision_cam = hikvision_cam self._hikvision_cam = hikvision_cam
self._state = STATE_OFF self._state = STATE_OFF
@property @property
def should_poll(self): def should_poll(self):
""" Poll for status regularly. """ """Poll for status regularly."""
return True return True
@property @property
def name(self): def name(self):
""" Returns the name of the device if any. """ """Return the name of the device if any."""
return self._name return self._name
@property @property
def state(self): def state(self):
""" Returns the state of the device if any. """ """Return the state of the device if any."""
return self._state return self._state
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """Return true if device is on."""
return self._state == STATE_ON return self._state == STATE_ON
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """Turn the device on."""
_LOGGING.info("Turning on Motion Detection ") _LOGGING.info("Turning on Motion Detection ")
self._hikvision_cam.enable_motion_detection() self._hikvision_cam.enable_motion_detection()
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off. """ """Turn the device off."""
_LOGGING.info("Turning off Motion Detection ") _LOGGING.info("Turning off Motion Detection ")
self._hikvision_cam.disable_motion_detection() self._hikvision_cam.disable_motion_detection()
def update(self): def update(self):
""" Update Motion Detection state """ """Update Motion Detection state."""
enabled = self._hikvision_cam.is_motion_detection_enabled() enabled = self._hikvision_cam.is_motion_detection_enabled()
_LOGGING.info('enabled: %s', enabled) _LOGGING.info('enabled: %s', enabled)

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.isy994
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for ISY994 switches. Support for ISY994 switches.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -19,7 +17,7 @@ from homeassistant.const import STATE_OFF, STATE_ON # STATE_OPEN, STATE_CLOSED
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the ISY994 platform. """ """Setup the ISY994 platform."""
# pylint: disable=too-many-locals # pylint: disable=too-many-locals
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
devs = [] devs = []
@ -28,14 +26,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
logger.error('A connection has not been made to the ISY controller.') logger.error('A connection has not been made to the ISY controller.')
return False return False
# import not dimmable nodes and groups # Import not dimmable nodes and groups
for (path, node) in ISY.nodes: for (path, node) in ISY.nodes:
if not node.dimmable and SENSOR_STRING not in node.name: if not node.dimmable and SENSOR_STRING not in node.name:
if HIDDEN_STRING in path: if HIDDEN_STRING in path:
node.name += HIDDEN_STRING node.name += HIDDEN_STRING
devs.append(ISYSwitchDevice(node)) devs.append(ISYSwitchDevice(node))
# import ISY doors programs # Import ISY doors programs
for folder_name, states in (('HA.doors', [STATE_ON, STATE_OFF]), for folder_name, states in (('HA.doors', [STATE_ON, STATE_OFF]),
('HA.switches', [STATE_ON, STATE_OFF])): ('HA.switches', [STATE_ON, STATE_OFF])):
try: try:
@ -61,7 +59,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ISYSwitchDevice(ISYDeviceABC): class ISYSwitchDevice(ISYDeviceABC):
""" Represents as ISY light. """ """Representation of an ISY switch."""
_domain = 'switch' _domain = 'switch'
_dtype = 'binary' _dtype = 'binary'
@ -69,21 +67,22 @@ class ISYSwitchDevice(ISYDeviceABC):
class ISYProgramDevice(ISYSwitchDevice): class ISYProgramDevice(ISYSwitchDevice):
""" Represents a door that can be manipulated. """ """Representation of an ISY door."""
_domain = 'switch' _domain = 'switch'
_dtype = 'binary' _dtype = 'binary'
def __init__(self, name, node, actions, states): def __init__(self, name, node, actions, states):
"""Initialize the switch."""
super().__init__(node) super().__init__(node)
self._states = states self._states = states
self._name = name self._name = name
self.action_node = actions self.action_node = actions
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turns the device on/closes the device. """ """Turn the device on/close the device."""
self.action_node.runThen() self.action_node.runThen()
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turns the device off/opens the device. """ """Turn the device off/open the device."""
self.action_node.runElse() self.action_node.runElse()

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.mfi
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Ubiquiti mFi switches. Support for Ubiquiti mFi switches.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -30,8 +28,7 @@ CONF_VERIFY_TLS = 'verify_tls'
# pylint: disable=unused-variable # pylint: disable=unused-variable
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up mFi sensors. """ """Setup mFi sensors."""
if not validate_config({DOMAIN: config}, if not validate_config({DOMAIN: config},
{DOMAIN: ['host', {DOMAIN: ['host',
CONF_USERNAME, CONF_USERNAME,
@ -64,47 +61,58 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class MfiSwitch(SwitchDevice): class MfiSwitch(SwitchDevice):
""" An mFi switch-able device. """ """Representation of an mFi switch-able device."""
def __init__(self, port): def __init__(self, port):
"""Initialize the mFi device."""
self._port = port self._port = port
self._target_state = None self._target_state = None
@property @property
def should_poll(self): def should_poll(self):
"""Polling is needed."""
return True return True
@property @property
def unique_id(self): def unique_id(self):
"""Return the unique ID of the device."""
return self._port.ident return self._port.ident
@property @property
def name(self): def name(self):
"""Return the name of the device."""
return self._port.label return self._port.label
@property @property
def is_on(self): def is_on(self):
"""Return true if the device is on."""
return self._port.output return self._port.output
def update(self): def update(self):
"""Get the latest state and update the state."""
self._port.refresh() self._port.refresh()
if self._target_state is not None: if self._target_state is not None:
self._port.data['output'] = float(self._target_state) self._port.data['output'] = float(self._target_state)
self._target_state = None self._target_state = None
def turn_on(self): def turn_on(self):
"""Turn the switch on."""
self._port.control(True) self._port.control(True)
self._target_state = True self._target_state = True
def turn_off(self): def turn_off(self):
"""Turn the switch off."""
self._port.control(False) self._port.control(False)
self._target_state = False self._target_state = False
@property @property
def current_power_mwh(self): def current_power_mwh(self):
"""Return the current power usage in mWh."""
return int(self._port.data.get('active_pwr', 0) * 1000) return int(self._port.data.get('active_pwr', 0) * 1000)
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes fof the device."""
attr = {} attr = {}
attr['volts'] = round(self._port.data.get('v_rms', 0), 1) attr['volts'] = round(self._port.data.get('v_rms', 0), 1)
attr['amps'] = round(self._port.data.get('i_rms', 0), 1) attr['amps'] = round(self._port.data.get('i_rms', 0), 1)

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.modbus
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Modbus switches. Support for Modbus switches.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -16,7 +14,7 @@ DEPENDENCIES = ['modbus']
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Read configuration and create Modbus devices. """ """Read configuration and create Modbus devices."""
switches = [] switches = []
slave = config.get("slave", None) slave = config.get("slave", None)
if modbus.TYPE == "serial" and not slave: if modbus.TYPE == "serial" and not slave:
@ -44,10 +42,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ModbusSwitch(ToggleEntity): class ModbusSwitch(ToggleEntity):
# pylint: disable=too-many-arguments """Representation of a Modbus switch."""
""" Represents a Modbus switch. """
# pylint: disable=too-many-arguments
def __init__(self, name, slave, register, bit, coil=False): def __init__(self, name, slave, register, bit, coil=False):
"""Initialize the switch."""
self._name = name self._name = name
self.slave = int(slave) if slave else 1 self.slave = int(slave) if slave else 1
self.register = int(register) self.register = int(register)
@ -61,31 +60,31 @@ class ModbusSwitch(ToggleEntity):
@property @property
def should_poll(self): def should_poll(self):
""" """Poling needed.
We should poll, because slaves are not allowed to initiate
communication on Modbus networks. Slaves are not allowed to initiate communication on Modbus networks.
""" """
return True return True
@property @property
def unique_id(self): def unique_id(self):
""" Returns a unique id. """ """Return a unique ID."""
return "MODBUS-SWITCH-{}-{}-{}".format(self.slave, return "MODBUS-SWITCH-{}-{}-{}".format(self.slave,
self.register, self.register,
self.bit) self.bit)
@property @property
def is_on(self): def is_on(self):
""" Returns True if switch is on. """ """Return true if switch is on."""
return self._is_on return self._is_on
@property @property
def name(self): def name(self):
""" Get the name of the switch. """ """Return the name of the switch."""
return self._name return self._name
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Set switch on. """ """Set switch on."""
if self.register_value is None: if self.register_value is None:
self.update() self.update()
@ -98,7 +97,7 @@ class ModbusSwitch(ToggleEntity):
value=val) value=val)
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Set switch off. """ """Set switch off."""
if self.register_value is None: if self.register_value is None:
self.update() self.update()
@ -111,7 +110,7 @@ class ModbusSwitch(ToggleEntity):
value=val) value=val)
def update(self): def update(self):
""" Update the state of the switch. """ """Update the state of the switch."""
if self._coil: if self._coil:
result = modbus.NETWORK.read_coils(self.register, 1) result = modbus.NETWORK.read_coils(self.register, 1)
self.register_value = result.bits[0] self.register_value = result.bits[0]

View file

@ -26,7 +26,6 @@ DEPENDENCIES = ['mqtt']
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Add MQTT switch.""" """Add MQTT switch."""
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
@ -46,9 +45,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 MqttSwitch(SwitchDevice): class MqttSwitch(SwitchDevice):
"""Represents a switch that can be toggled using MQTT.""" """Representation of a switch that can be toggled using MQTT."""
def __init__(self, hass, name, state_topic, command_topic, qos, retain, def __init__(self, hass, name, state_topic, command_topic, qos, retain,
payload_on, payload_off, optimistic, value_template): payload_on, payload_off, optimistic, value_template):
"""Initialize the MQTT switch."""
self._state = False self._state = False
self._hass = hass self._hass = hass
self._name = name self._name = name
@ -86,17 +87,17 @@ class MqttSwitch(SwitchDevice):
@property @property
def name(self): def name(self):
"""The name of the switch.""" """Return the name of the switch."""
return self._name return self._name
@property @property
def is_on(self): def is_on(self):
"""True if device is on.""" """Return true if device is on."""
return self._state return self._state
@property @property
def assumed_state(self): def assumed_state(self):
"""Return True if we do optimistic updates.""" """Return true if we do optimistic updates."""
return self._optimistic return self._optimistic
def turn_on(self, **kwargs): def turn_on(self, **kwargs):

View file

@ -52,10 +52,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class MySensorsSwitch(SwitchDevice): class MySensorsSwitch(SwitchDevice):
"""Represent the value of a MySensors child node.""" """Representation of the value of a MySensors child node."""
# pylint: disable=too-many-arguments,too-many-instance-attributes # pylint: disable=too-many-arguments,too-many-instance-attributes
def __init__( def __init__(
self, gateway, node_id, child_id, name, value_type, child_type): self, gateway, node_id, child_id, name, value_type, child_type):
"""Setup class attributes on instantiation. """Setup class attributes on instantiation.

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.mystrom
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for myStrom switches. Support for myStrom switches.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
@ -18,7 +16,7 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Find and return myStrom switches. """ """Find and return myStrom switch."""
host = config.get('host') host = config.get('host')
if host is None: if host is None:
@ -41,8 +39,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class MyStromSwitch(SwitchDevice): class MyStromSwitch(SwitchDevice):
""" Represents a myStrom switch. """ """Representation of a myStrom switch."""
def __init__(self, name, resource): def __init__(self, name, resource):
"""Initialize the myStrom switch."""
self._state = False self._state = False
self._name = name self._name = name
self._resource = resource self._resource = resource
@ -50,21 +50,21 @@ class MyStromSwitch(SwitchDevice):
@property @property
def name(self): def name(self):
""" The name of the switch. """ """Return the name of the switch."""
return self._name return self._name
@property @property
def is_on(self): def is_on(self):
""" True if switch is on. """ """Return true if switch is on."""
return self._state return self._state
@property @property
def current_power_mwh(self): def current_power_mwh(self):
""" Current power consumption in mwh. """ """Return the urrent power consumption in mWh."""
return self.consumption return self.consumption
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the switch on. """ """Turn the switch on."""
try: try:
request = requests.get('{}/relay'.format(self._resource), request = requests.get('{}/relay'.format(self._resource),
params={'state': '1'}, params={'state': '1'},
@ -76,7 +76,7 @@ class MyStromSwitch(SwitchDevice):
self._resource) self._resource)
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the switch off. """ """Turn the switch off."""
try: try:
request = requests.get('{}/relay'.format(self._resource), request = requests.get('{}/relay'.format(self._resource),
params={'state': '0'}, params={'state': '0'},
@ -88,7 +88,7 @@ class MyStromSwitch(SwitchDevice):
self._resource) self._resource)
def update(self): def update(self):
""" Gets the latest data from REST API and updates the state. """ """Get the latest data from REST API and update the state."""
try: try:
request = requests.get('{}/report'.format(self._resource), request = requests.get('{}/report'.format(self._resource),
timeout=10) timeout=10)

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.orvibo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Orvibo S20 Wifi Smart Switches. Support for Orvibo S20 Wifi Smart Switches.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -17,7 +15,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return S20 switches. """ """Find and return S20 switches."""
from orvibo.s20 import S20, S20Exception from orvibo.s20 import S20, S20Exception
switches = [] switches = []
@ -40,8 +38,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class S20Switch(SwitchDevice): class S20Switch(SwitchDevice):
""" Represents an S20 switch. """ """Representsation of an S20 switch."""
def __init__(self, name, s20): def __init__(self, name, s20):
"""Initialize the S20 device."""
from orvibo.s20 import S20Exception from orvibo.s20 import S20Exception
self._name = name self._name = name
@ -51,35 +51,35 @@ class S20Switch(SwitchDevice):
@property @property
def should_poll(self): def should_poll(self):
""" Poll. """ """Polling is needed."""
return True return True
@property @property
def name(self): def name(self):
""" The name of the switch. """ """Return the name of the switch."""
return self._name return self._name
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """Return true if device is on."""
return self._state return self._state
def update(self): def update(self):
""" Update device state. """ """Update device state."""
try: try:
self._state = self._s20.on self._state = self._s20.on
except self._exc: except self._exc:
_LOGGER.exception("Error while fetching S20 state") _LOGGER.exception("Error while fetching S20 state")
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """Turn the device on."""
try: try:
self._s20.on = True self._s20.on = True
except self._exc: except self._exc:
_LOGGER.exception("Error while turning on S20") _LOGGER.exception("Error while turning on S20")
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off. """ """Turn the device off."""
try: try:
self._s20.on = False self._s20.on = False
except self._exc: except self._exc:

View file

@ -1,7 +1,5 @@
""" """
homeassistant.components.switch.rest Support for RESTful switches.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to configure a REST switch.
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/switch.rest/ https://home-assistant.io/components/switch.rest/
@ -21,8 +19,7 @@ DEFAULT_BODY_OFF = "OFF"
# pylint: disable=unused-argument, # pylint: disable=unused-argument,
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Get REST switch. """ """Setup the REST switch."""
resource = config.get('resource') resource = config.get('resource')
if resource is None: if resource is None:
@ -49,8 +46,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
class RestSwitch(SwitchDevice): class RestSwitch(SwitchDevice):
""" Represents a switch that can be toggled using REST. """ """Representation of a switch that can be toggled using REST."""
def __init__(self, hass, name, resource, body_on, body_off): def __init__(self, hass, name, resource, body_on, body_off):
"""Initialize the REST switch."""
self._state = None self._state = None
self._hass = hass self._hass = hass
self._name = name self._name = name
@ -60,16 +59,16 @@ class RestSwitch(SwitchDevice):
@property @property
def name(self): def name(self):
""" The name of the switch. """ """The name of the switch."""
return self._name return self._name
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """return true if device is on."""
return self._state return self._state
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """Turn the device on."""
request = requests.post(self._resource, request = requests.post(self._resource,
data=self._body_on, data=self._body_on,
timeout=10) timeout=10)
@ -80,7 +79,7 @@ class RestSwitch(SwitchDevice):
self._resource) self._resource)
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off. """ """Turn the device off."""
request = requests.post(self._resource, request = requests.post(self._resource,
data=self._body_off, data=self._body_off,
timeout=10) timeout=10)
@ -91,7 +90,7 @@ class RestSwitch(SwitchDevice):
self._resource) self._resource)
def update(self): def update(self):
""" Gets the latest data from REST API and updates the state. """ """Get the latest data from REST API and update the state."""
request = requests.get(self._resource, timeout=10) request = requests.get(self._resource, timeout=10)
if request.text == self._body_on: if request.text == self._body_on:
self._state = True self._state = True

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.rfxtrx
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for RFXtrx switches. Support for RFXtrx switches.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -22,7 +20,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 the RFXtrx platform. """ """Setup the RFXtrx platform."""
import RFXtrx as rfxtrxmod import RFXtrx as rfxtrxmod
# Add switch from config file # Add switch from config file
@ -47,7 +45,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
add_devices_callback(switchs) add_devices_callback(switchs)
def switch_update(event): def switch_update(event):
""" Callback for sensor updates from the RFXtrx gateway. """ """Callback for sensor updates from the RFXtrx gateway."""
if not isinstance(event.device, rfxtrxmod.LightingDevice) or \ if not isinstance(event.device, rfxtrxmod.LightingDevice) or \
event.device.known_to_be_dimmable: event.device.known_to_be_dimmable:
return return
@ -107,8 +105,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class RfxtrxSwitch(SwitchDevice): class RfxtrxSwitch(SwitchDevice):
""" Provides a RFXtrx switch. """ """Representation of a RFXtrx switch."""
def __init__(self, name, event, datas, signal_repetitions): def __init__(self, name, event, datas, signal_repetitions):
"""Initialize the switch."""
self._name = name self._name = name
self._event = event self._event = event
self._state = datas[ATTR_STATE] self._state = datas[ATTR_STATE]
@ -117,31 +117,31 @@ class RfxtrxSwitch(SwitchDevice):
@property @property
def should_poll(self): def should_poll(self):
""" No polling needed for a RFXtrx switch. """ """No polling needed for a RFXtrx switch."""
return False return False
@property @property
def name(self): def name(self):
""" Returns the name of the device if any. """ """Return the name of the device if any."""
return self._name return self._name
@property @property
def should_fire_event(self): def should_fire_event(self):
""" Returns is the device must fire event""" """Return is the device must fire event."""
return self._should_fire_event return self._should_fire_event
@property @property
def is_on(self): def is_on(self):
""" True if light is on. """ """Return true if light is on."""
return self._state return self._state
@property @property
def assumed_state(self): def assumed_state(self):
"""Return True if unable to access real state of entity.""" """Return true if unable to access real state of entity."""
return True return True
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """Turn the device on."""
if not self._event: if not self._event:
return return
@ -152,7 +152,7 @@ class RfxtrxSwitch(SwitchDevice):
self.update_ha_state() self.update_ha_state()
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off. """ """Turn the device off."""
if not self._event: if not self._event:
return return

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.rpi_gpio
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to configure a switch using RPi GPIO. Allows to configure a switch using RPi GPIO.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -21,8 +19,7 @@ _LOGGER = logging.getLogger(__name__)
# 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 the Raspberry PI GPIO devices. """ """Setup the Raspberry PI GPIO devices."""
invert_logic = config.get('invert_logic', DEFAULT_INVERT_LOGIC) invert_logic = config.get('invert_logic', DEFAULT_INVERT_LOGIC)
switches = [] switches = []
@ -33,8 +30,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class RPiGPIOSwitch(ToggleEntity): class RPiGPIOSwitch(ToggleEntity):
""" Represents a switch that can be toggled using Raspberry Pi GPIO. """ """Representation of a Raspberry Pi GPIO."""
def __init__(self, name, port, invert_logic): def __init__(self, name, port, invert_logic):
"""Initialize the pin."""
self._name = name or DEVICE_DEFAULT_NAME self._name = name or DEVICE_DEFAULT_NAME
self._port = port self._port = port
self._invert_logic = invert_logic self._invert_logic = invert_logic
@ -43,27 +42,27 @@ class RPiGPIOSwitch(ToggleEntity):
@property @property
def name(self): def name(self):
""" The name of the switch. """ """Return the name of the switch."""
return self._name return self._name
@property @property
def should_poll(self): def should_poll(self):
""" No polling needed. """ """No polling needed."""
return False return False
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """Return true if device is on."""
return self._state return self._state
def turn_on(self): def turn_on(self):
""" Turn the device on. """ """Turn the device on."""
rpi_gpio.write_output(self._port, 0 if self._invert_logic else 1) rpi_gpio.write_output(self._port, 0 if self._invert_logic else 1)
self._state = True self._state = True
self.update_ha_state() self.update_ha_state()
def turn_off(self): def turn_off(self):
""" Turn the device off. """ """Turn the device off."""
rpi_gpio.write_output(self._port, 1 if self._invert_logic else 0) rpi_gpio.write_output(self._port, 1 if self._invert_logic else 0)
self._state = False self._state = False
self.update_ha_state() self.update_ha_state()

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.scsgate
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for SCSGate switches. Support for SCSGate switches.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -16,8 +14,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 switches."""
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
_setup_traditional_switches( _setup_traditional_switches(
@ -32,7 +29,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
def _setup_traditional_switches(logger, config, add_devices_callback): def _setup_traditional_switches(logger, config, add_devices_callback):
""" Add traditional SCSGate switches """ """Add traditional SCSGate switches."""
traditional = config.get('traditional') traditional = config.get('traditional')
switches = [] switches = []
@ -58,7 +55,7 @@ def _setup_traditional_switches(logger, config, add_devices_callback):
def _setup_scenario_switches(logger, config, hass): def _setup_scenario_switches(logger, config, hass):
""" Add only SCSGate scenario switches """ """Add only SCSGate scenario switches."""
scenario = config.get("scenario") scenario = config.get("scenario")
if scenario: if scenario:
@ -81,8 +78,10 @@ def _setup_scenario_switches(logger, config, hass):
class SCSGateSwitch(SwitchDevice): class SCSGateSwitch(SwitchDevice):
""" Provides a SCSGate switch. """ """Representation of a SCSGate switch."""
def __init__(self, scs_id, name, logger): def __init__(self, scs_id, name, logger):
"""Initialize the switch."""
self._name = name self._name = name
self._scs_id = scs_id self._scs_id = scs_id
self._toggled = False self._toggled = False
@ -90,26 +89,26 @@ class SCSGateSwitch(SwitchDevice):
@property @property
def scs_id(self): def scs_id(self):
""" SCS ID """ """Return the SCS ID."""
return self._scs_id return self._scs_id
@property @property
def should_poll(self): def should_poll(self):
""" No polling needed for a SCSGate switch. """ """No polling needed."""
return False return False
@property @property
def name(self): def name(self):
""" Returns the name of the device if any. """ """Return the name of the device if any."""
return self._name return self._name
@property @property
def is_on(self): def is_on(self):
""" True if switch is on. """ """Return true if switch is on."""
return self._toggled return self._toggled
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """Turn the device on."""
from scsgate.tasks import ToggleStatusTask from scsgate.tasks import ToggleStatusTask
scsgate.SCSGATE.append_task( scsgate.SCSGATE.append_task(
@ -121,7 +120,7 @@ class SCSGateSwitch(SwitchDevice):
self.update_ha_state() self.update_ha_state()
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off. """ """Turn the device off."""
from scsgate.tasks import ToggleStatusTask from scsgate.tasks import ToggleStatusTask
scsgate.SCSGATE.append_task( scsgate.SCSGATE.append_task(
@ -133,7 +132,7 @@ class SCSGateSwitch(SwitchDevice):
self.update_ha_state() self.update_ha_state()
def process_event(self, message): def process_event(self, message):
""" Handle a SCSGate message related with this switch""" """Handle a SCSGate message related with this switch."""
if self._toggled == message.toggled: if self._toggled == message.toggled:
self._logger.info( self._logger.info(
"Switch %s, ignoring message %s because state already active", "Switch %s, ignoring message %s because state already active",
@ -157,12 +156,14 @@ class SCSGateSwitch(SwitchDevice):
class SCSGateScenarioSwitch: class SCSGateScenarioSwitch:
""" Provides a SCSGate scenario switch. """Provides a SCSGate scenario switch.
This switch is always in a 'off" state, when toggled This switch is always in a 'off" state, when toggled it's used to trigger
it's used to trigger events events.
""" """
def __init__(self, scs_id, name, logger, hass): def __init__(self, scs_id, name, logger, hass):
"""Initialize the scenario."""
self._name = name self._name = name
self._scs_id = scs_id self._scs_id = scs_id
self._logger = logger self._logger = logger
@ -170,16 +171,16 @@ class SCSGateScenarioSwitch:
@property @property
def scs_id(self): def scs_id(self):
""" SCS ID """ """Return the SCS ID."""
return self._scs_id return self._scs_id
@property @property
def name(self): def name(self):
""" Returns the name of the device if any. """ """Return the name of the device if any."""
return self._name return self._name
def process_event(self, message): def process_event(self, message):
""" Handle a SCSGate message related with this switch""" """Handle a SCSGate message related with this switch."""
from scsgate.messages import StateMessage, ScenarioTriggeredMessage from scsgate.messages import StateMessage, ScenarioTriggeredMessage
if isinstance(message, StateMessage): if isinstance(message, StateMessage):

View file

@ -1,8 +1,7 @@
""" """
homeassistant.components.switch.tellduslive Support for Tellstick switches using Tellstick Net.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Tellstick switches using Tellstick Net and This platform uses the Telldus Live online service.
the Telldus Live online service.
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/switch.tellduslive/ https://home-assistant.io/components/switch.tellduslive/
@ -17,53 +16,56 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Find and return Tellstick switches. """ """Setup Tellstick switches."""
if discovery_info is None: if discovery_info is None:
return return
add_devices(TelldusLiveSwitch(switch) for switch in discovery_info) add_devices(TelldusLiveSwitch(switch) for switch in discovery_info)
class TelldusLiveSwitch(ToggleEntity): class TelldusLiveSwitch(ToggleEntity):
""" Represents a Tellstick switch. """ """Representation of a Tellstick switch."""
def __init__(self, switch_id): def __init__(self, switch_id):
"""Initialize the switch."""
self._id = switch_id self._id = switch_id
self.update() self.update()
_LOGGER.debug("created switch %s", self) _LOGGER.debug("created switch %s", self)
def update(self): def update(self):
"""Get the latest date and update the state."""
tellduslive.NETWORK.update_switches() tellduslive.NETWORK.update_switches()
self._switch = tellduslive.NETWORK.get_switch(self._id) self._switch = tellduslive.NETWORK.get_switch(self._id)
@property @property
def should_poll(self): def should_poll(self):
""" Tells Home Assistant to poll this entity. """ """Polling is needed."""
return True return True
@property @property
def assumed_state(self): def assumed_state(self):
"""Return True if unable to access real state of entity.""" """Return true if unable to access real state of entity."""
return True return True
@property @property
def name(self): def name(self):
""" Returns the name of the switch if any. """ """Return the name of the switch if any."""
return self._switch["name"] return self._switch["name"]
@property @property
def available(self): def available(self):
"""Return the state of the switch."""
return not self._switch.get("offline", False) return not self._switch.get("offline", False)
@property @property
def is_on(self): def is_on(self):
""" True if switch is on. """ """Return true if switch is on."""
from tellive.live import const from tellive.live import const
return self._switch["state"] == const.TELLSTICK_TURNON return self._switch["state"] == const.TELLSTICK_TURNON
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turns the switch on. """ """Turn the switch on."""
tellduslive.NETWORK.turn_switch_on(self._id) tellduslive.NETWORK.turn_switch_on(self._id)
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turns the switch off. """ """Turn the switch off."""
tellduslive.NETWORK.turn_switch_off(self._id) tellduslive.NETWORK.turn_switch_off(self._id)

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.tellstick
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Tellstick switches. Support for Tellstick switches.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -18,26 +16,23 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return Tellstick switches. """ """Setup Tellstick switches."""
import tellcore.telldus as telldus import tellcore.telldus as telldus
import tellcore.constants as tellcore_constants import tellcore.constants as tellcore_constants
from tellcore.library import DirectCallbackDispatcher from tellcore.library import DirectCallbackDispatcher
core = telldus.TelldusCore(callback_dispatcher=DirectCallbackDispatcher()) core = telldus.TelldusCore(callback_dispatcher=DirectCallbackDispatcher())
signal_repetitions = config.get('signal_repetitions', SIGNAL_REPETITIONS) signal_repetitions = config.get('signal_repetitions', SIGNAL_REPETITIONS)
switches_and_lights = core.devices() switches_and_lights = core.devices()
switches = [] switches = []
for switch in switches_and_lights: for switch in switches_and_lights:
if not switch.methods(tellcore_constants.TELLSTICK_DIM): if not switch.methods(tellcore_constants.TELLSTICK_DIM):
switches.append( switches.append(
TellstickSwitchDevice(switch, signal_repetitions)) TellstickSwitchDevice(switch, signal_repetitions))
def _device_event_callback(id_, method, data, cid): def _device_event_callback(id_, method, data, cid):
""" Called from the TelldusCore library to update one device """ """Called from the TelldusCore library to update one device."""
for switch_device in switches: for switch_device in switches:
if switch_device.tellstick_device.id == id_: if switch_device.tellstick_device.id == id_:
switch_device.update_ha_state() switch_device.update_ha_state()
@ -46,7 +41,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
callback_id = core.register_device_event(_device_event_callback) callback_id = core.register_device_event(_device_event_callback)
def unload_telldus_lib(event): def unload_telldus_lib(event):
""" Un-register the callback bindings """ """Un-register the callback bindings."""
if callback_id is not None: if callback_id is not None:
core.unregister_callback(callback_id) core.unregister_callback(callback_id)
@ -56,9 +51,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class TellstickSwitchDevice(ToggleEntity): class TellstickSwitchDevice(ToggleEntity):
""" Represents a Tellstick switch. """ """Representation of a Tellstick switch."""
def __init__(self, tellstick_device, signal_repetitions): def __init__(self, tellstick_device, signal_repetitions):
"""Initialize the Tellstick switch."""
import tellcore.constants as tellcore_constants import tellcore.constants as tellcore_constants
self.tellstick_device = tellstick_device self.tellstick_device = tellstick_device
@ -69,22 +65,22 @@ class TellstickSwitchDevice(ToggleEntity):
@property @property
def should_poll(self): def should_poll(self):
""" Tells Home Assistant not to poll this entity. """ """No polling needed."""
return False return False
@property @property
def assumed_state(self): def assumed_state(self):
""" Tellstick devices are always assumed state """ """The Tellstick devices are always assumed state."""
return True return True
@property @property
def name(self): def name(self):
""" Returns the name of the switch if any. """ """Return the name of the switch if any."""
return self.tellstick_device.name return self.tellstick_device.name
@property @property
def is_on(self): def is_on(self):
""" True if switch is on. """ """Return true if switch is on."""
import tellcore.constants as tellcore_constants import tellcore.constants as tellcore_constants
last_command = self.tellstick_device.last_sent_command( last_command = self.tellstick_device.last_sent_command(
@ -93,13 +89,13 @@ class TellstickSwitchDevice(ToggleEntity):
return last_command == tellcore_constants.TELLSTICK_TURNON return last_command == tellcore_constants.TELLSTICK_TURNON
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turns the switch on. """ """Turn the switch on."""
for _ in range(self.signal_repetitions): for _ in range(self.signal_repetitions):
self.tellstick_device.turn_on() self.tellstick_device.turn_on()
self.update_ha_state() self.update_ha_state()
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turns the switch off. """ """Turn the switch off."""
for _ in range(self.signal_repetitions): for _ in range(self.signal_repetitions):
self.tellstick_device.turn_off() self.tellstick_device.turn_off()
self.update_ha_state() self.update_ha_state()

View file

@ -30,8 +30,7 @@ OFF_ACTION = 'turn_off'
# 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 the Template switch.""" """Setup the Template switch."""
switches = [] switches = []
if config.get(CONF_SWITCHES) is None: if config.get(CONF_SWITCHES) is None:
_LOGGER.error("Missing configuration data for switch platform") _LOGGER.error("Missing configuration data for switch platform")
@ -79,21 +78,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class SwitchTemplate(SwitchDevice): class SwitchTemplate(SwitchDevice):
"""Represents a Template switch.""" """Representation of a Template switch."""
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def __init__(self, def __init__(self, hass, device_id, friendly_name, state_template,
hass, on_action, off_action):
device_id, """Initialize the Template switch."""
friendly_name, self.entity_id = generate_entity_id(ENTITY_ID_FORMAT, device_id,
state_template, hass=hass)
on_action,
off_action):
self.entity_id = generate_entity_id(
ENTITY_ID_FORMAT, device_id,
hass=hass)
self.hass = hass self.hass = hass
self._name = friendly_name self._name = friendly_name
self._template = state_template self._template = state_template
@ -103,14 +95,14 @@ class SwitchTemplate(SwitchDevice):
self.hass.bus.listen(EVENT_STATE_CHANGED, self._event_listener) self.hass.bus.listen(EVENT_STATE_CHANGED, self._event_listener)
def _event_listener(self, event): def _event_listener(self, event):
""" Called when the target device changes state. """ """Called when the target device changes state."""
if not hasattr(self, 'hass'): if not hasattr(self, 'hass'):
return return
self.update_ha_state(True) self.update_ha_state(True)
@property @property
def name(self): def name(self):
"""Returns the name of the switch.""" """Return the name of the switch."""
return self._name return self._name
@property @property
@ -119,30 +111,30 @@ class SwitchTemplate(SwitchDevice):
return False return False
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
"""Fires the on action.""" """Fire the on action."""
call_from_config(self.hass, self._on_action, True) call_from_config(self.hass, self._on_action, True)
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
"""Fires the off action.""" """Fire the off action."""
call_from_config(self.hass, self._off_action, True) call_from_config(self.hass, self._off_action, True)
@property @property
def is_on(self): def is_on(self):
"""True if device is on.""" """Return true if device is on."""
return self._value.lower() == 'true' or self._value == STATE_ON return self._value.lower() == 'true' or self._value == STATE_ON
@property @property
def is_off(self): def is_off(self):
"""True if device is off.""" """Return true if device is off."""
return self._value.lower() == 'false' or self._value == STATE_OFF return self._value.lower() == 'false' or self._value == STATE_OFF
@property @property
def available(self): def available(self):
"""Return True if entity is available.""" """Return true if entity is available."""
return self.is_on or self.is_off return self.is_on or self.is_off
def update(self): def update(self):
"""Updates the state from the template.""" """Update the state from the template."""
try: try:
self._value = template.render(self.hass, self._template) self._value = template.render(self.hass, self._template)
if not self.available: if not self.available:

View file

@ -1,7 +1,5 @@
""" """
homeassistant.components.switch.transmission Support for setting the Transmission BitTorrent client Turtle Mode.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enable or disable Transmission BitTorrent client Turtle Mode.
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/switch.transmission/ https://home-assistant.io/components/switch.transmission/
@ -18,7 +16,7 @@ REQUIREMENTS = ['transmissionrpc==0.11']
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Sets up the transmission sensor. """ """Setup the transmission sensor."""
import transmissionrpc import transmissionrpc
from transmissionrpc.error import TransmissionError from transmissionrpc.error import TransmissionError
@ -49,49 +47,48 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class TransmissionSwitch(ToggleEntity): class TransmissionSwitch(ToggleEntity):
""" A Transmission sensor. """ """Representation of a Transmission sensor."""
def __init__(self, transmission_client, name): def __init__(self, transmission_client, name):
"""Initialize the Transmission switch."""
self._name = name self._name = name
self.transmission_client = transmission_client self.transmission_client = transmission_client
self._state = STATE_OFF self._state = STATE_OFF
@property @property
def name(self): def name(self):
"""Return the name of the switch."""
return self._name return self._name
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Return the state of the device."""
return self._state return self._state
@property @property
def should_poll(self): def should_poll(self):
""" Poll for status regularly. """ """Poll for status regularly."""
return True return True
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """Return true if device is on."""
return self._state == STATE_ON return self._state == STATE_ON
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """Turn the device on."""
_LOGGING.info("Turning on Turtle Mode") _LOGGING.info("Turning on Turtle Mode")
self.transmission_client.set_session( self.transmission_client.set_session(
alt_speed_enabled=True) alt_speed_enabled=True)
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off. """ """Turn the device off."""
_LOGGING.info("Turning off Turtle Mode ") _LOGGING.info("Turning off Turtle Mode ")
self.transmission_client.set_session( self.transmission_client.set_session(
alt_speed_enabled=False) alt_speed_enabled=False)
def update(self): def update(self):
""" Gets the latest data from Transmission and updates the state. """ """Get the latest data from Transmission and updates the state."""
active = self.transmission_client.get_session( active = self.transmission_client.get_session(
).alt_speed_enabled ).alt_speed_enabled
self._state = STATE_ON if active else STATE_OFF self._state = STATE_ON if active else STATE_OFF

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.vera
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Vera switches. Support for Vera switches.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -23,7 +21,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument # pylint: disable=unused-argument
def get_devices(hass, config): def get_devices(hass, config):
""" Find and return Vera switches. """ """Find and return Vera switches."""
import pyvera as veraApi import pyvera as veraApi
base_url = config.get('vera_controller_url') base_url = config.get('vera_controller_url')
@ -40,7 +38,7 @@ def get_devices(hass, config):
if created: if created:
def stop_subscription(event): def stop_subscription(event):
""" Shutdown Vera subscriptions and subscription thread on exit""" """Shutdown Vera subscriptions and subscription thread on exit."""
_LOGGER.info("Shutting down subscriptions.") _LOGGER.info("Shutting down subscriptions.")
vera_controller.stop() vera_controller.stop()
@ -68,14 +66,15 @@ def get_devices(hass, config):
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Find and return Vera lights. """ """Find and return Vera lights."""
add_devices(get_devices(hass, config)) add_devices(get_devices(hass, config))
class VeraSwitch(SwitchDevice): class VeraSwitch(SwitchDevice):
""" Represents a Vera Switch. """ """Representation of a Vera Switch."""
def __init__(self, vera_device, controller, extra_data=None): def __init__(self, vera_device, controller, extra_data=None):
"""Initialize the Vera device."""
self.vera_device = vera_device self.vera_device = vera_device
self.extra_data = extra_data self.extra_data = extra_data
self.controller = controller self.controller = controller
@ -93,11 +92,12 @@ class VeraSwitch(SwitchDevice):
@property @property
def name(self): def name(self):
""" Get the mame of the switch. """ """Return the mame of the switch."""
return self._name return self._name
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes of the device."""
attr = {} attr = {}
if self.vera_device.has_battery: if self.vera_device.has_battery:
@ -123,27 +123,29 @@ class VeraSwitch(SwitchDevice):
return attr return attr
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
"""Turn device on."""
self.vera_device.switch_on() self.vera_device.switch_on()
self._state = STATE_ON self._state = STATE_ON
self.update_ha_state() self.update_ha_state()
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
"""Turn device off."""
self.vera_device.switch_off() self.vera_device.switch_off()
self._state = STATE_OFF self._state = STATE_OFF
self.update_ha_state() self.update_ha_state()
@property @property
def should_poll(self): def should_poll(self):
""" Tells Home Assistant not to poll this entity. """ """No polling needed."""
return False return False
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """Return true if device is on."""
return self._state == STATE_ON return self._state == STATE_ON
def update(self): def update(self):
""" Called by the vera device callback to update state. """ """Called by the vera device callback to update state."""
if self.vera_device.is_switched_on(): if self.vera_device.is_switched_on():
self._state = STATE_ON self._state = STATE_ON
else: else:

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.verisure
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Verisure Smartplugs. Support for Verisure Smartplugs.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -15,7 +13,7 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Verisure platform. """ """Setup the Verisure platform."""
if not int(hub.config.get('smartplugs', '1')): if not int(hub.config.get('smartplugs', '1')):
return False return False
@ -28,31 +26,34 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class VerisureSmartplug(SwitchDevice): class VerisureSmartplug(SwitchDevice):
""" Represents a Verisure smartplug. """ """Representation of a Verisure smartplug."""
def __init__(self, device_id): def __init__(self, device_id):
"""Initialize the Verisure device."""
self._id = device_id self._id = device_id
@property @property
def name(self): def name(self):
""" Get the name (location) of the smartplug. """ """Return the name or location of the smartplug."""
return hub.smartplug_status[self._id].location return hub.smartplug_status[self._id].location
@property @property
def is_on(self): def is_on(self):
""" Returns True if on """ """Return true if on."""
return hub.smartplug_status[self._id].status == 'on' return hub.smartplug_status[self._id].status == 'on'
def turn_on(self): def turn_on(self):
""" Set smartplug status on. """ """Set smartplug status on."""
hub.my_pages.smartplug.set(self._id, 'on') hub.my_pages.smartplug.set(self._id, 'on')
hub.my_pages.smartplug.wait_while_updating(self._id, 'on') hub.my_pages.smartplug.wait_while_updating(self._id, 'on')
self.update() self.update()
def turn_off(self): def turn_off(self):
""" Set smartplug status off. """ """Set smartplug status off."""
hub.my_pages.smartplug.set(self._id, 'off') hub.my_pages.smartplug.set(self._id, 'off')
hub.my_pages.smartplug.wait_while_updating(self._id, 'off') hub.my_pages.smartplug.wait_while_updating(self._id, 'off')
self.update() self.update()
def update(self): def update(self):
"""Get the latest date of the smartplug."""
hub.update_smartplugs() hub.update_smartplugs()

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.wemo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for WeMo switches. Support for WeMo switches.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
@ -34,7 +32,7 @@ WEMO_STANDBY = 8
# pylint: disable=unused-argument, too-many-function-args # pylint: disable=unused-argument, too-many-function-args
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Register discovered WeMo switches.""" """Setup discovered WeMo switches."""
import pywemo.discovery as discovery import pywemo.discovery as discovery
if discovery_info is not None: if discovery_info is not None:
@ -47,8 +45,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class WemoSwitch(SwitchDevice): class WemoSwitch(SwitchDevice):
"""Represents a WeMo switch.""" """Representation of a WeMo switch."""
def __init__(self, device): def __init__(self, device):
"""Initialize the WeMo switch."""
self.wemo = device self.wemo = device
self.insight_params = None self.insight_params = None
self.maker_params = None self.maker_params = None
@ -59,7 +59,7 @@ class WemoSwitch(SwitchDevice):
wemo.SUBSCRIPTION_REGISTRY.on(self.wemo, None, self._update_callback) wemo.SUBSCRIPTION_REGISTRY.on(self.wemo, None, self._update_callback)
def _update_callback(self, _device, _params): def _update_callback(self, _device, _params):
"""Called by the wemo device callback to update state.""" """Called by the Wemo device callback to update state."""
_LOGGER.info( _LOGGER.info(
'Subscription update for %s', 'Subscription update for %s',
_device) _device)
@ -67,21 +67,22 @@ class WemoSwitch(SwitchDevice):
@property @property
def should_poll(self): def should_poll(self):
"""No polling needed with subscriptions""" """No polling needed with subscriptions."""
return False return False
@property @property
def unique_id(self): def unique_id(self):
"""Returns the id of this WeMo switch""" """Return the ID of this WeMo switch."""
return "{}.{}".format(self.__class__, self.wemo.serialnumber) return "{}.{}".format(self.__class__, self.wemo.serialnumber)
@property @property
def name(self): def name(self):
"""Returns the name of the switch if any.""" """Return the name of the switch if any."""
return self.wemo.name return self.wemo.name
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes of the device."""
attr = {} attr = {}
if self.maker_params: if self.maker_params:
# Is the maker sensor on or off. # Is the maker sensor on or off.
@ -105,19 +106,19 @@ class WemoSwitch(SwitchDevice):
@property @property
def current_power_mwh(self): def current_power_mwh(self):
"""Current power usage in mwh.""" """Current power usage in mWh."""
if self.insight_params: if self.insight_params:
return self.insight_params['currentpower'] return self.insight_params['currentpower']
@property @property
def today_power_mw(self): def today_power_mw(self):
"""Today total power usage in mw.""" """Today total power usage in mW."""
if self.insight_params: if self.insight_params:
return self.insight_params['todaymw'] return self.insight_params['todaymw']
@property @property
def detail_state(self): def detail_state(self):
"""Is the device on - or in standby.""" """Return the state of the device."""
if self.insight_params: if self.insight_params:
standby_state = int(self.insight_params['state']) standby_state = int(self.insight_params['state'])
if standby_state == WEMO_ON: if standby_state == WEMO_ON:
@ -131,29 +132,27 @@ class WemoSwitch(SwitchDevice):
@property @property
def is_on(self): def is_on(self):
"""True if switch is on. Standby is on!""" """Return true if switch is on. Standby is on."""
return self._state return self._state
@property @property
def available(self): def available(self):
"""True if switch is available.""" """True if switch is available."""
if (self.wemo.model_name == 'Insight' and if (self.wemo.model_name == 'Insight' and self.insight_params is None):
self.insight_params is None):
return False return False
if (self.wemo.model_name == 'Maker' and if (self.wemo.model_name == 'Maker' and self.maker_params is None):
self.maker_params is None):
return False return False
return True return True
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
"""Turns the switch on.""" """Turn the switch on."""
self._state = WEMO_ON self._state = WEMO_ON
self.update_ha_state() self.update_ha_state()
self.wemo.on() self.wemo.on()
def turn_off(self): def turn_off(self):
"""Turns the switch off.""" """Turn the switch off."""
self._state = WEMO_OFF self._state = WEMO_OFF
self.update_ha_state() self.update_ha_state()
self.wemo.off() self.wemo.off()

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.wink
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Wink switches. Support for Wink switches.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -15,7 +13,7 @@ REQUIREMENTS = ['python-wink==0.6.2']
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Wink platform. """ """Setup the Wink platform."""
import pywink import pywink
if discovery_info is None: if discovery_info is None:

View file

@ -1,6 +1,4 @@
""" """
homeassistant.components.switch.zigbee
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Contains functionality to use a ZigBee device as a switch. Contains functionality to use a ZigBee device as a switch.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -14,14 +12,13 @@ DEPENDENCIES = ["zigbee"]
def setup_platform(hass, config, add_entities, discovery_info=None): def setup_platform(hass, config, add_entities, discovery_info=None):
""" Create and add an entity based on the configuration. """ """Create and add an entity based on the configuration."""
add_entities([ add_entities([
ZigBeeSwitch(hass, ZigBeeDigitalOutConfig(config)) ZigBeeSwitch(hass, ZigBeeDigitalOutConfig(config))
]) ])
class ZigBeeSwitch(ZigBeeDigitalOut, SwitchDevice): class ZigBeeSwitch(ZigBeeDigitalOut, SwitchDevice):
""" """Representation of a ZigBee Digital Out device."""
Use multiple inheritance to turn a ZigBeeDigitalOut into a SwitchDevice.
"""
pass pass

View file

@ -1,8 +1,8 @@
""" """
homeassistant.components.switch.zwave
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Zwave platform that handles simple binary switches. Zwave platform that handles simple binary switches.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.zwave/
""" """
# Because we do not compile openzwave on CI # Because we do not compile openzwave on CI
# pylint: disable=import-error # pylint: disable=import-error
@ -14,7 +14,7 @@ from homeassistant.components.zwave import (
# 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):
""" Find and return demo switches. """ """Find and return Z-Wave switches."""
if discovery_info is None or NETWORK is None: if discovery_info is None or NETWORK is None:
return return
@ -33,8 +33,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ZwaveSwitch(ZWaveDeviceEntity, SwitchDevice): class ZwaveSwitch(ZWaveDeviceEntity, SwitchDevice):
""" Provides a zwave switch. """ """Representation of a Z-Wave switch."""
def __init__(self, value): def __init__(self, value):
"""Initialize the Z-Wave switch device."""
from openzwave.network import ZWaveNetwork from openzwave.network import ZWaveNetwork
from pydispatch import dispatcher from pydispatch import dispatcher
@ -45,20 +47,20 @@ class ZwaveSwitch(ZWaveDeviceEntity, SwitchDevice):
self._value_changed, ZWaveNetwork.SIGNAL_VALUE_CHANGED) self._value_changed, ZWaveNetwork.SIGNAL_VALUE_CHANGED)
def _value_changed(self, value): def _value_changed(self, value):
""" Called when a value has changed on the network. """ """Called when a value has changed on the network."""
if self._value.value_id == value.value_id: if self._value.value_id == value.value_id:
self._state = value.data self._state = value.data
self.update_ha_state() self.update_ha_state()
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """Return true if device is on."""
return self._state return self._state
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """Turn the device on."""
self._value.node.set_switch(self._value.value_id, True) self._value.node.set_switch(self._value.value_id, True)
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off. """ """Turn the device off."""
self._value.node.set_switch(self._value.value_id, False) self._value.node.set_switch(self._value.value_id, False)