Update docstrings (#13720)
This commit is contained in:
parent
85487612d5
commit
3394916a68
6 changed files with 72 additions and 74 deletions
|
@ -18,30 +18,31 @@ import homeassistant.helpers.config_validation as cv
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_DISTANCE_SENSOR = "distance_sensor"
|
||||
ATTR_DOOR_STATE = "door_state"
|
||||
ATTR_SIGNAL_STRENGTH = "wifi_signal"
|
||||
ATTR_DISTANCE_SENSOR = 'distance_sensor'
|
||||
ATTR_DOOR_STATE = 'door_state'
|
||||
ATTR_SIGNAL_STRENGTH = 'wifi_signal'
|
||||
|
||||
CONF_DEVICEKEY = "device_key"
|
||||
CONF_DEVICE_ID = 'device_id'
|
||||
CONF_DEVICE_KEY = 'device_key'
|
||||
|
||||
DEFAULT_NAME = 'OpenGarage'
|
||||
DEFAULT_PORT = 80
|
||||
|
||||
STATE_CLOSING = "closing"
|
||||
STATE_OFFLINE = "offline"
|
||||
STATE_OPENING = "opening"
|
||||
STATE_STOPPED = "stopped"
|
||||
STATE_CLOSING = 'closing'
|
||||
STATE_OFFLINE = 'offline'
|
||||
STATE_OPENING = 'opening'
|
||||
STATE_STOPPED = 'stopped'
|
||||
|
||||
STATES_MAP = {
|
||||
0: STATE_CLOSED,
|
||||
1: STATE_OPEN
|
||||
1: STATE_OPEN,
|
||||
}
|
||||
|
||||
COVER_SCHEMA = vol.Schema({
|
||||
vol.Required(CONF_DEVICEKEY): cv.string,
|
||||
vol.Required(CONF_DEVICE_KEY): cv.string,
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||
vol.Optional(CONF_NAME): cv.string
|
||||
})
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
|
@ -50,7 +51,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up OpenGarage covers."""
|
||||
"""Set up the OpenGarage covers."""
|
||||
covers = []
|
||||
devices = config.get(CONF_COVERS)
|
||||
|
||||
|
@ -59,8 +60,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
CONF_NAME: device_config.get(CONF_NAME),
|
||||
CONF_HOST: device_config.get(CONF_HOST),
|
||||
CONF_PORT: device_config.get(CONF_PORT),
|
||||
"device_id": device_config.get(CONF_DEVICE, device_id),
|
||||
CONF_DEVICEKEY: device_config.get(CONF_DEVICEKEY)
|
||||
CONF_DEVICE_ID: device_config.get(CONF_DEVICE, device_id),
|
||||
CONF_DEVICE_KEY: device_config.get(CONF_DEVICE_KEY)
|
||||
}
|
||||
|
||||
covers.append(OpenGarageCover(hass, args))
|
||||
|
@ -79,8 +80,8 @@ class OpenGarageCover(CoverDevice):
|
|||
self.hass = hass
|
||||
self._name = args[CONF_NAME]
|
||||
self.device_id = args['device_id']
|
||||
self._devicekey = args[CONF_DEVICEKEY]
|
||||
self._state = STATE_UNKNOWN
|
||||
self._device_key = args[CONF_DEVICE_KEY]
|
||||
self._state = None
|
||||
self._state_before_move = None
|
||||
self.dist = None
|
||||
self.signal = None
|
||||
|
@ -138,8 +139,8 @@ class OpenGarageCover(CoverDevice):
|
|||
try:
|
||||
status = self._get_status()
|
||||
if self._name is None:
|
||||
if status["name"] is not None:
|
||||
self._name = status["name"]
|
||||
if status['name'] is not None:
|
||||
self._name = status['name']
|
||||
state = STATES_MAP.get(status.get('door'), STATE_UNKNOWN)
|
||||
if self._state_before_move is not None:
|
||||
if self._state_before_move != state:
|
||||
|
@ -152,7 +153,7 @@ class OpenGarageCover(CoverDevice):
|
|||
self.signal = status.get('rssi')
|
||||
self.dist = status.get('dist')
|
||||
self._available = True
|
||||
except (requests.exceptions.RequestException) as ex:
|
||||
except requests.exceptions.RequestException as ex:
|
||||
_LOGGER.error("Unable to connect to OpenGarage device: %(reason)s",
|
||||
dict(reason=ex))
|
||||
self._state = STATE_OFFLINE
|
||||
|
@ -166,15 +167,15 @@ class OpenGarageCover(CoverDevice):
|
|||
def _push_button(self):
|
||||
"""Send commands to API."""
|
||||
url = '{}/cc?dkey={}&click=1'.format(
|
||||
self.opengarage_url, self._devicekey)
|
||||
self.opengarage_url, self._device_key)
|
||||
try:
|
||||
response = requests.get(url, timeout=10).json()
|
||||
if response["result"] == 2:
|
||||
_LOGGER.error("Unable to control %s: device_key is incorrect.",
|
||||
if response['result'] == 2:
|
||||
_LOGGER.error("Unable to control %s: Device key is incorrect",
|
||||
self._name)
|
||||
self._state = self._state_before_move
|
||||
self._state_before_move = None
|
||||
except (requests.exceptions.RequestException) as ex:
|
||||
except requests.exceptions.RequestException as ex:
|
||||
_LOGGER.error("Unable to connect to OpenGarage device: %(reason)s",
|
||||
dict(reason=ex))
|
||||
self._state = self._state_before_move
|
||||
|
|
|
@ -16,7 +16,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up Tahoma covers."""
|
||||
"""Set up the Tahoma covers."""
|
||||
controller = hass.data[TAHOMA_DOMAIN]['controller']
|
||||
devices = []
|
||||
for device in hass.data[TAHOMA_DOMAIN]['devices']['cover']:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
"""IHC component.
|
||||
"""
|
||||
Support for IHC devices.
|
||||
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/ihc/
|
||||
|
@ -6,18 +7,18 @@ https://home-assistant.io/components/ihc/
|
|||
import logging
|
||||
import os.path
|
||||
import xml.etree.ElementTree
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.ihc.const import (
|
||||
ATTR_IHC_ID, ATTR_VALUE, CONF_INFO, CONF_AUTOSETUP,
|
||||
CONF_BINARY_SENSOR, CONF_LIGHT, CONF_SENSOR, CONF_SWITCH,
|
||||
CONF_XPATH, CONF_NODE, CONF_DIMMABLE, CONF_INVERTING,
|
||||
SERVICE_SET_RUNTIME_VALUE_BOOL, SERVICE_SET_RUNTIME_VALUE_INT,
|
||||
SERVICE_SET_RUNTIME_VALUE_FLOAT)
|
||||
ATTR_IHC_ID, ATTR_VALUE, CONF_AUTOSETUP, CONF_BINARY_SENSOR, CONF_DIMMABLE,
|
||||
CONF_INFO, CONF_INVERTING, CONF_LIGHT, CONF_NODE, CONF_SENSOR, CONF_SWITCH,
|
||||
CONF_XPATH, SERVICE_SET_RUNTIME_VALUE_BOOL,
|
||||
SERVICE_SET_RUNTIME_VALUE_FLOAT, SERVICE_SET_RUNTIME_VALUE_INT)
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.const import (
|
||||
CONF_URL, CONF_USERNAME, CONF_PASSWORD, CONF_ID, CONF_NAME,
|
||||
CONF_UNIT_OF_MEASUREMENT, CONF_TYPE, TEMP_CELSIUS)
|
||||
CONF_ID, CONF_NAME, CONF_PASSWORD, CONF_TYPE, CONF_UNIT_OF_MEASUREMENT,
|
||||
CONF_URL, CONF_USERNAME, TEMP_CELSIUS)
|
||||
from homeassistant.helpers import discovery
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
@ -36,7 +37,7 @@ CONFIG_SCHEMA = vol.Schema({
|
|||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(CONF_AUTOSETUP, default=True): cv.boolean,
|
||||
vol.Optional(CONF_INFO, default=True): cv.boolean
|
||||
vol.Optional(CONF_INFO, default=True): cv.boolean,
|
||||
}),
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
@ -97,7 +98,7 @@ IHC_PLATFORMS = ('binary_sensor', 'light', 'sensor', 'switch')
|
|||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Setup the IHC component."""
|
||||
"""Set up the IHC component."""
|
||||
from ihcsdk.ihccontroller import IHCController
|
||||
conf = config[DOMAIN]
|
||||
url = conf[CONF_URL]
|
||||
|
@ -106,7 +107,7 @@ def setup(hass, config):
|
|||
ihc_controller = IHCController(url, username, password)
|
||||
|
||||
if not ihc_controller.authenticate():
|
||||
_LOGGER.error("Unable to authenticate on ihc controller.")
|
||||
_LOGGER.error("Unable to authenticate on IHC controller")
|
||||
return False
|
||||
|
||||
if (conf[CONF_AUTOSETUP] and
|
||||
|
@ -125,7 +126,7 @@ def autosetup_ihc_products(hass: HomeAssistantType, config, ihc_controller):
|
|||
"""Auto setup of IHC products from the ihc project file."""
|
||||
project_xml = ihc_controller.get_project()
|
||||
if not project_xml:
|
||||
_LOGGER.error("Unable to read project from ihc controller.")
|
||||
_LOGGER.error("Unable to read project from ICH controller")
|
||||
return False
|
||||
project = xml.etree.ElementTree.fromstring(project_xml)
|
||||
|
||||
|
@ -150,7 +151,7 @@ def autosetup_ihc_products(hass: HomeAssistantType, config, ihc_controller):
|
|||
|
||||
|
||||
def get_discovery_info(component_setup, groups):
|
||||
"""Get discovery info for specified component."""
|
||||
"""Get discovery info for specified IHC component."""
|
||||
discovery_data = {}
|
||||
for group in groups:
|
||||
groupname = group.attrib['name']
|
||||
|
@ -173,7 +174,7 @@ def get_discovery_info(component_setup, groups):
|
|||
|
||||
|
||||
def setup_service_functions(hass: HomeAssistantType, ihc_controller):
|
||||
"""Setup the ihc service functions."""
|
||||
"""Setup the IHC service functions."""
|
||||
def set_runtime_value_bool(call):
|
||||
"""Set a IHC runtime bool value service function."""
|
||||
ihc_id = call.data[ATTR_IHC_ID]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""Implements a base class for all IHC devices."""
|
||||
"""Implementation of a base class for all IHC devices."""
|
||||
import asyncio
|
||||
from xml.etree.ElementTree import Element
|
||||
|
||||
|
@ -6,7 +6,7 @@ from homeassistant.helpers.entity import Entity
|
|||
|
||||
|
||||
class IHCDevice(Entity):
|
||||
"""Base class for all ihc devices.
|
||||
"""Base class for all IHC devices.
|
||||
|
||||
All IHC devices have an associated IHC resource. IHCDevice handled the
|
||||
registration of the IHC controller callback when the IHC resource changes.
|
||||
|
@ -31,13 +31,13 @@ class IHCDevice(Entity):
|
|||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
"""Add callback for ihc changes."""
|
||||
"""Add callback for IHC changes."""
|
||||
self.ihc_controller.add_notify_event(
|
||||
self.ihc_id, self.on_ihc_change, True)
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""No polling needed for ihc devices."""
|
||||
"""No polling needed for IHC devices."""
|
||||
return False
|
||||
|
||||
@property
|
||||
|
@ -58,7 +58,7 @@ class IHCDevice(Entity):
|
|||
}
|
||||
|
||||
def on_ihc_change(self, ihc_id, value):
|
||||
"""Callback when ihc resource changes.
|
||||
"""Callback when IHC resource changes.
|
||||
|
||||
Derived classes must overwrite this to do device specific stuff.
|
||||
"""
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
"""
|
||||
Support for Nanoleaf Aurora platform.
|
||||
|
||||
Based in large parts upon Software-2's ha-aurora and fully
|
||||
reliant on Software-2's nanoleaf-aurora Python Library, see
|
||||
https://github.com/software-2/ha-aurora as well as
|
||||
https://github.com/software-2/nanoleaf
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/light.nanoleaf_aurora/
|
||||
"""
|
||||
|
@ -15,9 +10,9 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_EFFECT, ATTR_HS_COLOR,
|
||||
SUPPORT_EFFECT, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP,
|
||||
SUPPORT_COLOR, PLATFORM_SCHEMA, Light)
|
||||
from homeassistant.const import CONF_HOST, CONF_TOKEN, CONF_NAME
|
||||
PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS, SUPPORT_COLOR, SUPPORT_COLOR_TEMP,
|
||||
SUPPORT_EFFECT, Light)
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_TOKEN
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.util import color as color_util
|
||||
from homeassistant.util.color import \
|
||||
|
@ -25,20 +20,24 @@ from homeassistant.util.color import \
|
|||
|
||||
REQUIREMENTS = ['nanoleaf==0.4.1']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_NAME = 'Aurora'
|
||||
|
||||
ICON = 'mdi:triangle-outline'
|
||||
|
||||
SUPPORT_AURORA = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_EFFECT |
|
||||
SUPPORT_COLOR)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Required(CONF_TOKEN): cv.string,
|
||||
vol.Optional(CONF_NAME, default='Aurora'): cv.string,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
})
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup Nanoleaf Aurora device."""
|
||||
"""Set up the Nanoleaf Aurora device."""
|
||||
import nanoleaf
|
||||
host = config.get(CONF_HOST)
|
||||
name = config.get(CONF_NAME)
|
||||
|
@ -47,8 +46,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
aurora_light.hass_name = name
|
||||
|
||||
if aurora_light.on is None:
|
||||
_LOGGER.error("Could not connect to \
|
||||
Nanoleaf Aurora: %s on %s", name, host)
|
||||
_LOGGER.error(
|
||||
"Could not connect to Nanoleaf Aurora: %s on %s", name, host)
|
||||
return
|
||||
|
||||
add_devices([AuroraLight(aurora_light)], True)
|
||||
|
||||
|
||||
|
@ -56,7 +57,7 @@ class AuroraLight(Light):
|
|||
"""Representation of a Nanoleaf Aurora."""
|
||||
|
||||
def __init__(self, light):
|
||||
"""Initialize an Aurora."""
|
||||
"""Initialize an Aurora light."""
|
||||
self._brightness = None
|
||||
self._color_temp = None
|
||||
self._effect = None
|
||||
|
@ -99,7 +100,7 @@ class AuroraLight(Light):
|
|||
@property
|
||||
def icon(self):
|
||||
"""Return the icon to use in the frontend, if any."""
|
||||
return "mdi:triangle-outline"
|
||||
return ICON
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
|
@ -141,10 +142,7 @@ class AuroraLight(Light):
|
|||
self._light.on = False
|
||||
|
||||
def update(self):
|
||||
"""Fetch new state data for this light.
|
||||
|
||||
This is the only method that should fetch new data for Home Assistant.
|
||||
"""
|
||||
"""Fetch new state data for this light."""
|
||||
self._brightness = self._light.brightness
|
||||
self._color_temp = self._light.color_temperature
|
||||
self._effect = self._light.effect
|
||||
|
|
|
@ -4,17 +4,17 @@ Weather information for air and road temperature, provided by Trafikverket.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.trafikverket_weatherstation/
|
||||
"""
|
||||
from datetime import timedelta
|
||||
import json
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
|
||||
import requests
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
CONF_NAME, ATTR_ATTRIBUTION, TEMP_CELSIUS, CONF_API_KEY, CONF_TYPE)
|
||||
ATTR_ATTRIBUTION, CONF_API_KEY, CONF_NAME, CONF_TYPE, TEMP_CELSIUS)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
|
||||
|
@ -25,6 +25,7 @@ CONF_ATTRIBUTION = "Data provided by Trafikverket API"
|
|||
CONF_STATION = 'station'
|
||||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=300)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
|
@ -36,7 +37,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the sensor platform."""
|
||||
"""Set up the Trafikverket sensor platform."""
|
||||
sensor_name = config.get(CONF_NAME)
|
||||
sensor_api = config.get(CONF_API_KEY)
|
||||
sensor_station = config.get(CONF_STATION)
|
||||
|
@ -47,10 +48,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
|
||||
|
||||
class TrafikverketWeatherStation(Entity):
|
||||
"""Representation of a Sensor."""
|
||||
"""Representation of a Trafikverket sensor."""
|
||||
|
||||
def __init__(self, sensor_name, sensor_api, sensor_station, sensor_type):
|
||||
"""Initialize the sensor."""
|
||||
"""Initialize the Trafikverket sensor."""
|
||||
self._name = sensor_name
|
||||
self._api = sensor_api
|
||||
self._station = sensor_station
|
||||
|
@ -82,10 +83,7 @@ class TrafikverketWeatherStation(Entity):
|
|||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
def update(self):
|
||||
"""Fetch new state data for the sensor.
|
||||
|
||||
This is the only method that should fetch new data for Home Assistant.
|
||||
"""
|
||||
"""Fetch new state data for the sensor."""
|
||||
url = 'http://api.trafikinfo.trafikverket.se/v1.3/data.json'
|
||||
|
||||
if self._type == 'road':
|
||||
|
@ -117,7 +115,7 @@ class TrafikverketWeatherStation(Entity):
|
|||
result = data["RESPONSE"]["RESULT"][0]
|
||||
final = result["WeatherStation"][0]["Measurement"]
|
||||
except KeyError:
|
||||
_LOGGER.error("Incorrect weather station or API key.")
|
||||
_LOGGER.error("Incorrect weather station or API key")
|
||||
return
|
||||
|
||||
# air_vs_road contains "Air" or "Road" depending on user input.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue