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.
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):
""" 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
return hass.states.is_state(entity_id, STATE_ON)
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
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
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
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
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
hass.services.call(DOMAIN, SERVICE_TOGGLE, data)
def setup(hass, config):
""" Track states and offer events for switches. """
"""Track states and offer events for switches."""
component = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL, DISCOVERY_PLATFORMS,
GROUP_NAME_ALL_SWITCHES)
component.setup(config)
def handle_switch_service(service):
""" Handles calls to the switch services. """
"""Handle calls to the switch services."""
target_switches = component.extract_from_service(service)
for switch in target_switches:
@ -111,27 +109,27 @@ def setup(hass, config):
class SwitchDevice(ToggleEntity):
""" Represents a switch within Home Assistant. """
# pylint: disable=no-self-use
"""Representation of a switch."""
# pylint: disable=no-self-use
@property
def current_power_mwh(self):
""" Current power usage in mwh. """
"""Return the current power usage in mWh."""
return None
@property
def today_power_mw(self):
""" Today total power usage in mw. """
"""Return the today total power usage in mW."""
return None
@property
def is_standby(self):
""" Is the device in standby. """
"""Return true if device is in standby."""
return None
@property
def state_attributes(self):
""" Returns optional state attributes. """
"""Return the optional state attributes."""
data = {}
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. So far only digital pins are
supported.
Support for switching Arduino pins on and off.
So far only digital pins are supported.
For more details about this platform, please refer to the documentation at
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):
""" Sets up the Arduino platform. """
"""Setup the Arduino platform."""
# Verify that Arduino board is present
if arduino.BOARD is None:
_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):
""" Represents an Arduino switch. """
"""Representation of an Arduino switch."""
def __init__(self, name, pin, pin_type):
"""Initialize the Pin."""
self._pin = pin
self._name = name or DEVICE_DEFAULT_NAME
self.pin_type = pin_type
@ -49,20 +49,20 @@ class ArduinoSwitch(SwitchDevice):
@property
def name(self):
""" Get the name of the pin. """
"""Get the name of the pin."""
return self._name
@property
def is_on(self):
""" Returns True if pin is high/on. """
"""Return true if pin is high/on."""
return self._state
def turn_on(self):
""" Turns the pin to high/on. """
"""Turn the pin to high/on."""
self._state = True
arduino.BOARD.set_digital_out_high(self._pin)
def turn_off(self):
""" Turns the pin to low/off. """
"""Turn the pin to low/off."""
self._state = False
arduino.BOARD.set_digital_out_low(self._pin)

View file

@ -1,8 +1,5 @@
"""
homeassistant.components.switch.arest
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
Support for device running with the aREST RESTful framework.
For more details about this platform, please refer to the documentation at
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):
""" Get the aREST switches. """
"""Setup the aREST switches."""
resource = config.get('resource', None)
try:
@ -54,9 +50,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ArestSwitchBase(SwitchDevice):
""" Implements an aREST switch. """
"""representation of an aREST switch."""
def __init__(self, resource, location, name):
"""Initialize the switch."""
self._resource = resource
self._name = '{} {}'.format(location.title(), name.title()) \
or DEVICE_DEFAULT_NAME
@ -64,19 +61,20 @@ class ArestSwitchBase(SwitchDevice):
@property
def name(self):
""" The name of the switch. """
"""Return the name of the switch."""
return self._name
@property
def is_on(self):
""" True if device is on. """
"""Return true if device is on."""
return self._state
class ArestSwitchFunction(ArestSwitchBase):
""" Implements an aREST switch. Based on functions. """
"""Representation of an aREST switch."""
def __init__(self, resource, location, name, func):
"""Initialize the switch."""
super().__init__(resource, location, name)
self._func = func
@ -96,7 +94,7 @@ class ArestSwitchFunction(ArestSwitchBase):
_LOGGER.error("Response invalid. Is the function name correct.")
def turn_on(self, **kwargs):
""" Turn the device on. """
"""Turn the device on."""
request = requests.get('{}/{}'.format(self._resource, self._func),
timeout=10, params={"params": "1"})
@ -108,7 +106,7 @@ class ArestSwitchFunction(ArestSwitchBase):
self._func, self._resource)
def turn_off(self, **kwargs):
""" Turn the device off. """
"""Turn the device off."""
request = requests.get('{}/{}'.format(self._resource, self._func),
timeout=10, params={"params": "0"})
@ -120,16 +118,17 @@ class ArestSwitchFunction(ArestSwitchBase):
self._func, self._resource)
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,
self._func), timeout=10)
self._state = request.json()['return_value'] != 0
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):
"""Initialize the switch."""
super().__init__(resource, location, name)
self._pin = pin
@ -139,7 +138,7 @@ class ArestSwitchPin(ArestSwitchBase):
_LOGGER.error("Can't set mode. Is device offline?")
def turn_on(self, **kwargs):
""" Turn the device on. """
"""Turn the device on."""
request = requests.get('{}/digital/{}/1'.format(self._resource,
self._pin), timeout=10)
if request.status_code == 200:
@ -149,7 +148,7 @@ class ArestSwitchPin(ArestSwitchBase):
self._pin, self._resource)
def turn_off(self, **kwargs):
""" Turn the device off. """
"""Turn the device off."""
request = requests.get('{}/digital/{}/0'.format(self._resource,
self._pin), timeout=10)
if request.status_code == 200:
@ -159,7 +158,7 @@ class ArestSwitchPin(ArestSwitchBase):
self._pin, self._resource)
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,
self._pin), timeout=10)
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):
"""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
def __init__(self, hass, name, command_on, command_off,
command_state, value_template):
"""Initialize the switch."""
self._hass = hass
self._name = name
self._state = False
@ -84,12 +84,12 @@ class CommandSwitch(SwitchDevice):
@property
def name(self):
"""The name of the switch."""
"""Return the name of the switch."""
return self._name
@property
def is_on(self):
"""True if device is on."""
"""Return true if device is on."""
return self._state
def _query_state(self):

View file

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

View file

@ -1,6 +1,4 @@
"""
homeassistant.components.switch.dlink
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for D-link W215 smart switch.
For more details about this platform, please refer to the documentation at
@ -26,7 +24,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument
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
# 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):
""" Represents an d-link Smart Plug switch. """
"""Representation of a D-link Smart Plug switch."""
def __init__(self, smartplug, name):
"""Initialize the switch."""
self.smartplug = smartplug
self._name = name
@property
def name(self):
""" Returns the name of the Smart Plug, if any. """
"""Return the name of the Smart Plug, if any."""
return self._name
@property
def current_power_watt(self):
""" Current power usage in watt. """
"""Return the current power usage in Watt."""
try:
return float(self.smartplug.current_consumption)
except ValueError:
@ -67,13 +67,13 @@ class SmartPlugSwitch(SwitchDevice):
@property
def is_on(self):
""" True if switch is on. """
"""Return true if switch is on."""
return self.smartplug.state == 'ON'
def turn_on(self, **kwargs):
""" Turns the switch on. """
"""Turn the switch on."""
self.smartplug.state = 'ON'
def turn_off(self):
""" Turns the switch off. """
"""Turn the switch off."""
self.smartplug.state = 'OFF'

