mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Update docstrings
This commit is contained in:
parent
635369ad65
commit
b19fbd8e72
@ -1,6 +1,6 @@
|
|||||||
"""
|
"""
|
||||||
homeassistant.components.scsgate
|
homeassistant.components.scsgate
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
Provides support for SCSGate components.
|
Provides support for SCSGate components.
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
For more details about this component, please refer to the documentation at
|
||||||
@ -11,16 +11,13 @@ from threading import Lock
|
|||||||
from homeassistant.core import EVENT_HOMEASSISTANT_STOP
|
from homeassistant.core import EVENT_HOMEASSISTANT_STOP
|
||||||
|
|
||||||
REQUIREMENTS = ['scsgate==0.1.0']
|
REQUIREMENTS = ['scsgate==0.1.0']
|
||||||
|
|
||||||
|
|
||||||
DOMAIN = "scsgate"
|
DOMAIN = "scsgate"
|
||||||
|
|
||||||
SCSGATE = None
|
SCSGATE = None
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SCSGate:
|
class SCSGate:
|
||||||
""" Class dealing with the SCSGate device via scsgate.Reactor """
|
""" Class dealing with the SCSGate device via scsgate.Reactor. """
|
||||||
|
|
||||||
def __init__(self, device, logger):
|
def __init__(self, device, logger):
|
||||||
self._logger = logger
|
self._logger = logger
|
||||||
@ -40,7 +37,7 @@ class SCSGate:
|
|||||||
handle_message=self.handle_message)
|
handle_message=self.handle_message)
|
||||||
|
|
||||||
def handle_message(self, message):
|
def handle_message(self, message):
|
||||||
""" Method called whenever a message is seen on the bus """
|
""" Method called whenever a message is seen on the bus. """
|
||||||
from scsgate.messages import StateMessage, ScenarioTriggeredMessage
|
from scsgate.messages import StateMessage, ScenarioTriggeredMessage
|
||||||
|
|
||||||
self._logger.debug("Received message {}".format(message))
|
self._logger.debug("Received message {}".format(message))
|
||||||
@ -74,31 +71,30 @@ class SCSGate:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def devices(self):
|
def devices(self):
|
||||||
""" Dictionary with known devices. Key is device ID,
|
"""
|
||||||
value is the device itself """
|
Dictionary with known devices. Key is device ID, value is the device
|
||||||
|
itself.
|
||||||
|
"""
|
||||||
return self._devices
|
return self._devices
|
||||||
|
|
||||||
def add_device(self, device):
|
def add_device(self, device):
|
||||||
""" Adds the specified device to the list of the already registered ones.
|
"""
|
||||||
|
Adds the specified device to the list of the already registered ones.
|
||||||
|
|
||||||
Beware: this is not what you usually want to do, take
|
Beware: this is not what you usually want to do, take a look at
|
||||||
a look at `add_devices_to_register`
|
`add_devices_to_register`
|
||||||
"""
|
"""
|
||||||
self._devices[device.scs_id] = device
|
self._devices[device.scs_id] = device
|
||||||
|
|
||||||
def add_devices_to_register(self, devices):
|
def add_devices_to_register(self, devices):
|
||||||
""" List of devices to be registered.
|
""" List of devices to be registered. """
|
||||||
|
|
||||||
Arguments:
|
|
||||||
* devices: list of devices to register
|
|
||||||
"""
|
|
||||||
with self._devices_to_register_lock:
|
with self._devices_to_register_lock:
|
||||||
for device in devices:
|
for device in devices:
|
||||||
self._devices_to_register[device.scs_id] = device
|
self._devices_to_register[device.scs_id] = device
|
||||||
self._activate_next_device()
|
self._activate_next_device()
|
||||||
|
|
||||||
def _activate_next_device(self):
|
def _activate_next_device(self):
|
||||||
""" Starts the activation of the 1st device inside of self._devices """
|
""" Starts the activation of the first device. """
|
||||||
from scsgate.tasks import GetStatusTask
|
from scsgate.tasks import GetStatusTask
|
||||||
|
|
||||||
with self._devices_to_register_lock:
|
with self._devices_to_register_lock:
|
||||||
@ -110,11 +106,7 @@ class SCSGate:
|
|||||||
self._reactor.append_task(GetStatusTask(target=device.scs_id))
|
self._reactor.append_task(GetStatusTask(target=device.scs_id))
|
||||||
|
|
||||||
def is_device_registered(self, device_id):
|
def is_device_registered(self, device_id):
|
||||||
""" Checks whether a device is already registered or not
|
""" Checks whether a device is already registered or not. """
|
||||||
|
|
||||||
Arguments:
|
|
||||||
device_id: the ID of the device to look for
|
|
||||||
"""
|
|
||||||
with self._devices_to_register_lock:
|
with self._devices_to_register_lock:
|
||||||
if device_id in self._devices_to_register.keys():
|
if device_id in self._devices_to_register.keys():
|
||||||
return False
|
return False
|
||||||
@ -126,15 +118,15 @@ class SCSGate:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
""" Start the scsgate.Reactor """
|
""" Start the scsgate.Reactor. """
|
||||||
self._reactor.start()
|
self._reactor.start()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
""" Stop the scsgate.Reactor """
|
""" Stop the scsgate.Reactor. """
|
||||||
self._reactor.stop()
|
self._reactor.stop()
|
||||||
|
|
||||||
def append_task(self, task):
|
def append_task(self, task):
|
||||||
""" Registers a new task to be executed """
|
""" Registers a new task to be executed. """
|
||||||
self._reactor.append_task(task)
|
self._reactor.append_task(task)
|
||||||
|
|
||||||
|
|
||||||
@ -152,8 +144,10 @@ def setup(hass, config):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def stop_monitor(event):
|
def stop_monitor(event):
|
||||||
""" Invoked when home-assistant is exiting. Performs the necessary
|
"""
|
||||||
cleanups """
|
Invoked when home-assistant is exiting. Performs the necessary
|
||||||
|
cleanups.
|
||||||
|
"""
|
||||||
_LOGGER.info("Stopping SCSGate monitor thread")
|
_LOGGER.info("Stopping SCSGate monitor thread")
|
||||||
SCSGATE.stop()
|
SCSGATE.stop()
|
||||||
|
|
||||||
|
@ -1,33 +1,11 @@
|
|||||||
"""
|
"""
|
||||||
homeassistant.components.tellduslive
|
homeassistant.components.tellduslive
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
Tellduslive Component.
|
||||||
|
|
||||||
Tellduslive Component
|
For more details about this component, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/tellduslive/
|
||||||
This component adds support for the Telldus Live service.
|
|
||||||
Telldus Live is the online service used with Tellstick Net devices.
|
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
|
||||||
https://home-assistant.io/components/sensor.tellduslive/
|
|
||||||
|
|
||||||
Developer access to the Telldus Live service is neccessary
|
|
||||||
API keys can be aquired from https://api.telldus.com/keys/index
|
|
||||||
|
|
||||||
Tellstick Net devices can be auto discovered using the method described in:
|
|
||||||
https://developer.telldus.com/doxygen/html/TellStickNet.html
|
|
||||||
|
|
||||||
It might be possible to communicate with the Tellstick Net device
|
|
||||||
directly, bypassing the Tellstick Live service.
|
|
||||||
This however is poorly documented and yet not fully supported (?) according to
|
|
||||||
http://developer.telldus.se/ticket/114 and
|
|
||||||
https://developer.telldus.com/doxygen/html/TellStickNet.html
|
|
||||||
|
|
||||||
API requests to certain methods, as described in
|
|
||||||
https://api.telldus.com/explore/sensor/info
|
|
||||||
are limited to one request every 10 minutes
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -38,7 +16,6 @@ from homeassistant.helpers import validate_config
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
EVENT_PLATFORM_DISCOVERED, ATTR_SERVICE, ATTR_DISCOVERED)
|
EVENT_PLATFORM_DISCOVERED, ATTR_SERVICE, ATTR_DISCOVERED)
|
||||||
|
|
||||||
|
|
||||||
DOMAIN = "tellduslive"
|
DOMAIN = "tellduslive"
|
||||||
DISCOVER_SWITCHES = "tellduslive.switches"
|
DISCOVER_SWITCHES = "tellduslive.switches"
|
||||||
DISCOVER_SENSORS = "tellduslive.sensors"
|
DISCOVER_SENSORS = "tellduslive.sensors"
|
||||||
@ -80,7 +57,7 @@ class TelldusLiveData(object):
|
|||||||
self._api = TelldusLive(self._client)
|
self._api = TelldusLive(self._client)
|
||||||
|
|
||||||
def update(self, hass, config):
|
def update(self, hass, config):
|
||||||
""" Send discovery event if component not yet discovered """
|
""" Send discovery event if component not yet discovered. """
|
||||||
self._update_sensors()
|
self._update_sensors()
|
||||||
self._update_switches()
|
self._update_switches()
|
||||||
for component_name, found_devices, discovery_type in \
|
for component_name, found_devices, discovery_type in \
|
||||||
@ -94,7 +71,7 @@ class TelldusLiveData(object):
|
|||||||
ATTR_DISCOVERED: {}})
|
ATTR_DISCOVERED: {}})
|
||||||
|
|
||||||
def _request(self, what, **params):
|
def _request(self, what, **params):
|
||||||
""" Sends a request to the tellstick live API """
|
""" Sends a request to the Tellstick Live API. """
|
||||||
|
|
||||||
from tellive.live import const
|
from tellive.live import const
|
||||||
|
|
||||||
@ -115,12 +92,12 @@ class TelldusLiveData(object):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
def check_request(self, what, **params):
|
def check_request(self, what, **params):
|
||||||
""" Make request, check result if successful """
|
""" Make request, check result if successful. """
|
||||||
response = self._request(what, **params)
|
response = self._request(what, **params)
|
||||||
return response['status'] == "success"
|
return response['status'] == "success"
|
||||||
|
|
||||||
def validate_session(self):
|
def validate_session(self):
|
||||||
""" Make a dummy request to see if the session is valid """
|
""" Make a dummy request to see if the session is valid. """
|
||||||
try:
|
try:
|
||||||
response = self._request("user/profile")
|
response = self._request("user/profile")
|
||||||
return 'email' in response
|
return 'email' in response
|
||||||
@ -129,12 +106,12 @@ class TelldusLiveData(object):
|
|||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def _update_sensors(self):
|
def _update_sensors(self):
|
||||||
""" Get the latest sensor data from Telldus Live """
|
""" Get the latest sensor data from Telldus Live. """
|
||||||
_LOGGER.info("Updating sensors from Telldus Live")
|
_LOGGER.info("Updating sensors from Telldus Live")
|
||||||
self._sensors = self._request("sensors/list")["sensor"]
|
self._sensors = self._request("sensors/list")["sensor"]
|
||||||
|
|
||||||
def _update_switches(self):
|
def _update_switches(self):
|
||||||
""" Get the configured switches from Telldus Live"""
|
""" Get the configured switches from Telldus Live. """
|
||||||
_LOGGER.info("Updating switches from Telldus Live")
|
_LOGGER.info("Updating switches from Telldus Live")
|
||||||
self._switches = self._request("devices/list")["device"]
|
self._switches = self._request("devices/list")["device"]
|
||||||
# filter out any group of switches
|
# filter out any group of switches
|
||||||
@ -142,17 +119,17 @@ class TelldusLiveData(object):
|
|||||||
if switch["type"] == "device"]
|
if switch["type"] == "device"]
|
||||||
|
|
||||||
def get_sensors(self):
|
def get_sensors(self):
|
||||||
""" Get the configured sensors """
|
""" Get the configured sensors. """
|
||||||
self._update_sensors()
|
self._update_sensors()
|
||||||
return self._sensors
|
return self._sensors
|
||||||
|
|
||||||
def get_switches(self):
|
def get_switches(self):
|
||||||
""" Get the configured switches """
|
""" Get the configured switches. """
|
||||||
self._update_switches()
|
self._update_switches()
|
||||||
return self._switches
|
return self._switches
|
||||||
|
|
||||||
def get_sensor_value(self, sensor_id, sensor_name):
|
def get_sensor_value(self, sensor_id, sensor_name):
|
||||||
""" Get the latest (possibly cached) sensor value """
|
""" Get the latest (possibly cached) sensor value. """
|
||||||
self._update_sensors()
|
self._update_sensors()
|
||||||
for component in self._sensors:
|
for component in self._sensors:
|
||||||
if component["id"] == sensor_id:
|
if component["id"] == sensor_id:
|
||||||
@ -163,22 +140,22 @@ class TelldusLiveData(object):
|
|||||||
component["lastUpdated"])
|
component["lastUpdated"])
|
||||||
|
|
||||||
def get_switch_state(self, switch_id):
|
def get_switch_state(self, switch_id):
|
||||||
""" returns state of switch. """
|
""" Returns the state of an switch. """
|
||||||
_LOGGER.info("Updating switch state from Telldus Live")
|
_LOGGER.info("Updating switch state from Telldus Live")
|
||||||
response = self._request("device/info", id=switch_id)["state"]
|
response = self._request("device/info", id=switch_id)["state"]
|
||||||
return int(response)
|
return int(response)
|
||||||
|
|
||||||
def turn_switch_on(self, switch_id):
|
def turn_switch_on(self, switch_id):
|
||||||
""" turn switch off """
|
""" Turn switch off. """
|
||||||
return self.check_request("device/turnOn", id=switch_id)
|
return self.check_request("device/turnOn", id=switch_id)
|
||||||
|
|
||||||
def turn_switch_off(self, switch_id):
|
def turn_switch_off(self, switch_id):
|
||||||
""" turn switch on """
|
""" Turn switch on. """
|
||||||
return self.check_request("device/turnOff", id=switch_id)
|
return self.check_request("device/turnOff", id=switch_id)
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
""" Setup the tellduslive component """
|
""" Setup the Telldus Live component. """
|
||||||
|
|
||||||
# fixme: aquire app key and provide authentication
|
# fixme: aquire app key and provide authentication
|
||||||
# using username + password
|
# using username + password
|
||||||
|
Loading…
x
Reference in New Issue
Block a user