Fixes for PEP257 (#11810)

* Fixes for PEP257

* More updates
This commit is contained in:
Fabian Affolter authored and Paulus Schoutsen committed 2018-01-20 22:35:38 -08:00
1 parent 0100f87ff2
commit 47e31dc9ee
143 files changed
+1584 -1761

No files matched your search

+13 -12
View File
@@ -3,21 +3,24 @@ Support for ADS switch platform.
For more details about this platform, please refer to the documentation.
https://home-assistant.io/components/switch.ads/
"""
import asyncio
import logging
import voluptuous as vol
from homeassistant.components.ads import CONF_ADS_VAR, DATA_ADS
from homeassistant.components.switch import PLATFORM_SCHEMA
from homeassistant.const import CONF_NAME
from homeassistant.components.ads import DATA_ADS, CONF_ADS_VAR
from homeassistant.helpers.entity import ToggleEntity
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import ToggleEntity
_LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['ads']
DEFAULT_NAME = 'ADS Switch'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_ADS_VAR): cv.string,
vol.Optional(CONF_NAME): cv.string,
@@ -49,15 +52,13 @@ class AdsSwitch(ToggleEntity):
"""Register device notification."""
def update(name, value):
"""Handle device notification."""
_LOGGER.debug('Variable %s changed its value to %d',
name, value)
_LOGGER.debug('Variable %s changed its value to %d', name, value)
self._on_state = value
self.schedule_update_ha_state()
self.hass.async_add_job(
self._ads_hub.add_device_notification,
self.ads_var, self._ads_hub.PLCTYPE_BOOL, update
)
self.ads_var, self._ads_hub.PLCTYPE_BOOL, update)
@property
def is_on(self):
@@ -76,10 +77,10 @@ class AdsSwitch(ToggleEntity):
def turn_on(self, **kwargs):
"""Turn the switch on."""
self._ads_hub.write_by_name(self.ads_var, True,
self._ads_hub.PLCTYPE_BOOL)
self._ads_hub.write_by_name(
self.ads_var, True, self._ads_hub.PLCTYPE_BOOL)
def turn_off(self, **kwargs):
"""Turn the switch off."""
self._ads_hub.write_by_name(self.ads_var, False,
self._ads_hub.PLCTYPE_BOOL)
self._ads_hub.write_by_name(
self.ads_var, False, self._ads_hub.PLCTYPE_BOOL)
+17 -12
View File
@@ -4,24 +4,23 @@ Support for Broadlink RM devices.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.broadlink/
"""
from datetime import timedelta
from base64 import b64encode, b64decode
import asyncio
from base64 import b64decode, b64encode
import binascii
from datetime import timedelta
import logging
import socket
import voluptuous as vol
from homeassistant.util.dt import utcnow
from homeassistant.util import Throttle
from homeassistant.components.switch import (
SwitchDevice, DOMAIN, PLATFORM_SCHEMA)
DOMAIN, PLATFORM_SCHEMA, SwitchDevice)
from homeassistant.const import (
CONF_FRIENDLY_NAME, CONF_SWITCHES,
CONF_COMMAND_OFF, CONF_COMMAND_ON,
CONF_TIMEOUT, CONF_HOST, CONF_MAC, CONF_TYPE)
CONF_COMMAND_OFF, CONF_COMMAND_ON, CONF_FRIENDLY_NAME, CONF_HOST, CONF_MAC,
CONF_SWITCHES, CONF_TIMEOUT, CONF_TYPE)
import homeassistant.helpers.config_validation as cv
from homeassistant.util import Throttle
from homeassistant.util.dt import utcnow
REQUIREMENTS = ['broadlink==0.5']
@@ -41,7 +40,7 @@ RM_TYPES = ['rm', 'rm2', 'rm_mini', 'rm_pro_phicomm', 'rm2_home_plus',
'rm2_pro_plus_bl', 'rm_mini_shate']
SP1_TYPES = ['sp1']
SP2_TYPES = ['sp2', 'honeywell_sp2', 'sp3', 'spmini2', 'spminiplus']
MP1_TYPES = ["mp1"]
MP1_TYPES = ['mp1']
SWITCH_TYPES = RM_TYPES + SP1_TYPES + SP2_TYPES + MP1_TYPES
@@ -71,7 +70,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up Broadlink switches."""
"""Set up the Broadlink switches."""
import broadlink
devices = config.get(CONF_SWITCHES)
slots = config.get('slots', {})
@@ -83,6 +82,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
@asyncio.coroutine
def _learn_command(call):
"""Handle a learn command."""
try:
auth = yield from hass.async_add_job(broadlink_device.auth)
except socket.timeout:
@@ -94,7 +94,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
yield from hass.async_add_job(broadlink_device.enter_learning)
_LOGGER.info("Press the key you want HASS to learn")
_LOGGER.info("Press the key you want Home Assistant to learn")
start_time = utcnow()
while (utcnow() - start_time) < timedelta(seconds=20):
packet = yield from hass.async_add_job(
@@ -113,6 +113,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
@asyncio.coroutine
def _send_packet(call):
"""Send a packet."""
packets = call.data.get('packet', [])
for packet in packets:
for retry in range(DEFAULT_RETRY):
@@ -133,6 +134,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
_LOGGER.error("Failed to send packet to device")
def _get_mp1_slot_name(switch_friendly_name, slot):
"""Get slot name."""
if not slots['slot_{}'.format(slot)]:
return '{} slot {}'.format(switch_friendly_name, slot)
return slots['slot_{}'.format(slot)]
@@ -288,6 +290,7 @@ class BroadlinkSP2Switch(BroadlinkSP1Switch):
self._update()
def _update(self, retry=2):
"""Update the state of the device."""
try:
state = self._device.check_power()
except (socket.timeout, ValueError) as error:
@@ -333,7 +336,7 @@ class BroadlinkMP1Slot(BroadlinkRMSwitch):
@property
def should_poll(self):
"""Polling needed."""
"""Return the polling state."""
return True
def update(self):
@@ -360,6 +363,7 @@ class BroadlinkMP1Switch(object):
self._update()
def _update(self, retry=2):
"""Update the state of the device."""
try:
states = self._device.check_power()
except (socket.timeout, ValueError) as error:
@@ -374,6 +378,7 @@ class BroadlinkMP1Switch(object):
self._states = states
def _auth(self, retry=2):
"""Authenticate the device."""
try:
auth = self._device.auth()
except socket.timeout:
+7 -6
View File
@@ -1,10 +1,11 @@
"""Support for powering relays in a DoorBird video doorbell."""
import datetime
import logging
import voluptuous as vol
from homeassistant.components.doorbird import DOMAIN as DOORBIRD_DOMAIN
from homeassistant.components.switch import SwitchDevice, PLATFORM_SCHEMA
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice
from homeassistant.const import CONF_SWITCHES
import homeassistant.helpers.config_validation as cv
@@ -62,12 +63,12 @@ class DoorBirdSwitch(SwitchDevice):
@property
def name(self):
"""Get the name of the switch."""
"""Return the name of the switch."""
return SWITCHES[self._switch]["name"]
@property
def icon(self):
"""Get an icon to display."""
"""Return the icon to display."""
return "mdi:{}".format(SWITCHES[self._switch]["icon"][self._state])
@property
@@ -86,9 +87,9 @@ class DoorBirdSwitch(SwitchDevice):
self._assume_off = now + SWITCHES[self._switch]["time"]
def turn_off(self, **kwargs):
"""The relays are time-based."""
raise NotImplementedError("DoorBird relays cannot be manually turned "
"off.")
"""Turn off the relays is not needed. They are time-based."""
raise NotImplementedError(
"DoorBird relays cannot be manually turned off.")
def update(self):
"""Wait for the correct amount of assumed time to pass."""
+9 -12
View File
@@ -5,9 +5,10 @@ For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.knx/
"""
import asyncio
import voluptuous as vol
from homeassistant.components.knx import DATA_KNX, ATTR_DISCOVER_DEVICES
from homeassistant.components.knx import ATTR_DISCOVER_DEVICES, DATA_KNX
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice
from homeassistant.const import CONF_NAME
from homeassistant.core import callback
@@ -27,20 +28,16 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices,
discovery_info=None):
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
"""Set up switch(es) for KNX platform."""
if DATA_KNX not in hass.data \
or not hass.data[DATA_KNX].initialized:
return False
if DATA_KNX not in hass.data or not hass.data[DATA_KNX].initialized:
return
if discovery_info is not None:
async_add_devices_discovery(hass, discovery_info, async_add_devices)
else:
async_add_devices_config(hass, config, async_add_devices)
return True
@callback
def async_add_devices_discovery(hass, discovery_info, async_add_devices):
@@ -69,7 +66,7 @@ class KNXSwitch(SwitchDevice):
"""Representation of a KNX switch."""
def __init__(self, hass, device):
"""Initialization of KNXSwitch."""
"""Initialize of KNX switch."""
self.device = device
self.hass = hass
self.async_register_callbacks()
@@ -79,7 +76,7 @@ class KNXSwitch(SwitchDevice):
"""Register callbacks to update hass after device was changed."""
@asyncio.coroutine
def after_update_callback(device):
"""Callback after device was updated."""
"""Call after device was updated."""
# pylint: disable=unused-argument
yield from self.async_update_ha_state()
self.device.register_device_updated_cb(after_update_callback)
@@ -91,12 +88,12 @@ class KNXSwitch(SwitchDevice):
@property
def available(self):
"""Return True if entity is available."""
"""Return true if entity is available."""
return self.hass.data[DATA_KNX].connected
@property
def should_poll(self):
"""No polling needed within KNX."""
"""Return the polling state. Not needed within KNX."""
return False
@property
+44 -39
View File
@@ -1,20 +1,27 @@
"""Integration with the Rachio Iro sprinkler system controller."""
import logging
"""
Integration with the Rachio Iro sprinkler system controller.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.rachio/
"""
from datetime import timedelta
import logging
import voluptuous as vol
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice
from homeassistant.const import CONF_ACCESS_TOKEN
import homeassistant.helpers.config_validation as cv
import homeassistant.util as util
from homeassistant.components.switch import SwitchDevice, PLATFORM_SCHEMA
from homeassistant.const import CONF_ACCESS_TOKEN
REQUIREMENTS = ['rachiopy==0.1.2']
_LOGGER = logging.getLogger(__name__)
CONF_MANUAL_RUN_MINS = 'manual_run_mins'
DATA_RACHIO = 'rachio'
CONF_MANUAL_RUN_MINS = 'manual_run_mins'
DEFAULT_MANUAL_RUN_MINS = 10
MIN_UPDATE_INTERVAL = timedelta(seconds=30)
@@ -23,50 +30,49 @@ MIN_FORCED_UPDATE_INTERVAL = timedelta(seconds=1)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_ACCESS_TOKEN): cv.string,
vol.Optional(CONF_MANUAL_RUN_MINS, default=DEFAULT_MANUAL_RUN_MINS):
cv.positive_int
cv.positive_int,
})
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the component."""
"""Set up the Rachio switches."""
from rachiopy import Rachio
# Get options
manual_run_mins = config.get(CONF_MANUAL_RUN_MINS)
_LOGGER.debug("Rachio run time is %d min", manual_run_mins)
# Get access token
_LOGGER.debug("Getting Rachio access token...")
access_token = config.get(CONF_ACCESS_TOKEN)
# Configure API
_LOGGER.debug("Configuring Rachio API...")
from rachiopy import Rachio
_LOGGER.debug("Configuring Rachio API")
rachio = Rachio(access_token)
person = None
try:
person = _get_person(rachio)
except KeyError:
_LOGGER.error("Could not reach the Rachio API. "
"Is your access token valid?")
return False
_LOGGER.error(
"Could not reach the Rachio API. Is your access token valid?")
return
# Get and persist devices
devices = _list_devices(rachio, manual_run_mins)
if not devices:
_LOGGER.error("No Rachio devices found in account " +
person['username'])
return False
_LOGGER.error(
"No Rachio devices found in account %s", person['username'])
return
hass.data[DATA_RACHIO] = devices[0]
if len(devices) > 1:
_LOGGER.warning("Multiple Rachio devices found in account, "
"using " + hass.data[DATA_RACHIO].device_id)
"using %s", hass.data[DATA_RACHIO].device_id)
else:
_LOGGER.info("Found Rachio device")
_LOGGER.debug("Found Rachio device")
hass.data[DATA_RACHIO].update()
add_devices(hass.data[DATA_RACHIO].list_zones())
return True
def _get_person(rachio):
@@ -82,10 +88,10 @@ def _list_devices(rachio, manual_run_mins):
class RachioIro(object):
"""Represents one Rachio Iro."""
"""Representation of a Rachio Iro."""
def __init__(self, rachio, device_id, manual_run_mins):
"""Initialize a new device."""
"""Initialize a Rachio device."""
self.rachio = rachio
self._device_id = device_id
self.manual_run_mins = manual_run_mins
@@ -95,40 +101,40 @@ class RachioIro(object):
def __str__(self):
"""Display the device as a string."""
return "Rachio Iro " + self.serial_number
return "Rachio Iro {}".format(self.serial_number)
@property
def device_id(self):
"""How the Rachio API refers to the device."""
"""Return the Rachio API device ID."""
return self._device['id']
@property
def status(self):
"""The current status of the device."""
"""Return the current status of the device."""
return self._device['status']
@property
def serial_number(self):
"""The serial number of the device."""
"""Return the serial number of the device."""
return self._device['serialNumber']
@property
def is_paused(self):
"""Whether the device is temporarily disabled."""
"""Return whether the device is temporarily disabled."""
return self._device['paused']
@property
def is_on(self):
"""Whether the device is powered on and connected."""
"""Return whether the device is powered on and connected."""
return self._device['on']
@property
def current_schedule(self):
"""The schedule that the device is running right now."""
"""Return the schedule that the device is running right now."""
return self._running
def list_zones(self, include_disabled=False):
"""A list of the zones connected to the device and their data."""
"""Return alist of the zones connected to the device, incl. data."""
if not self._zones:
self._zones = [RachioZone(self.rachio, self, zone['id'],
self.manual_run_mins)
@@ -155,7 +161,7 @@ class RachioIro(object):
class RachioZone(SwitchDevice):
"""Represents one zone of sprinklers connected to the Rachio Iro."""
"""Representation of one zone of sprinklers connected to the Rachio Iro."""
def __init__(self, rachio, device, zone_id, manual_run_mins):
"""Initialize a new Rachio Zone."""
@@ -167,7 +173,7 @@ class RachioZone(SwitchDevice):
def __str__(self):
"""Display the zone as a string."""
return "Rachio Zone " + self.name
return "Rachio Zone {}".format(self.name)
@property
def zone_id(self):
@@ -176,29 +182,28 @@ class RachioZone(SwitchDevice):
@property
def unique_id(self):
"""Generate a unique string ID for the zone."""
"""Return the unique string ID for the zone."""
return '{iro}-{zone}'.format(
iro=self._device.device_id,
zone=self.zone_id)
iro=self._device.device_id, zone=self.zone_id)
@property
def number(self):
"""The physical connection of the zone pump."""
"""Return the physical connection of the zone pump."""
return self._zone['zoneNumber']
@property
def name(self):
"""The friendly name of the zone."""
"""Return the friendly name of the zone."""
return self._zone['name']
@property
def is_enabled(self):
"""Whether the zone is allowed to run."""
"""Return whether the zone is allowed to run."""
return self._zone['enabled']
@property
def is_on(self):
"""Whether the zone is currently running."""
"""Return whether the zone is currently running."""
schedule = self._device.current_schedule
return self.zone_id == schedule.get('zoneId')
+28 -59
View File
@@ -5,18 +5,17 @@ For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.raspihats/
"""
import logging
import voluptuous as vol
from homeassistant.const import (
CONF_NAME, DEVICE_DEFAULT_NAME
)
import homeassistant.helpers.config_validation as cv
from homeassistant.components.switch import PLATFORM_SCHEMA
from homeassistant.helpers.entity import ToggleEntity
from homeassistant.components.raspihats import (
CONF_I2C_HATS, CONF_BOARD, CONF_ADDRESS, CONF_CHANNELS, CONF_INDEX,
CONF_INVERT_LOGIC, CONF_INITIAL_STATE, I2C_HAT_NAMES, I2C_HATS_MANAGER,
I2CHatsException
)
CONF_ADDRESS, CONF_BOARD, CONF_CHANNELS, CONF_I2C_HATS, CONF_INDEX,
CONF_INITIAL_STATE, CONF_INVERT_LOGIC, I2C_HAT_NAMES, I2C_HATS_MANAGER,
I2CHatsException)
from homeassistant.components.switch import PLATFORM_SCHEMA
from homeassistant.const import CONF_NAME, DEVICE_DEFAULT_NAME
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import ToggleEntity
_LOGGER = logging.getLogger(__name__)
@@ -32,7 +31,7 @@ _CHANNELS_SCHEMA = vol.Schema([{
_I2C_HATS_SCHEMA = vol.Schema([{
vol.Required(CONF_BOARD): vol.In(I2C_HAT_NAMES),
vol.Required(CONF_ADDRESS): vol.Coerce(int),
vol.Required(CONF_CHANNELS): _CHANNELS_SCHEMA
vol.Required(CONF_CHANNELS): _CHANNELS_SCHEMA,
}])
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
@@ -42,7 +41,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the raspihats switch devices."""
"""Set up the raspihats switch devices."""
I2CHatSwitch.I2C_HATS_MANAGER = hass.data[I2C_HATS_MANAGER]
switches = []
i2c_hat_configs = config.get(CONF_I2C_HATS)
@@ -54,9 +53,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
for channel_config in i2c_hat_config[CONF_CHANNELS]:
switches.append(
I2CHatSwitch(
board,
address,
channel_config[CONF_INDEX],
board, address, channel_config[CONF_INDEX],
channel_config[CONF_NAME],
channel_config[CONF_INVERT_LOGIC],
channel_config[CONF_INITIAL_STATE]
@@ -64,25 +61,18 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
)
except I2CHatsException as ex:
_LOGGER.error(
"Failed to register " + board + "I2CHat@" + hex(address) + " "
+ str(ex)
)
"Failed to register %s I2CHat@%s %s", board, hex(address),
str(ex))
add_devices(switches)
class I2CHatSwitch(ToggleEntity):
"""Represents a switch that uses a I2C-HAT digital output."""
"""Representation a switch that uses a I2C-HAT digital output."""
I2C_HATS_MANAGER = None
def __init__(
self,
board,
address,
channel,
name,
invert_logic,
initial_state):
def __init__(self, board, address, channel, name, invert_logic,
initial_state):
"""Initialize switch."""
self._board = board
self._address = address
@@ -95,22 +85,17 @@ class I2CHatSwitch(ToggleEntity):
else:
state = initial_state
self.I2C_HATS_MANAGER.write_dq(
self._address,
self._channel,
state
)
self._address, self._channel, state)
def online_callback():
"""Callback fired when board is online."""
"""Call fired when board is online."""
self.schedule_update_ha_state()
self.I2C_HATS_MANAGER.register_online_callback(
self._address,
self._channel,
online_callback
)
self._address, self._channel, online_callback)
def _log_message(self, message):
"""Create log message."""
string = self._name + " "
string += self._board + "I2CHat@" + hex(self._address) + " "
string += "channel:" + str(self._channel) + message
@@ -123,50 +108,34 @@ class I2CHatSwitch(ToggleEntity):
@property
def should_poll(self):
"""Polling not needed."""
"""Return the polling state."""
return False
@property
def is_on(self):
"""Return true if device is on."""
try:
state = self.I2C_HATS_MANAGER.read_dq(
self._address,
self._channel
)
state = self.I2C_HATS_MANAGER.read_dq(self._address, self._channel)
return state != self._invert_logic
except I2CHatsException as ex:
_LOGGER.error(
self._log_message("Is ON check failed, " + str(ex))
)
_LOGGER.error(self._log_message("Is ON check failed, " + str(ex)))
return False
def turn_on(self):
"""Turn the device on."""
try:
state = True if self._invert_logic is False else False
self.I2C_HATS_MANAGER.write_dq(
self._address,
self._channel,
state
)
self.I2C_HATS_MANAGER.write_dq(self._address, self._channel, state)
self.schedule_update_ha_state()
except I2CHatsException as ex:
_LOGGER.error(
self._log_message("Turn ON failed, " + str(ex))
)
_LOGGER.error(self._log_message("Turn ON failed, " + str(ex)))
def turn_off(self):
"""Turn the device off."""
try:
state = False if self._invert_logic is False else True
self.I2C_HATS_MANAGER.write_dq(
self._address,
self._channel,
state
)
self.I2C_HATS_MANAGER.write_dq(self._address, self._channel, state)
self.schedule_update_ha_state()
except I2CHatsException as ex:
_LOGGER.error(
self._log_message("Turn OFF failed, " + str(ex))
)
self._log_message("Turn OFF failed:, " + str(ex)))
+7 -6
View File
@@ -8,11 +8,11 @@ import logging
import voluptuous as vol
from homeassistant.components.switch import PLATFORM_SCHEMA
import homeassistant.components.rpi_pfio as rpi_pfio
from homeassistant.components.switch import PLATFORM_SCHEMA
from homeassistant.const import DEVICE_DEFAULT_NAME
from homeassistant.helpers.entity import ToggleEntity
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import ToggleEntity
_LOGGER = logging.getLogger(__name__)
@@ -20,24 +20,25 @@ DEPENDENCIES = ['rpi_pfio']
ATTR_INVERT_LOGIC = 'invert_logic'
ATTR_NAME = 'name'
CONF_PORTS = 'ports'
DEFAULT_INVERT_LOGIC = False
PORT_SCHEMA = vol.Schema({
vol.Optional(ATTR_NAME, default=None): cv.string,
vol.Optional(ATTR_INVERT_LOGIC, default=DEFAULT_INVERT_LOGIC): cv.boolean
vol.Optional(ATTR_INVERT_LOGIC, default=DEFAULT_INVERT_LOGIC): cv.boolean,
})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_PORTS, default={}): vol.Schema({
cv.positive_int: PORT_SCHEMA
cv.positive_int: PORT_SCHEMA,
})
})
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the PiFace Digital Output devices."""
"""Set up the PiFace Digital Output devices."""
switches = []
ports = config.get(CONF_PORTS)
for port, port_entity in ports.items():
@@ -66,7 +67,7 @@ class RPiPFIOSwitch(ToggleEntity):
@property
def should_poll(self):
"""No polling needed."""
"""Return the polling state."""
return False
@property
+10 -10
View File
@@ -4,17 +4,17 @@ Support for switch controlled using a telnet connection.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.telnet/
"""
from datetime import timedelta
import logging
import telnetlib
from datetime import timedelta
import voluptuous as vol
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA,
ENTITY_ID_FORMAT)
from homeassistant.components.switch import (
ENTITY_ID_FORMAT, PLATFORM_SCHEMA, SwitchDevice)
from homeassistant.const import (
CONF_RESOURCE, CONF_NAME, CONF_SWITCHES, CONF_VALUE_TEMPLATE,
CONF_COMMAND_OFF, CONF_COMMAND_ON, CONF_COMMAND_STATE, CONF_PORT)
CONF_COMMAND_OFF, CONF_COMMAND_ON, CONF_COMMAND_STATE, CONF_NAME,
CONF_PORT, CONF_RESOURCE, CONF_SWITCHES, CONF_VALUE_TEMPLATE)
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
@@ -22,13 +22,13 @@ _LOGGER = logging.getLogger(__name__)
DEFAULT_PORT = 23
SWITCH_SCHEMA = vol.Schema({
vol.Required(CONF_COMMAND_ON): cv.string,
vol.Required(CONF_COMMAND_OFF): cv.string,
vol.Required(CONF_COMMAND_ON): cv.string,
vol.Required(CONF_RESOURCE): cv.string,
vol.Required(CONF_VALUE_TEMPLATE): cv.template,
vol.Optional(CONF_COMMAND_STATE): cv.string,
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Required(CONF_RESOURCE): cv.string,
vol.Required(CONF_VALUE_TEMPLATE): cv.template,
})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
@@ -66,7 +66,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
if not switches:
_LOGGER.error("No switches added")
return False
return
add_devices(switches)
@@ -117,7 +117,7 @@ class TelnetSwitch(SwitchDevice):
@property
def assumed_state(self):
"""Default ist true if no state command is defined, false otherwise."""
"""Return true if no state command is defined, false otherwise."""
return self._command_state is None
def update(self):
+5 -4
View File
@@ -7,8 +7,9 @@ https://home-assistant.io/components/switch.tesla/
import logging
from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchDevice
from homeassistant.components.tesla import DOMAIN as TESLA_DOMAIN, TeslaDevice
from homeassistant.const import STATE_ON, STATE_OFF
from homeassistant.components.tesla import DOMAIN as TESLA_DOMAIN
from homeassistant.components.tesla import TeslaDevice
from homeassistant.const import STATE_OFF, STATE_ON
_LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['tesla']
@@ -25,7 +26,7 @@ class ChargerSwitch(TeslaDevice, SwitchDevice):
"""Representation of a Tesla charger switch."""
def __init__(self, tesla_device, controller):
"""Initialisation of the switch."""
"""Initialise of the switch."""
self._state = None
super().__init__(tesla_device, controller)
self.entity_id = ENTITY_ID_FORMAT.format(self.tesla_id)
@@ -46,7 +47,7 @@ class ChargerSwitch(TeslaDevice, SwitchDevice):
return self._state == STATE_ON
def update(self):
"""Updating state of the switch."""
"""Update the state of the switch."""
_LOGGER.debug("Updating state for: %s", self._name)
self.tesla_device.update()
self._state = STATE_ON if self.tesla_device.is_charging() \
+6 -6
View File
@@ -6,20 +6,20 @@ https://home-assistant.io/components/switch.toon/
"""
import logging
import homeassistant.components.toon as toon_main
from homeassistant.components.switch import SwitchDevice
import homeassistant.components.toon as toon_main
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the discovered Toon Smart Plugs."""
_toon_main = hass.data[toon_main.TOON_HANDLE]
switch_items = []
for plug in _toon_main.toon.smartplugs:
switch_items.append(EnecoSmartPlug(hass, plug))
add_devices_callback(switch_items)
add_devices(switch_items)
class EnecoSmartPlug(SwitchDevice):
@@ -42,12 +42,12 @@ class EnecoSmartPlug(SwitchDevice):
@property
def current_power_w(self):
"""Current power usage in W."""
"""Return the current power usage in W."""
return self.toon_data_store.get_data('current_power', self.name)
@property
def today_energy_kwh(self):
"""Today total energy usage in kWh."""
"""Return the today total energy usage in kWh."""
return self.toon_data_store.get_data('today_energy', self.name)
@property
@@ -57,7 +57,7 @@ class EnecoSmartPlug(SwitchDevice):
@property
def available(self):
"""True if switch is available."""
"""Return true if switch is available."""
return self.smartplug.can_toggle
def turn_on(self, **kwargs):
+1 -1
View File
@@ -24,7 +24,7 @@ DEPENDENCIES = ['vultr']
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_SUBSCRIPTION): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})
+2 -2
View File
@@ -7,7 +7,7 @@ https://home-assistant.io/components/switch.wink/
import asyncio
import logging
from homeassistant.components.wink import WinkDevice, DOMAIN
from homeassistant.components.wink import DOMAIN, WinkDevice
from homeassistant.helpers.entity import ToggleEntity
DEPENDENCIES = ['wink']
@@ -42,7 +42,7 @@ class WinkToggleDevice(WinkDevice, ToggleEntity):
@asyncio.coroutine
def async_added_to_hass(self):
"""Callback when entity is added to hass."""
"""Call when entity is added to hass."""
self.hass.data[DOMAIN]['entities']['switch'].append(self)
@property