View file

@ -1,6 +1,4 @@
"""
homeassistant.components.switch.edimax
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Edimax switches.
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/'
'365301ce3ff26129a7910c501ead09ea625f3700.zip#pyedimax==0.1']
# setup logger
_LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument
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
# pylint: disable=global-statement
@ -45,19 +42,21 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class SmartPlugSwitch(SwitchDevice):
""" Represents an Edimax Smart Plug switch. """
"""Representation an Edimax Smart Plug switch."""
def __init__(self, smartplug, name):
"""Initialize the switch."""
self.smartplug = smartplug
self._name = name
@property
def name(self):
""" Returns the name of the Smart Plug, if any. """
"""Return the name of the Smart Plug, if any."""
return self._name
@property
def current_power_mwh(self):
""" Current power usage in mWh. """
"""Return the current power usage in mWh."""
try:
return float(self.smartplug.now_power) / 1000000.0
except ValueError:
@ -65,7 +64,7 @@ class SmartPlugSwitch(SwitchDevice):
@property
def today_power_mw(self):
""" Today total power usage in mW. """
"""Return the today total power usage in mW."""
try:
return float(self.smartplug.now_energy_day) / 1000.0
except ValueError:
@ -73,13 +72,13 @@ class SmartPlugSwitch(SwitchDevice):
@property
def is_on(self):
""" True if switch is on. """
"""Return true if switch is on."""
return self.smartplug.state == 'ON'
def turn_on(self, **kwargs):
""" Turns the switch on. """
"""Turn the switch on."""
self.smartplug.state = 'ON'
def turn_off(self):
""" Turns the switch off. """
"""Turn the switch off."""
self.smartplug.state = 'OFF'

View file

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

View file

@ -1,6 +1,4 @@
"""
homeassistant.components.switch.isy994
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for ISY994 switches.
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):
""" Sets up the ISY994 platform. """
"""Setup the ISY994 platform."""
# pylint: disable=too-many-locals
logger = logging.getLogger(__name__)
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.')
return False
# import not dimmable nodes and groups
# Import not dimmable nodes and groups
for (path, node) in ISY.nodes:
if not node.dimmable and SENSOR_STRING not in node.name:
if HIDDEN_STRING in path:
node.name += HIDDEN_STRING
devs.append(ISYSwitchDevice(node))
# import ISY doors programs
# Import ISY doors programs
for folder_name, states in (('HA.doors', [STATE_ON, STATE_OFF]),
('HA.switches', [STATE_ON, STATE_OFF])):
try:
@ -61,7 +59,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ISYSwitchDevice(ISYDeviceABC):
""" Represents as ISY light. """
"""Representation of an ISY switch."""
_domain = 'switch'
_dtype = 'binary'
@ -69,21 +67,22 @@ class ISYSwitchDevice(ISYDeviceABC):
class ISYProgramDevice(ISYSwitchDevice):
""" Represents a door that can be manipulated. """
"""Representation of an ISY door."""
_domain = 'switch'
_dtype = 'binary'
def __init__(self, name, node, actions, states):
"""Initialize the switch."""
super().__init__(node)
self._states = states
self._name = name
self.action_node = actions
def turn_on(self, **kwargs):
""" Turns the device on/closes the device. """
"""Turn the device on/close the device."""
self.action_node.runThen()
def turn_off(self, **kwargs):
""" Turns the device off/opens the device. """
"""Turn the device off/open the device."""
self.action_node.runElse()

View file

@ -1,6 +1,4 @@
"""
homeassistant.components.switch.mfi
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Ubiquiti mFi switches.
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
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up mFi sensors. """
"""Setup mFi sensors."""
if not validate_config({DOMAIN: config},
{DOMAIN: ['host',
CONF_USERNAME,
@ -64,47 +61,58 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class MfiSwitch(SwitchDevice):
""" An mFi switch-able device. """
"""Representation of an mFi switch-able device."""
def __init__(self, port):
"""Initialize the mFi device."""
self._port = port
self._target_state = None
@property
def should_poll(self):
"""Polling is needed."""
return True
@property
def unique_id(self):
"""Return the unique ID of the device."""
return self._port.ident
@property
def name(self):
"""Return the name of the device."""
return self._port.label
@property
def is_on(self):
"""Return true if the device is on."""
return self._port.output
def update(self):
"""Get the latest state and update the state."""
self._port.refresh()
if self._target_state is not None:
self._port.data['output'] = float(self._target_state)
self._target_state = None
def turn_on(self):
"""Turn the switch on."""
self._port.control(True)
self._target_state = True
def turn_off(self):
"""Turn the switch off."""
self._port.control(False)
self._target_state = False
@property
def current_power_mwh(self):
"""Return the current power usage in mWh."""
return int(self._port.data.get('active_pwr', 0) * 1000)
@property
def device_state_attributes(self):
"""Return the state attributes fof the device."""
attr = {}
attr['volts'] = round(self._port.data.get('v_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.
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):
""" Read configuration and create Modbus devices. """
"""Read configuration and create Modbus devices."""
switches = []
slave = config.get("slave", None)
if modbus.TYPE == "serial" and not slave:
@ -44,10 +42,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ModbusSwitch(ToggleEntity):
# pylint: disable=too-many-arguments
""" Represents a Modbus switch. """
"""Representation of a Modbus switch."""
# pylint: disable=too-many-arguments
def __init__(self, name, slave, register, bit, coil=False):
"""Initialize the switch."""
self._name = name
self.slave = int(slave) if slave else 1
self.register = int(register)
@ -61,31 +60,31 @@ class ModbusSwitch(ToggleEntity):
@property
def should_poll(self):
"""
We should poll, because slaves are not allowed to initiate
communication on Modbus networks.
"""Poling needed.
Slaves are not allowed to initiate communication on Modbus networks.
"""
return True
@property
def unique_id(self):
""" Returns a unique id. """
"""Return a unique ID."""
return "MODBUS-SWITCH-{}-{}-{}".format(self.slave,
self.register,
self.bit)
@property
def is_on(self):
""" Returns True if switch is on. """
"""Return true if switch is on."""
return self._is_on
@property
def name(self):
""" Get the name of the switch. """
"""Return the name of the switch."""
return self._name
def turn_on(self, **kwargs):
""" Set switch on. """
"""Set switch on."""
if self.register_value is None:
self.update()
@ -98,7 +97,7 @@ class ModbusSwitch(ToggleEntity):
value=val)
def turn_off(self, **kwargs):
""" Set switch off. """
"""Set switch off."""
if self.register_value is None:
self.update()
@ -111,7 +110,7 @@ class ModbusSwitch(ToggleEntity):
value=val)
def update(self):
""" Update the state of the switch. """
"""Update the state of the switch."""
if self._coil:
result = modbus.NETWORK.read_coils(self.register, 1)
self.register_value = result.bits[0]

View file

@ -26,7 +26,6 @@ DEPENDENCIES = ['mqtt']
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Add MQTT switch."""
if config.get('command_topic') is None:
_LOGGER.error("Missing required variable: command_topic")
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
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,
payload_on, payload_off, optimistic, value_template):
"""Initialize the MQTT switch."""
self._state = False
self._hass = hass
self._name = name
@ -86,17 +87,17 @@ class MqttSwitch(SwitchDevice):
@property
def name(self):
"""The name of the switch."""
"""Return the name of the switch."""
return self._name
@property
def is_on(self):
"""True if device is on."""
"""Return true if device is on."""
return self._state
@property
def assumed_state(self):
"""Return True if we do optimistic updates."""
"""Return true if we do optimistic updates."""
return self._optimistic
def turn_on(self, **kwargs):

View file

@ -52,10 +52,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
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
def __init__(
self, gateway, node_id, child_id, name, value_type, child_type):
"""Setup class attributes on instantiation.

View file

@ -1,6 +1,4 @@
"""
homeassistant.components.switch.mystrom
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for myStrom switches.
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):
""" Find and return myStrom switches. """
"""Find and return myStrom switch."""
host = config.get('host')
if host is None:
@ -41,8 +39,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class MyStromSwitch(SwitchDevice):
""" Represents a myStrom switch. """
"""Representation of a myStrom switch."""
def __init__(self, name, resource):
"""Initialize the myStrom switch."""
self._state = False
self._name = name
self._resource = resource
@ -50,21 +50,21 @@ class MyStromSwitch(SwitchDevice):
@property
def name(self):
""" The name of the switch. """
"""Return the name of the switch."""
return self._name
@property
def is_on(self):
""" True if switch is on. """
"""Return true if switch is on."""
return self._state
@property
def current_power_mwh(self):
""" Current power consumption in mwh. """
"""Return the urrent power consumption in mWh."""
return self.consumption
def turn_on(self, **kwargs):
""" Turn the switch on. """
"""Turn the switch on."""
try:
request = requests.get('{}/relay'.format(self._resource),
params={'state': '1'},
@ -76,7 +76,7 @@ class MyStromSwitch(SwitchDevice):
self._resource)
def turn_off(self, **kwargs):
""" Turn the switch off. """
"""Turn the switch off."""
try:
request = requests.get('{}/relay'.format(self._resource),
params={'state': '0'},
@ -88,7 +88,7 @@ class MyStromSwitch(SwitchDevice):
self._resource)
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:
request = requests.get('{}/report'.format(self._resource),
timeout=10)

View file

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

View file

@ -1,7 +1,5 @@
"""
homeassistant.components.switch.rest
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to configure a REST switch.
Support for RESTful switches.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.rest/
@ -21,8 +19,7 @@ DEFAULT_BODY_OFF = "OFF"
# pylint: disable=unused-argument,
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Get REST switch. """
"""Setup the REST switch."""
resource = config.get('resource')
if resource is None:
@ -49,8 +46,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
# pylint: disable=too-many-arguments
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):
"""Initialize the REST switch."""
self._state = None
self._hass = hass
self._name = name
@ -60,16 +59,16 @@ class RestSwitch(SwitchDevice):
@property
def name(self):
""" The name of the switch. """
"""The name of the switch."""
return self._name
@property
def is_on(self):
""" True if device is on. """
"""return true if device is on."""
return self._state
def turn_on(self, **kwargs):
""" Turn the device on. """
"""Turn the device on."""
request = requests.post(self._resource,
data=self._body_on,
timeout=10)
@ -80,7 +79,7 @@ class RestSwitch(SwitchDevice):
self._resource)
def turn_off(self, **kwargs):
""" Turn the device off. """
"""Turn the device off."""
request = requests.post(self._resource,
data=self._body_off,
timeout=10)
@ -91,7 +90,7 @@ class RestSwitch(SwitchDevice):
self._resource)
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)
if request.text == self._body_on:
self._state = True

View file

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

View file

@ -1,6 +1,4 @@
"""
homeassistant.components.switch.rpi_gpio
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to configure a switch using RPi GPIO.
For more details about this platform, please refer to the documentation at
@ -21,8 +19,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument
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)
switches = []
@ -33,8 +30,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
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):
"""Initialize the pin."""
self._name = name or DEVICE_DEFAULT_NAME
self._port = port
self._invert_logic = invert_logic
@ -43,27 +42,27 @@ class RPiGPIOSwitch(ToggleEntity):
@property
def name(self):
""" The name of the switch. """
"""Return the name of the switch."""
return self._name
@property
def should_poll(self):
""" No polling needed. """
"""No polling needed."""
return False
@property
def is_on(self):
""" True if device is on. """
"""Return true if device is on."""
return self._state
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)
self._state = True
self.update_ha_state()
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)
self._state = False
self.update_ha_state()

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,4 @@
"""
homeassistant.components.switch.verisure
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Verisure Smartplugs.
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):
""" Sets up the Verisure platform. """
"""Setup the Verisure platform."""
if not int(hub.config.get('smartplugs', '1')):
return False
@ -28,31 +26,34 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class VerisureSmartplug(SwitchDevice):
""" Represents a Verisure smartplug. """
"""Representation of a Verisure smartplug."""
def __init__(self, device_id):
"""Initialize the Verisure device."""
self._id = device_id
@property
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
@property
def is_on(self):
""" Returns True if on """
"""Return true if on."""
return hub.smartplug_status[self._id].status == 'on'
def turn_on(self):
""" Set smartplug status on. """
"""Set smartplug status on."""
hub.my_pages.smartplug.set(self._id, 'on')
hub.my_pages.smartplug.wait_while_updating(self._id, 'on')
self.update()
def turn_off(self):
""" Set smartplug status off. """
"""Set smartplug status off."""
hub.my_pages.smartplug.set(self._id, 'off')
hub.my_pages.smartplug.wait_while_updating(self._id, 'off')
self.update()
def update(self):
"""Get the latest date of the smartplug."""
hub.update_smartplugs()

View file

@ -1,6 +1,4 @@
"""
homeassistant.components.switch.wemo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for WeMo switches.
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
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Register discovered WeMo switches."""
"""Setup discovered WeMo switches."""
import pywemo.discovery as discovery
if discovery_info is not None:
@ -47,8 +45,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class WemoSwitch(SwitchDevice):
"""Represents a WeMo switch."""
"""Representation of a WeMo switch."""
def __init__(self, device):
"""Initialize the WeMo switch."""
self.wemo = device
self.insight_params = None
self.maker_params = None
@ -59,7 +59,7 @@ class WemoSwitch(SwitchDevice):
wemo.SUBSCRIPTION_REGISTRY.on(self.wemo, None, self._update_callback)
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(
'Subscription update for %s',
_device)
@ -67,21 +67,22 @@ class WemoSwitch(SwitchDevice):
@property
def should_poll(self):
"""No polling needed with subscriptions"""
"""No polling needed with subscriptions."""
return False
@property
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)
@property
def name(self):
"""Returns the name of the switch if any."""
"""Return the name of the switch if any."""
return self.wemo.name
@property
def device_state_attributes(self):
"""Return the state attributes of the device."""
attr = {}
if self.maker_params:
# Is the maker sensor on or off.
@ -105,19 +106,19 @@ class WemoSwitch(SwitchDevice):
@property
def current_power_mwh(self):
"""Current power usage in mwh."""
"""Current power usage in mWh."""
if self.insight_params:
return self.insight_params['currentpower']
@property
def today_power_mw(self):
"""Today total power usage in mw."""
"""Today total power usage in mW."""
if self.insight_params:
return self.insight_params['todaymw']
@property
def detail_state(self):
"""Is the device on - or in standby."""
"""Return the state of the device."""
if self.insight_params:
standby_state = int(self.insight_params['state'])
if standby_state == WEMO_ON:
@ -131,29 +132,27 @@ class WemoSwitch(SwitchDevice):
@property
def is_on(self):
"""True if switch is on. Standby is on!"""
"""Return true if switch is on. Standby is on."""
return self._state
@property
def available(self):
"""True if switch is available."""
if (self.wemo.model_name == 'Insight' and
self.insight_params is None):
if (self.wemo.model_name == 'Insight' and self.insight_params is None):
return False
if (self.wemo.model_name == 'Maker' and
self.maker_params is None):
if (self.wemo.model_name == 'Maker' and self.maker_params is None):
return False
return True
def turn_on(self, **kwargs):
"""Turns the switch on."""
"""Turn the switch on."""
self._state = WEMO_ON
self.update_ha_state()
self.wemo.on()
def turn_off(self):
"""Turns the switch off."""
"""Turn the switch off."""
self._state = WEMO_OFF
self.update_ha_state()
self.wemo.off()

View file

@ -1,6 +1,4 @@
"""
homeassistant.components.switch.wink
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Wink switches.
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):
""" Sets up the Wink platform. """
"""Setup the Wink platform."""
import pywink
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.
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):
""" Create and add an entity based on the configuration. """
"""Create and add an entity based on the configuration."""
add_entities([
ZigBeeSwitch(hass, ZigBeeDigitalOutConfig(config))
])
class ZigBeeSwitch(ZigBeeDigitalOut, SwitchDevice):
"""
Use multiple inheritance to turn a ZigBeeDigitalOut into a SwitchDevice.
"""
"""Representation of a ZigBee Digital Out device."""
pass

View file

@ -1,8 +1,8 @@
"""
homeassistant.components.switch.zwave
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
# pylint: disable=import-error
@ -14,7 +14,7 @@ from homeassistant.components.zwave import (
# pylint: disable=unused-argument
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:
return
@ -33,8 +33,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ZwaveSwitch(ZWaveDeviceEntity, SwitchDevice):
""" Provides a zwave switch. """
"""Representation of a Z-Wave switch."""
def __init__(self, value):
"""Initialize the Z-Wave switch device."""
from openzwave.network import ZWaveNetwork
from pydispatch import dispatcher
@ -45,20 +47,20 @@ class ZwaveSwitch(ZWaveDeviceEntity, SwitchDevice):
self._value_changed, ZWaveNetwork.SIGNAL_VALUE_CHANGED)
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:
self._state = value.data
self.update_ha_state()
@property
def is_on(self):
""" True if device is on. """
"""Return true if device is on."""
return self._state
def turn_on(self, **kwargs):
""" Turn the device on. """
"""Turn the device on."""
self._value.node.set_switch(self._value.value_id, True)
def turn_off(self, **kwargs):
""" Turn the device off. """
"""Turn the device off."""
self._value.node.set_switch(self._value.value_id, False)