Merge 'dev' into mysensors-component-switch

This commit is contained in:
MartinHjelmare 2015-12-05 23:55:36 +01:00
commit 1d141566bd
237 changed files with 7086 additions and 2944 deletions

View File

@ -17,6 +17,9 @@ omit =
homeassistant/components/*/tellstick.py homeassistant/components/*/tellstick.py
homeassistant/components/*/vera.py homeassistant/components/*/vera.py
homeassistant/components/ecobee.py
homeassistant/components/*/ecobee.py
homeassistant/components/verisure.py homeassistant/components/verisure.py
homeassistant/components/*/verisure.py homeassistant/components/*/verisure.py
@ -29,25 +32,29 @@ omit =
homeassistant/components/rfxtrx.py homeassistant/components/rfxtrx.py
homeassistant/components/*/rfxtrx.py homeassistant/components/*/rfxtrx.py
homeassistant/components/ifttt.py homeassistant/components/binary_sensor/arest.py
homeassistant/components/browser.py homeassistant/components/browser.py
homeassistant/components/camera/* homeassistant/components/camera/*
homeassistant/components/device_tracker/actiontec.py homeassistant/components/device_tracker/actiontec.py
homeassistant/components/device_tracker/aruba.py homeassistant/components/device_tracker/aruba.py
homeassistant/components/device_tracker/asuswrt.py homeassistant/components/device_tracker/asuswrt.py
homeassistant/components/device_tracker/ddwrt.py homeassistant/components/device_tracker/ddwrt.py
homeassistant/components/device_tracker/geofancy.py
homeassistant/components/device_tracker/luci.py homeassistant/components/device_tracker/luci.py
homeassistant/components/device_tracker/ubus.py homeassistant/components/device_tracker/ubus.py
homeassistant/components/device_tracker/netgear.py homeassistant/components/device_tracker/netgear.py
homeassistant/components/device_tracker/nmap_tracker.py homeassistant/components/device_tracker/nmap_tracker.py
homeassistant/components/device_tracker/owntracks.py
homeassistant/components/device_tracker/thomson.py homeassistant/components/device_tracker/thomson.py
homeassistant/components/device_tracker/tomato.py homeassistant/components/device_tracker/tomato.py
homeassistant/components/device_tracker/tplink.py homeassistant/components/device_tracker/tplink.py
homeassistant/components/device_tracker/snmp.py homeassistant/components/device_tracker/snmp.py
homeassistant/components/discovery.py homeassistant/components/discovery.py
homeassistant/components/downloader.py homeassistant/components/downloader.py
homeassistant/components/ifttt.py
homeassistant/components/keyboard.py homeassistant/components/keyboard.py
homeassistant/components/light/hue.py homeassistant/components/light/hue.py
homeassistant/components/light/mqtt.py
homeassistant/components/light/limitlessled.py homeassistant/components/light/limitlessled.py
homeassistant/components/light/blinksticklight.py homeassistant/components/light/blinksticklight.py
homeassistant/components/light/hyperion.py homeassistant/components/light/hyperion.py
@ -64,6 +71,7 @@ omit =
homeassistant/components/notify/instapush.py homeassistant/components/notify/instapush.py
homeassistant/components/notify/nma.py homeassistant/components/notify/nma.py
homeassistant/components/notify/pushbullet.py homeassistant/components/notify/pushbullet.py
homeassistant/components/notify/pushetta.py
homeassistant/components/notify/pushover.py homeassistant/components/notify/pushover.py
homeassistant/components/notify/slack.py homeassistant/components/notify/slack.py
homeassistant/components/notify/smtp.py homeassistant/components/notify/smtp.py
@ -93,10 +101,14 @@ omit =
homeassistant/components/switch/command_switch.py homeassistant/components/switch/command_switch.py
homeassistant/components/switch/edimax.py homeassistant/components/switch/edimax.py
homeassistant/components/switch/hikvisioncam.py homeassistant/components/switch/hikvisioncam.py
homeassistant/components/switch/mystrom.py
homeassistant/components/switch/orvibo.py
homeassistant/components/switch/rest.py homeassistant/components/switch/rest.py
homeassistant/components/switch/rpi_gpio.py homeassistant/components/switch/rpi_gpio.py
homeassistant/components/switch/transmission.py homeassistant/components/switch/transmission.py
homeassistant/components/switch/wemo.py homeassistant/components/switch/wemo.py
homeassistant/components/thermostat/homematic.py
homeassistant/components/thermostat/honeywell.py
homeassistant/components/thermostat/nest.py homeassistant/components/thermostat/nest.py
homeassistant/components/thermostat/radiotherm.py homeassistant/components/thermostat/radiotherm.py

View File

@ -2,9 +2,10 @@ sudo: false
language: python language: python
cache: cache:
directories: directories:
- $HOME/virtualenv/python3.4.2/ - $HOME/virtualenv/python$TRAVIS_PYTHON_VERSION/
python: python:
- "3.4" - 3.4.2
- 3.5.0
install: install:
- script/bootstrap_server - script/bootstrap_server
script: script:

View File

@ -1,19 +1,27 @@
FROM python:3-onbuild FROM python:3.4
MAINTAINER Paulus Schoutsen <Paulus@PaulusSchoutsen.nl> MAINTAINER Paulus Schoutsen <Paulus@PaulusSchoutsen.nl>
VOLUME /config VOLUME /config
RUN pip3 install --no-cache-dir -r requirements_all.txt RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# For the nmap tracker # For the nmap tracker
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y --no-install-recommends nmap net-tools && \ apt-get install -y --no-install-recommends nmap net-tools && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY script/build_python_openzwave script/build_python_openzwave
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y cython3 libudev-dev && \ apt-get install -y cython3 libudev-dev && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \ apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
pip3 install "cython<0.23" && \ pip3 install "cython<0.23" && \
script/build_python_openzwave script/build_python_openzwave
COPY requirements_all.txt requirements_all.txt
RUN pip3 install --no-cache-dir -r requirements_all.txt
# Copy source
COPY . .
CMD [ "python", "-m", "homeassistant", "--config", "/config" ] CMD [ "python", "-m", "homeassistant", "--config", "/config" ]

View File

@ -1,4 +1,4 @@
include README.md include README.rst
include LICENSE include LICENSE
graft homeassistant graft homeassistant
prune homeassistant/components/frontend/www_static/home-assistant-polymer prune homeassistant/components/frontend/www_static/home-assistant-polymer

View File

@ -1,38 +0,0 @@
# Home Assistant [![Build Status](https://travis-ci.org/balloob/home-assistant.svg?branch=master)](https://travis-ci.org/balloob/home-assistant) [![Coverage Status](https://img.shields.io/coveralls/balloob/home-assistant.svg)](https://coveralls.io/r/balloob/home-assistant?branch=master) [![Join the chat at https://gitter.im/balloob/home-assistant](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/balloob/home-assistant?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[demo]: https://home-assistant.io/demo/
Home Assistant is a home automation platform running on Python 3. The goal of Home Assistant is to be able to track and control all devices at home and offer a platform for automating control.
To get started:
```bash
python3 -m pip install homeassistant
hass --open-ui
```
Check out [the website](https://home-assistant.io) for [a demo][demo], installation instructions, tutorials and documentation.
[![screenshot-states](https://raw.github.com/balloob/home-assistant/master/docs/screenshots.png)][demo]
Examples of devices it can interface it:
* Monitoring connected devices to a wireless router: [OpenWrt](https://openwrt.org/), [Tomato](http://www.polarcloud.com/tomato), [Netgear](http://netgear.com), [DD-WRT](http://www.dd-wrt.com/site/index), [TPLink](http://www.tp-link.us/), [ASUSWRT](http://event.asus.com/2013/nw/ASUSWRT/) and any SNMP capable Linksys WAP/WRT
* [Philips Hue](http://meethue.com) lights, [WeMo](http://www.belkin.com/us/Products/home-automation/c/wemo-home-automation/) switches, [Edimax](http://www.edimax.com/) switches, [Efergy](https://efergy.com) energy monitoring, and [Tellstick](http://www.telldus.se/products/tellstick) devices and sensors
* [Google Chromecasts](http://www.google.com/intl/en/chrome/devices/chromecast), [Music Player Daemon](http://www.musicpd.org/), [Logitech Squeezebox](https://en.wikipedia.org/wiki/Squeezebox_%28network_music_player%29), [Plex](https://plex.tv/), [Kodi (XBMC)](http://kodi.tv/), iTunes (by way of [itunes-api](https://github.com/maddox/itunes-api)), and Amazon Fire TV (by way of [python-firetv](https://github.com/happyleavesaoc/python-firetv))
* Support for [ISY994](https://www.universal-devices.com/residential/isy994i-series/) (Insteon and X10 devices), [Z-Wave](http://www.z-wave.com/), [Nest Thermostats](https://nest.com/), [RFXtrx](http://www.rfxcom.com/), [Arduino](https://www.arduino.cc/), [Raspberry Pi](https://www.raspberrypi.org/), and [Modbus](http://www.modbus.org/)
* Interaction with [IFTTT](https://ifttt.com/)
* Integrate data from the [Bitcoin](https://bitcoin.org) network, meteorological data from [OpenWeatherMap](http://openweathermap.org/) and [Forecast.io](https://forecast.io/), [Transmission](http://www.transmissionbt.com/), or [SABnzbd](http://sabnzbd.org).
* [See full list of supported devices](https://home-assistant.io/components/)
Built home automation on top of your devices:
* Keep a precise history of every change to the state of your house
* Turn on the lights when people get home after sun set
* Turn on lights slowly during sun set to compensate for less light
* Turn off all lights and devices when everybody leaves the house
* Offers a [REST API](https://home-assistant.io/developers/api.html) and can interface with MQTT for easy integration with other projects like [OwnTracks](http://owntracks.org/)
* Allow sending notifications using [Instapush](https://instapush.im), [Notify My Android (NMA)](http://www.notifymyandroid.com/), [PushBullet](https://www.pushbullet.com/), [PushOver](https://pushover.net/), [Slack](https://slack.com/), [Telegram](https://telegram.org/), and [Jabber (XMPP)](http://xmpp.org)
The system is built modular so support for other devices or actions can be implemented easily. See also the [section on architecture](https://home-assistant.io/developers/architecture.html) and the [section on creating your own components](https://home-assistant.io/developers/creating_components.html).
If you run into issues while using Home Assistant or during development of a component, check the [Home Assistant help section](https://home-assistant.io/help/) how to reach us.

98
README.rst Normal file
View File

@ -0,0 +1,98 @@
Home Assistant |Build Status| |Coverage Status| |Join the chat at https://gitter.im/balloob/home-assistant|
===========================================================================================================
Home Assistant is a home automation platform running on Python 3. The
goal of Home Assistant is to be able to track and control all devices at
home and offer a platform for automating control.
To get started:
.. code:: bash
python3 -m pip install homeassistant
hass --open-ui
Check out `the website <https://home-assistant.io>`__ for `a
demo <https://home-assistant.io/demo/>`__, installation instructions,
tutorials and documentation.
|screenshot-states|
Examples of devices it can interface it:
- Monitoring connected devices to a wireless router:
`OpenWrt <https://openwrt.org/>`__,
`Tomato <http://www.polarcloud.com/tomato>`__,
`Netgear <http://netgear.com>`__,
`DD-WRT <http://www.dd-wrt.com/site/index>`__,
`TPLink <http://www.tp-link.us/>`__,
`ASUSWRT <http://event.asus.com/2013/nw/ASUSWRT/>`__ and any SNMP
capable Linksys WAP/WRT
- `Philips Hue <http://meethue.com>`__ lights,
`WeMo <http://www.belkin.com/us/Products/home-automation/c/wemo-home-automation/>`__
switches, `Edimax <http://www.edimax.com/>`__ switches,
`Efergy <https://efergy.com>`__ energy monitoring, and
`Tellstick <http://www.telldus.se/products/tellstick>`__ devices and
sensors
- `Google
Chromecasts <http://www.google.com/intl/en/chrome/devices/chromecast>`__,
`Music Player Daemon <http://www.musicpd.org/>`__, `Logitech
Squeezebox <https://en.wikipedia.org/wiki/Squeezebox_%28network_music_player%29>`__,
`Plex <https://plex.tv/>`__, `Kodi (XBMC) <http://kodi.tv/>`__,
iTunes (by way of
`itunes-api <https://github.com/maddox/itunes-api>`__), and Amazon
Fire TV (by way of
`python-firetv <https://github.com/happyleavesaoc/python-firetv>`__)
- Support for
`ISY994 <https://www.universal-devices.com/residential/isy994i-series/>`__
(Insteon and X10 devices), `Z-Wave <http://www.z-wave.com/>`__, `Nest
Thermostats <https://nest.com/>`__,
`RFXtrx <http://www.rfxcom.com/>`__,
`Arduino <https://www.arduino.cc/>`__, `Raspberry
Pi <https://www.raspberrypi.org/>`__, and
`Modbus <http://www.modbus.org/>`__
- Interaction with `IFTTT <https://ifttt.com/>`__
- Integrate data from the `Bitcoin <https://bitcoin.org>`__ network,
meteorological data from
`OpenWeatherMap <http://openweathermap.org/>`__ and
`Forecast.io <https://forecast.io/>`__,
`Transmission <http://www.transmissionbt.com/>`__, or
`SABnzbd <http://sabnzbd.org>`__.
- `See full list of supported
devices <https://home-assistant.io/components/>`__
Built home automation on top of your devices:
- Keep a precise history of every change to the state of your house
- Turn on the lights when people get home after sun set
- Turn on lights slowly during sun set to compensate for less light
- Turn off all lights and devices when everybody leaves the house
- Offers a `REST API <https://home-assistant.io/developers/api/>`__
and can interface with MQTT for easy integration with other projects
like `OwnTracks <http://owntracks.org/>`__
- Allow sending notifications using
`Instapush <https://instapush.im>`__, `Notify My Android
(NMA) <http://www.notifymyandroid.com/>`__,
`PushBullet <https://www.pushbullet.com/>`__,
`PushOver <https://pushover.net/>`__, `Slack <https://slack.com/>`__,
`Telegram <https://telegram.org/>`__, and `Jabber
(XMPP) <http://xmpp.org>`__
The system is built modular so support for other devices or actions can
be implemented easily. See also the `section on
architecture <https://home-assistant.io/developers/architecture.html>`__
and the `section on creating your own
components <https://home-assistant.io/developers/creating_components.html>`__.
If you run into issues while using Home Assistant or during development
of a component, check the `Home Assistant help
section <https://home-assistant.io/help/>`__ how to reach us.
.. |Build Status| image:: https://travis-ci.org/balloob/home-assistant.svg?branch=master
:target: https://travis-ci.org/balloob/home-assistant
.. |Coverage Status| image:: https://img.shields.io/coveralls/balloob/home-assistant.svg
:target: https://coveralls.io/r/balloob/home-assistant?branch=master
.. |Join the chat at https://gitter.im/balloob/home-assistant| image:: https://badges.gitter.im/Join%20Chat.svg
:target: https://gitter.im/balloob/home-assistant?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
.. |screenshot-states| image:: https://raw.github.com/balloob/home-assistant/master/docs/screenshots.png
:target: https://home-assistant.io/demo/

View File

@ -9,11 +9,12 @@ After bootstrapping you can add your own components or
start by calling homeassistant.start_home_assistant(bus) start by calling homeassistant.start_home_assistant(bus)
""" """
import os from collections import defaultdict
import sys
import logging import logging
import logging.handlers import logging.handlers
from collections import defaultdict import os
import shutil
import sys
import homeassistant.core as core import homeassistant.core as core
import homeassistant.util.dt as date_util import homeassistant.util.dt as date_util
@ -25,7 +26,7 @@ import homeassistant.components as core_components
import homeassistant.components.group as group import homeassistant.components.group as group
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.const import ( from homeassistant.const import (
EVENT_COMPONENT_LOADED, CONF_LATITUDE, CONF_LONGITUDE, __version__, EVENT_COMPONENT_LOADED, CONF_LATITUDE, CONF_LONGITUDE,
CONF_TEMPERATURE_UNIT, CONF_NAME, CONF_TIME_ZONE, CONF_CUSTOMIZE, CONF_TEMPERATURE_UNIT, CONF_NAME, CONF_TIME_ZONE, CONF_CUSTOMIZE,
TEMP_CELCIUS, TEMP_FAHRENHEIT) TEMP_CELCIUS, TEMP_FAHRENHEIT)
@ -34,6 +35,7 @@ _LOGGER = logging.getLogger(__name__)
ATTR_COMPONENT = 'component' ATTR_COMPONENT = 'component'
PLATFORM_FORMAT = '{}.{}' PLATFORM_FORMAT = '{}.{}'
ERROR_LOG_FILENAME = 'home-assistant.log'
def setup_component(hass, domain, config=None): def setup_component(hass, domain, config=None):
@ -80,7 +82,7 @@ def _setup_component(hass, domain, config):
return True return True
component = loader.get_component(domain) component = loader.get_component(domain)
missing_deps = [dep for dep in component.DEPENDENCIES missing_deps = [dep for dep in getattr(component, 'DEPENDENCIES', [])
if dep not in hass.config.components] if dep not in hass.config.components]
if missing_deps: if missing_deps:
@ -104,7 +106,7 @@ def _setup_component(hass, domain, config):
# Assumption: if a component does not depend on groups # Assumption: if a component does not depend on groups
# it communicates with devices # it communicates with devices
if group.DOMAIN not in component.DEPENDENCIES: if group.DOMAIN not in getattr(component, 'DEPENDENCIES', []):
hass.pool.add_worker() hass.pool.add_worker()
hass.bus.fire( hass.bus.fire(
@ -131,8 +133,7 @@ def prepare_setup_platform(hass, config, domain, platform_name):
return platform return platform
# Load dependencies # Load dependencies
if hasattr(platform, 'DEPENDENCIES'): for component in getattr(platform, 'DEPENDENCIES', []):
for component in platform.DEPENDENCIES:
if not setup_component(hass, component, config): if not setup_component(hass, component, config):
_LOGGER.error( _LOGGER.error(
'Unable to prepare setup for platform %s because ' 'Unable to prepare setup for platform %s because '
@ -167,6 +168,7 @@ def from_config_dict(config, hass=None, config_dir=None, enable_log=True,
hass.config.config_dir = config_dir hass.config.config_dir = config_dir
mount_local_lib_path(config_dir) mount_local_lib_path(config_dir)
process_ha_config_upgrade(hass)
process_ha_core_config(hass, config.get(core.DOMAIN, {})) process_ha_core_config(hass, config.get(core.DOMAIN, {}))
if enable_log: if enable_log:
@ -252,7 +254,7 @@ def enable_logging(hass, verbose=False, daemon=False, log_rotate_days=None):
"Colorlog package not found, console coloring disabled") "Colorlog package not found, console coloring disabled")
# Log errors to a file if we have write access to file or config dir # Log errors to a file if we have write access to file or config dir
err_log_path = hass.config.path('home-assistant.log') err_log_path = hass.config.path(ERROR_LOG_FILENAME)
err_path_exists = os.path.isfile(err_log_path) err_path_exists = os.path.isfile(err_log_path)
# Check if we can write to the error log if it exists or that # Check if we can write to the error log if it exists or that
@ -280,6 +282,31 @@ def enable_logging(hass, verbose=False, daemon=False, log_rotate_days=None):
'Unable to setup error log %s (access denied)', err_log_path) 'Unable to setup error log %s (access denied)', err_log_path)
def process_ha_config_upgrade(hass):
""" Upgrade config if necessary. """
version_path = hass.config.path('.HA_VERSION')
try:
with open(version_path, 'rt') as inp:
conf_version = inp.readline().strip()
except FileNotFoundError:
# Last version to not have this file
conf_version = '0.7.7'
if conf_version == __version__:
return
_LOGGER.info('Upgrading config directory from %s to %s', conf_version,
__version__)
lib_path = hass.config.path('lib')
if os.path.isdir(lib_path):
shutil.rmtree(lib_path)
with open(version_path, 'wt') as outp:
outp.write(__version__)
def process_ha_core_config(hass, config): def process_ha_core_config(hass, config):
""" Processes the [homeassistant] section from the config. """ """ Processes the [homeassistant] section from the config. """
hac = hass.config hac = hass.config

View File

@ -1,7 +1,6 @@
""" """
homeassistant.components homeassistant.components
~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
This package contains components that can be plugged into Home Assistant. This package contains components that can be plugged into Home Assistant.
Component design guidelines: Component design guidelines:
@ -12,7 +11,6 @@ Each component that tracks states should create state entity names in the
format "<DOMAIN>.<OBJECT_ID>". format "<DOMAIN>.<OBJECT_ID>".
Each component should publish services only under its own domain. Each component should publish services only under its own domain.
""" """
import itertools as it import itertools as it
import logging import logging

View File

@ -15,7 +15,6 @@ from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
DOMAIN = 'alarm_control_panel' DOMAIN = 'alarm_control_panel'
DEPENDENCIES = []
SCAN_INTERVAL = 30 SCAN_INTERVAL = 30
ENTITY_ID_FORMAT = DOMAIN + '.{}' ENTITY_ID_FORMAT = DOMAIN + '.{}'

View File

@ -0,0 +1,13 @@
"""
homeassistant.components.alarm_control_panel.demo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo platform that has two fake alarm control panels.
"""
import homeassistant.components.alarm_control_panel.manual as manual
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Demo alarm control panels. """
add_devices([
manual.ManualAlarm(hass, 'Alarm', '1234', 5, 10),
])

View File

@ -4,7 +4,7 @@ homeassistant.components.alarm_control_panel.manual
Support for manual alarms. Support for manual alarms.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/alarm_control_panel.manual.html https://home-assistant.io/components/alarm_control_panel.manual/
""" """
import logging import logging
import datetime import datetime
@ -18,8 +18,6 @@ from homeassistant.const import (
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DEPENDENCIES = []
DEFAULT_ALARM_NAME = 'HA Alarm' DEFAULT_ALARM_NAME = 'HA Alarm'
DEFAULT_PENDING_TIME = 60 DEFAULT_PENDING_TIME = 60
DEFAULT_TRIGGER_TIME = 120 DEFAULT_TRIGGER_TIME = 120

View File

@ -4,7 +4,7 @@ homeassistant.components.alarm_control_panel.mqtt
This platform enables the possibility to control a MQTT alarm. This platform enables the possibility to control a MQTT alarm.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/alarm_control_panel.mqtt.html https://home-assistant.io/components/alarm_control_panel.mqtt/
""" """
import logging import logging
import homeassistant.components.mqtt as mqtt import homeassistant.components.mqtt as mqtt

View File

@ -2,6 +2,9 @@
homeassistant.components.alarm_control_panel.verisure homeassistant.components.alarm_control_panel.verisure
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Interfaces with Verisure alarm control panel. Interfaces with Verisure alarm control panel.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/verisure/
""" """
import logging import logging

View File

@ -4,7 +4,7 @@ homeassistant.components.api
Provides a Rest API for Home Assistant. Provides a Rest API for Home Assistant.
For more details about the RESTful API, please refer to the documentation at For more details about the RESTful API, please refer to the documentation at
https://home-assistant.io/developers/api.html https://home-assistant.io/developers/api/
""" """
import re import re
import logging import logging
@ -14,10 +14,11 @@ import json
import homeassistant.core as ha import homeassistant.core as ha
from homeassistant.helpers.state import TrackStates from homeassistant.helpers.state import TrackStates
import homeassistant.remote as rem import homeassistant.remote as rem
from homeassistant.bootstrap import ERROR_LOG_FILENAME
from homeassistant.const import ( from homeassistant.const import (
URL_API, URL_API_STATES, URL_API_EVENTS, URL_API_SERVICES, URL_API_STREAM, URL_API, URL_API_STATES, URL_API_EVENTS, URL_API_SERVICES, URL_API_STREAM,
URL_API_EVENT_FORWARD, URL_API_STATES_ENTITY, URL_API_COMPONENTS, URL_API_EVENT_FORWARD, URL_API_STATES_ENTITY, URL_API_COMPONENTS,
URL_API_CONFIG, URL_API_BOOTSTRAP, URL_API_CONFIG, URL_API_BOOTSTRAP, URL_API_ERROR_LOG, URL_API_LOG_OUT,
EVENT_TIME_CHANGED, EVENT_HOMEASSISTANT_STOP, MATCH_ALL, EVENT_TIME_CHANGED, EVENT_HOMEASSISTANT_STOP, MATCH_ALL,
HTTP_OK, HTTP_CREATED, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_OK, HTTP_CREATED, HTTP_BAD_REQUEST, HTTP_NOT_FOUND,
HTTP_UNPROCESSABLE_ENTITY) HTTP_UNPROCESSABLE_ENTITY)
@ -35,10 +36,6 @@ _LOGGER = logging.getLogger(__name__)
def setup(hass, config): def setup(hass, config):
""" Register the API with the HTTP interface. """ """ Register the API with the HTTP interface. """
if 'http' not in hass.config.components:
_LOGGER.error('Dependency http is not loaded')
return False
# /api - for validation purposes # /api - for validation purposes
hass.http.register_path('GET', URL_API, _handle_get_api) hass.http.register_path('GET', URL_API, _handle_get_api)
@ -89,6 +86,11 @@ def setup(hass, config):
hass.http.register_path( hass.http.register_path(
'GET', URL_API_COMPONENTS, _handle_get_api_components) 'GET', URL_API_COMPONENTS, _handle_get_api_components)
hass.http.register_path('GET', URL_API_ERROR_LOG,
_handle_get_api_error_log)
hass.http.register_path('POST', URL_API_LOG_OUT, _handle_post_api_log_out)
return True return True
@ -104,6 +106,7 @@ def _handle_get_api_stream(handler, path_match, data):
wfile = handler.wfile wfile = handler.wfile
write_lock = threading.Lock() write_lock = threading.Lock()
block = threading.Event() block = threading.Event()
session_id = None
restrict = data.get('restrict') restrict = data.get('restrict')
if restrict: if restrict:
@ -117,6 +120,7 @@ def _handle_get_api_stream(handler, path_match, data):
try: try:
wfile.write(msg.encode("UTF-8")) wfile.write(msg.encode("UTF-8"))
wfile.flush() wfile.flush()
handler.server.sessions.extend_validation(session_id)
except IOError: except IOError:
block.set() block.set()
@ -136,6 +140,7 @@ def _handle_get_api_stream(handler, path_match, data):
handler.send_response(HTTP_OK) handler.send_response(HTTP_OK)
handler.send_header('Content-type', 'text/event-stream') handler.send_header('Content-type', 'text/event-stream')
session_id = handler.set_session_cookie_header()
handler.end_headers() handler.end_headers()
hass.bus.listen(MATCH_ALL, forward_events) hass.bus.listen(MATCH_ALL, forward_events)
@ -341,6 +346,19 @@ def _handle_get_api_components(handler, path_match, data):
handler.write_json(handler.server.hass.config.components) handler.write_json(handler.server.hass.config.components)
def _handle_get_api_error_log(handler, path_match, data):
""" Returns the logged errors for this session. """
handler.write_file(handler.server.hass.config.path(ERROR_LOG_FILENAME),
False)
def _handle_post_api_log_out(handler, path_match, data):
""" Log user out. """
handler.send_response(HTTP_OK)
handler.destroy_session()
handler.end_headers()
def _services_json(hass): def _services_json(hass):
""" Generate services data to JSONify. """ """ Generate services data to JSONify. """
return [{"domain": key, "services": value} return [{"domain": key, "services": value}

View File

@ -5,7 +5,7 @@ Arduino component that connects to a directly attached Arduino board which
runs with the Firmata firmware. runs with the Firmata firmware.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/arduino.html https://home-assistant.io/components/arduino/
""" """
import logging import logging
@ -19,7 +19,6 @@ from homeassistant.const import (EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP) EVENT_HOMEASSISTANT_STOP)
DOMAIN = "arduino" DOMAIN = "arduino"
DEPENDENCIES = []
REQUIREMENTS = ['PyMata==2.07a'] REQUIREMENTS = ['PyMata==2.07a']
BOARD = None BOARD = None
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View File

@ -1,8 +1,10 @@
""" """
homeassistant.components.automation homeassistant.components.automation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to setup simple automation rules via the config file. Allows to setup simple automation rules via the config file.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/automation/
""" """
import logging import logging
@ -121,7 +123,7 @@ def _migrate_old_config(config):
_LOGGER.warning( _LOGGER.warning(
'You are using an old configuration format. Please upgrade: ' 'You are using an old configuration format. Please upgrade: '
'https://home-assistant.io/components/automation.html') 'https://home-assistant.io/components/automation/')
new_conf = { new_conf = {
CONF_TRIGGER: dict(config), CONF_TRIGGER: dict(config),

View File

@ -4,7 +4,7 @@ homeassistant.components.automation.event
Offers event listening automation rules. Offers event listening automation rules.
For more details about this automation rule, please refer to the documentation For more details about this automation rule, please refer to the documentation
at https://home-assistant.io/components/automation.html#event-trigger at https://home-assistant.io/components/automation/#event-trigger
""" """
import logging import logging

View File

@ -4,7 +4,7 @@ homeassistant.components.automation.mqtt
Offers MQTT listening automation rules. Offers MQTT listening automation rules.
For more details about this automation rule, please refer to the documentation For more details about this automation rule, please refer to the documentation
at https://home-assistant.io/components/automation.html#mqtt-trigger at https://home-assistant.io/components/automation/#mqtt-trigger
""" """
import logging import logging

View File

@ -1,10 +1,10 @@
""" """
homeassistant.components.automation.numeric_state homeassistant.components.automation.numeric_state
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Offers numeric state listening automation rules. Offers numeric state listening automation rules.
For more details about this automation rule, please refer to the documentation For more details about this automation rule, please refer to the documentation
at https://home-assistant.io/components/automation.html#numeric-state-trigger at https://home-assistant.io/components/automation/#numeric-state-trigger
""" """
import logging import logging
@ -14,6 +14,7 @@ from homeassistant.helpers.event import track_state_change
CONF_ENTITY_ID = "entity_id" CONF_ENTITY_ID = "entity_id"
CONF_BELOW = "below" CONF_BELOW = "below"
CONF_ABOVE = "above" CONF_ABOVE = "above"
CONF_ATTRIBUTE = "attribute"
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -28,6 +29,7 @@ def trigger(hass, config, action):
below = config.get(CONF_BELOW) below = config.get(CONF_BELOW)
above = config.get(CONF_ABOVE) above = config.get(CONF_ABOVE)
attribute = config.get(CONF_ATTRIBUTE)
if below is None and above is None: if below is None and above is None:
_LOGGER.error("Missing configuration key." _LOGGER.error("Missing configuration key."
@ -40,8 +42,8 @@ def trigger(hass, config, action):
""" Listens for state changes and calls action. """ """ Listens for state changes and calls action. """
# Fire action if we go from outside range into range # Fire action if we go from outside range into range
if _in_range(to_s.state, above, below) and \ if _in_range(to_s, above, below, attribute) and \
(from_s is None or not _in_range(from_s.state, above, below)): (from_s is None or not _in_range(from_s, above, below, attribute)):
action() action()
track_state_change( track_state_change(
@ -61,6 +63,7 @@ def if_action(hass, config):
below = config.get(CONF_BELOW) below = config.get(CONF_BELOW)
above = config.get(CONF_ABOVE) above = config.get(CONF_ABOVE)
attribute = config.get(CONF_ATTRIBUTE)
if below is None and above is None: if below is None and above is None:
_LOGGER.error("Missing configuration key." _LOGGER.error("Missing configuration key."
@ -71,18 +74,19 @@ def if_action(hass, config):
def if_numeric_state(): def if_numeric_state():
""" Test numeric state condition. """ """ Test numeric state condition. """
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
return state is not None and _in_range(state.state, above, below) return state is not None and _in_range(state, above, below, attribute)
return if_numeric_state return if_numeric_state
def _in_range(value, range_start, range_end): def _in_range(state, range_start, range_end, attribute):
""" Checks if value is inside the range """ """ Checks if value is inside the range """
value = (state.state if attribute is None
else state.attributes.get(attribute))
try: try:
value = float(value) value = float(value)
except ValueError: except ValueError:
_LOGGER.warn("Missing value in numeric check") _LOGGER.warning("Missing value in numeric check")
return False return False
if range_start is not None and range_end is not None: if range_start is not None and range_end is not None:

View File

@ -4,7 +4,7 @@ homeassistant.components.automation.state
Offers state listening automation rules. Offers state listening automation rules.
For more details about this automation rule, please refer to the documentation For more details about this automation rule, please refer to the documentation
at https://home-assistant.io/components/automation.html#state-trigger at https://home-assistant.io/components/automation/#state-trigger
""" """
import logging import logging

View File

@ -4,7 +4,7 @@ homeassistant.components.automation.sun
Offers sun based automation rules. Offers sun based automation rules.
For more details about this automation rule, please refer to the documentation For more details about this automation rule, please refer to the documentation
at https://home-assistant.io/components/automation.html#sun-trigger at https://home-assistant.io/components/automation/#sun-trigger
""" """
import logging import logging
from datetime import timedelta from datetime import timedelta

View File

@ -4,7 +4,7 @@ homeassistant.components.automation.time
Offers time listening automation rules. Offers time listening automation rules.
For more details about this automation rule, please refer to the documentation For more details about this automation rule, please refer to the documentation
at https://home-assistant.io/components/automation.html#time-trigger at https://home-assistant.io/components/automation/#time-trigger
""" """
import logging import logging

View File

@ -4,7 +4,7 @@ homeassistant.components.automation.zone
Offers zone automation rules. Offers zone automation rules.
For more details about this automation rule, please refer to the documentation For more details about this automation rule, please refer to the documentation
at https://home-assistant.io/components/automation.html#zone-trigger at https://home-assistant.io/components/automation/#zone-trigger
""" """
import logging import logging
@ -46,6 +46,7 @@ def trigger(hass, config, action):
from_match = _in_zone(hass, zone_entity_id, from_s) if from_s else None from_match = _in_zone(hass, zone_entity_id, from_s) if from_s else None
to_match = _in_zone(hass, zone_entity_id, to_s) to_match = _in_zone(hass, zone_entity_id, to_s)
# pylint: disable=too-many-boolean-expressions
if event == EVENT_ENTER and not from_match and to_match or \ if event == EVENT_ENTER and not from_match and to_match or \
event == EVENT_LEAVE and from_match and not to_match: event == EVENT_LEAVE and from_match and not to_match:
action() action()

View File

@ -0,0 +1,49 @@
"""
homeassistant.components.binary_sensor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component to interface with binary sensors (sensors which only know two states)
that can be monitored.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/binary_sensor/
"""
import logging
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.entity import Entity
from homeassistant.const import (STATE_ON, STATE_OFF)
DOMAIN = 'binary_sensor'
SCAN_INTERVAL = 30
ENTITY_ID_FORMAT = DOMAIN + '.{}'
def setup(hass, config):
""" Track states and offer events for binary sensors. """
component = EntityComponent(
logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL)
component.setup(config)
return True
# pylint: disable=no-self-use
class BinarySensorDevice(Entity):
""" Represents a binary sensor. """
@property
def is_on(self):
""" True if the binary sensor is on. """
return None
@property
def state(self):
""" Returns the state of the binary sensor. """
return STATE_ON if self.is_on else STATE_OFF
@property
def friendly_state(self):
""" Returns the friendly state of the binary sensor. """
return None

View File

@ -0,0 +1,107 @@
"""
homeassistant.components.binary_sensor.arest
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The arest sensor will consume an exposed aREST API of a device.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.arest/
"""
from datetime import timedelta
import logging
import requests
from homeassistant.util import Throttle
from homeassistant.components.binary_sensor import BinarySensorDevice
_LOGGER = logging.getLogger(__name__)
# Return cached results if last scan was less then this time ago
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
CONF_RESOURCE = 'resource'
CONF_PIN = 'pin'
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Get the aREST binary sensor. """
resource = config.get(CONF_RESOURCE)
pin = config.get(CONF_PIN)
if None in (resource, pin):
_LOGGER.error('Not all required config keys present: %s',
', '.join((CONF_RESOURCE, CONF_PIN)))
return False
try:
response = requests.get(resource, timeout=10).json()
except requests.exceptions.MissingSchema:
_LOGGER.error('Missing resource or schema in configuration. '
'Add http:// to your URL.')
return False
except requests.exceptions.ConnectionError:
_LOGGER.error('No route to device at %s. '
'Please check the IP address in the configuration file.',
resource)
return False
arest = ArestData(resource, pin)
add_devices([ArestBinarySensor(arest,
resource,
config.get('name', response['name']),
pin)])
# pylint: disable=too-many-instance-attributes, too-many-arguments
class ArestBinarySensor(BinarySensorDevice):
""" Implements an aREST binary sensor for a pin. """
def __init__(self, arest, resource, name, pin):
self.arest = arest
self._resource = resource
self._name = name
self._pin = pin
self.update()
if self._pin is not None:
request = requests.get('{}/mode/{}/i'.format
(self._resource, self._pin), timeout=10)
if request.status_code is not 200:
_LOGGER.error("Can't set mode. Is device offline?")
@property
def name(self):
""" The name of the binary sensor. """
return self._name
@property
def is_on(self):
""" True if the binary sensor is on. """
return bool(self.arest.data.get('state'))
def update(self):
""" Gets the latest data from aREST API. """
self.arest.update()
# pylint: disable=too-few-public-methods
class ArestData(object):
""" Class for handling the data retrieval for pins. """
def __init__(self, resource, pin):
self._resource = resource
self._pin = pin
self.data = {}
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
""" Gets the latest data from aREST device. """
try:
response = requests.get('{}/digital/{}'.format(
self._resource, self._pin), timeout=10)
self.data = {'state': response.json()['return_value']}
except requests.exceptions.ConnectionError:
_LOGGER.error("No route to device '%s'. Is device offline?",
self._resource)

View File

@ -0,0 +1,37 @@
"""
homeassistant.components.binary_sensor.demo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo platform that has two fake binary sensors.
"""
from homeassistant.components.binary_sensor import BinarySensorDevice
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Demo binary sensors. """
add_devices([
DemoBinarySensor('Basement Floor Wet', False),
DemoBinarySensor('Movement Backyard', True),
])
class DemoBinarySensor(BinarySensorDevice):
""" A Demo binary sensor. """
def __init__(self, name, state):
self._name = name
self._state = state
@property
def should_poll(self):
""" No polling needed for a demo binary sensor. """
return False
@property
def name(self):
""" Returns the name of the binary sensor. """
return self._name
@property
def is_on(self):
""" True if the binary sensor is on. """
return self._state

View File

@ -0,0 +1,76 @@
"""
homeassistant.components.binary_sensor.mqtt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to configure a MQTT binary sensor.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.mqtt/
"""
import logging
from homeassistant.components.binary_sensor import BinarySensorDevice
import homeassistant.components.mqtt as mqtt
_LOGGER = logging.getLogger(__name__)
DEFAULT_NAME = 'MQTT Binary sensor'
DEFAULT_QOS = 0
DEFAULT_PAYLOAD_ON = 'ON'
DEFAULT_PAYLOAD_OFF = 'OFF'
DEPENDENCIES = ['mqtt']
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Add MQTT binary sensor. """
if config.get('state_topic') is None:
_LOGGER.error('Missing required variable: state_topic')
return False
add_devices([MqttBinarySensor(
hass,
config.get('name', DEFAULT_NAME),
config.get('state_topic', None),
config.get('qos', DEFAULT_QOS),
config.get('payload_on', DEFAULT_PAYLOAD_ON),
config.get('payload_off', DEFAULT_PAYLOAD_OFF))])
# pylint: disable=too-many-arguments, too-many-instance-attributes
class MqttBinarySensor(BinarySensorDevice):
""" Represents a binary sensor that is updated by MQTT. """
def __init__(self, hass, name, state_topic, qos, payload_on, payload_off):
self._hass = hass
self._name = name
self._state = False
self._state_topic = state_topic
self._payload_on = payload_on
self._payload_off = payload_off
self._qos = qos
def message_received(topic, payload, qos):
""" A new MQTT message has been received. """
if payload == self._payload_on:
self._state = True
self.update_ha_state()
elif payload == self._payload_off:
self._state = False
self.update_ha_state()
mqtt.subscribe(hass, self._state_topic, message_received, self._qos)
@property
def should_poll(self):
""" No polling needed. """
return False
@property
def name(self):
""" The name of the binary sensor. """
return self._name
@property
def is_on(self):
""" True if the binary sensor is on. """
return self._state

View File

@ -1,12 +1,13 @@
""" """
homeassistant.components.browser homeassistant.components.browser
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides functionality to launch a webbrowser on the host machine. Provides functionality to launch a webbrowser on the host machine.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/browser/
""" """
DOMAIN = "browser" DOMAIN = "browser"
DEPENDENCIES = []
SERVICE_BROWSE_URL = "browse_url" SERVICE_BROWSE_URL = "browse_url"

View File

@ -4,38 +4,23 @@ homeassistant.components.camera
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component to interface with various cameras. Component to interface with various cameras.
The following features are supported: For more details about this component, please refer to the documentation at
- Returning recorded camera images and streams https://home-assistant.io/components/camera/
- Proxying image requests via HA for external access
- Converting a still image url into a live video stream
Upcoming features
- Recording
- Snapshot
- Motion Detection Recording(for supported cameras)
- Automatic Configuration(for supported cameras)
- Creation of child entities for supported functions
- Collating motion event images passed via FTP into time based events
- A service for calling camera functions
- Camera movement(panning)
- Zoom
- Light/Nightvision toggling
- Support for more devices
- Expanded documentation
""" """
import requests
import logging import logging
import time
import re import re
import time
import requests
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.const import ( from homeassistant.const import (
ATTR_ENTITY_PICTURE, ATTR_ENTITY_PICTURE,
HTTP_NOT_FOUND, HTTP_NOT_FOUND,
ATTR_ENTITY_ID, ATTR_ENTITY_ID,
) )
from homeassistant.helpers.entity_component import EntityComponent
DOMAIN = 'camera' DOMAIN = 'camera'
DEPENDENCIES = ['http'] DEPENDENCIES = ['http']
@ -74,7 +59,7 @@ MJPEG_START_HEADER = 'Content-type: {0}\r\n\r\n'
# pylint: disable=too-many-branches # pylint: disable=too-many-branches
def setup(hass, config): def setup(hass, config):
""" Track states and offer events for sensors. """ """ Track states and offer events for cameras. """
component = EntityComponent( component = EntityComponent(
logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL, logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL,
@ -96,16 +81,21 @@ def setup(hass, config):
def _proxy_camera_image(handler, path_match, data): def _proxy_camera_image(handler, path_match, data):
""" Proxies the camera image via the HA server. """ """ Proxies the camera image via the HA server. """
entity_id = path_match.group(ATTR_ENTITY_ID) entity_id = path_match.group(ATTR_ENTITY_ID)
camera = component.entities.get(entity_id)
camera = None if camera is None:
if entity_id in component.entities.keys():
camera = component.entities[entity_id]
if camera:
response = camera.camera_image()
handler.wfile.write(response)
else:
handler.send_response(HTTP_NOT_FOUND) handler.send_response(HTTP_NOT_FOUND)
handler.end_headers()
return
response = camera.camera_image()
if response is None:
handler.send_response(HTTP_NOT_FOUND)
handler.end_headers()
return
handler.wfile.write(response)
hass.http.register_path( hass.http.register_path(
'GET', 'GET',
@ -114,18 +104,16 @@ def setup(hass, config):
# pylint: disable=unused-argument # pylint: disable=unused-argument
def _proxy_camera_mjpeg_stream(handler, path_match, data): def _proxy_camera_mjpeg_stream(handler, path_match, data):
""" Proxies the camera image as an mjpeg stream via the HA server. """
Proxies the camera image as an mjpeg stream via the HA server.
This function takes still images from the IP camera and turns them This function takes still images from the IP camera and turns them
into an MJPEG stream. This means that HA can return a live video into an MJPEG stream. This means that HA can return a live video
stream even with only a still image URL available. stream even with only a still image URL available.
""" """
entity_id = path_match.group(ATTR_ENTITY_ID) entity_id = path_match.group(ATTR_ENTITY_ID)
camera = component.entities.get(entity_id)
camera = None if camera is None:
if entity_id in component.entities.keys():
camera = component.entities[entity_id]
if not camera:
handler.send_response(HTTP_NOT_FOUND) handler.send_response(HTTP_NOT_FOUND)
handler.end_headers() handler.end_headers()
return return
@ -143,9 +131,9 @@ def setup(hass, config):
# MJPEG_START_HEADER.format() # MJPEG_START_HEADER.format()
while True: while True:
img_bytes = camera.camera_image() img_bytes = camera.camera_image()
if img_bytes is None:
continue
headers_str = '\r\n'.join(( headers_str = '\r\n'.join((
'Content-length: {}'.format(len(img_bytes)), 'Content-length: {}'.format(len(img_bytes)),
'Content-type: image/jpeg', 'Content-type: image/jpeg',
@ -159,12 +147,12 @@ def setup(hass, config):
handler.request.sendall( handler.request.sendall(
bytes('--jpgboundary\r\n', 'utf-8')) bytes('--jpgboundary\r\n', 'utf-8'))
time.sleep(0.5)
except (requests.RequestException, IOError): except (requests.RequestException, IOError):
camera.is_streaming = False camera.is_streaming = False
camera.update_ha_state() camera.update_ha_state()
camera.is_streaming = False
hass.http.register_path( hass.http.register_path(
'GET', 'GET',
re.compile( re.compile(
@ -175,7 +163,7 @@ def setup(hass, config):
class Camera(Entity): class Camera(Entity):
""" The base class for camera components """ """ The base class for camera components. """
def __init__(self): def __init__(self):
self.is_streaming = False self.is_streaming = False
@ -183,23 +171,23 @@ class Camera(Entity):
@property @property
# pylint: disable=no-self-use # pylint: disable=no-self-use
def is_recording(self): def is_recording(self):
""" Returns true if the device is recording """ """ Returns true if the device is recording. """
return False return False
@property @property
# pylint: disable=no-self-use # pylint: disable=no-self-use
def brand(self): def brand(self):
""" Should return a string of the camera brand """ """ Should return a string of the camera brand. """
return None return None
@property @property
# pylint: disable=no-self-use # pylint: disable=no-self-use
def model(self): def model(self):
""" Returns string of camera model """ """ Returns string of camera model. """
return None return None
def camera_image(self): def camera_image(self):
""" Return bytes of camera image """ """ Return bytes of camera image. """
raise NotImplementedError() raise NotImplementedError()
@property @property

View File

@ -0,0 +1,37 @@
"""
homeassistant.components.camera.demo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo platform that has a fake camera.
"""
import os
from homeassistant.components.camera import Camera
import homeassistant.util.dt as dt_util
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Demo camera. """
add_devices([
DemoCamera('Demo camera')
])
class DemoCamera(Camera):
""" A Demo camera. """
def __init__(self, name):
super().__init__()
self._name = name
def camera_image(self):
""" Return a faked still image response. """
now = dt_util.utcnow()
image_path = os.path.join(os.path.dirname(__file__),
'demo_{}.jpg'.format(now.second % 4))
with open(image_path, 'rb') as file:
return file.read()
@property
def name(self):
""" Return the name of this device. """
return self._name

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View File

@ -4,14 +4,14 @@ homeassistant.components.camera.foscam
This component provides basic support for Foscam IP cameras. This component provides basic support for Foscam IP cameras.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/camera.foscam.html https://home-assistant.io/components/camera.foscam/
""" """
import logging import logging
from homeassistant.helpers import validate_config
from homeassistant.components.camera import DOMAIN
from homeassistant.components.camera import Camera
import requests import requests
import re
from homeassistant.helpers import validate_config
from homeassistant.components.camera import DOMAIN, Camera
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -40,7 +40,7 @@ class FoscamCamera(Camera):
self._username = device_info.get('username') self._username = device_info.get('username')
self._password = device_info.get('password') self._password = device_info.get('password')
self._snap_picture_url = self._base_url \ self._snap_picture_url = self._base_url \
+ 'cgi-bin/CGIProxy.fcgi?cmd=snapPicture&usr=' \ + 'cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=' \
+ self._username + '&pwd=' + self._password + self._username + '&pwd=' + self._password
self._name = device_info.get('name', 'Foscam Camera') self._name = device_info.get('name', 'Foscam Camera')
@ -50,17 +50,9 @@ class FoscamCamera(Camera):
def camera_image(self): def camera_image(self):
""" Return a still image reponse from the camera. """ """ Return a still image reponse from the camera. """
# send the request to snap a picture # Send the request to snap a picture and return raw jpg data
response = requests.get(self._snap_picture_url) response = requests.get(self._snap_picture_url)
# parse the response to find the image file name
pattern = re.compile('src="[.][.]/(.*[.]jpg)"')
filename = pattern.search(response.content.decode("utf-8")).group(1)
# send request for the image
response = requests.get(self._base_url + filename)
return response.content return response.content
@property @property

View File

@ -4,14 +4,15 @@ homeassistant.components.camera.generic
Support for IP Cameras. Support for IP Cameras.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/camera.generic.html https://home-assistant.io/components/camera.generic/
""" """
import logging import logging
from requests.auth import HTTPBasicAuth
from homeassistant.helpers import validate_config
from homeassistant.components.camera import DOMAIN
from homeassistant.components.camera import Camera
import requests import requests
from requests.auth import HTTPBasicAuth
from homeassistant.helpers import validate_config
from homeassistant.components.camera import DOMAIN, Camera
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -40,13 +41,21 @@ class GenericCamera(Camera):
self._still_image_url = device_info['still_image_url'] self._still_image_url = device_info['still_image_url']
def camera_image(self): def camera_image(self):
""" Return a still image reponse from the camera. """ """ Return a still image response from the camera. """
if self._username and self._password: if self._username and self._password:
try:
response = requests.get( response = requests.get(
self._still_image_url, self._still_image_url,
auth=HTTPBasicAuth(self._username, self._password)) auth=HTTPBasicAuth(self._username, self._password))
except requests.exceptions.RequestException as error:
_LOGGER.error('Error getting camera image: %s', error)
return None
else: else:
try:
response = requests.get(self._still_image_url) response = requests.get(self._still_image_url)
except requests.exceptions.RequestException as error:
_LOGGER.error('Error getting camera image: %s', error)
return None
return response.content return response.content

View File

@ -0,0 +1,72 @@
"""
homeassistant.components.camera.mjpeg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for IP Cameras.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/camera.mjpeg/
"""
from contextlib import closing
import logging
import requests
from requests.auth import HTTPBasicAuth
from homeassistant.helpers import validate_config
from homeassistant.components.camera import DOMAIN, Camera
_LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Adds a mjpeg IP Camera. """
if not validate_config({DOMAIN: config}, {DOMAIN: ['mjpeg_url']},
_LOGGER):
return None
add_devices_callback([MjpegCamera(config)])
# pylint: disable=too-many-instance-attributes
class MjpegCamera(Camera):
"""
A generic implementation of an IP camera that is reachable over a URL.
"""
def __init__(self, device_info):
super().__init__()
self._name = device_info.get('name', 'Mjpeg Camera')
self._username = device_info.get('username')
self._password = device_info.get('password')
self._mjpeg_url = device_info['mjpeg_url']
def camera_image(self):
""" Return a still image response from the camera. """
def process_response(response):
""" Take in a response object, return the jpg from it. """
data = b''
for chunk in response.iter_content(1024):
data += chunk
jpg_start = data.find(b'\xff\xd8')
jpg_end = data.find(b'\xff\xd9')
if jpg_start != -1 and jpg_end != -1:
jpg = data[jpg_start:jpg_end + 2]
return jpg
if self._username and self._password:
with closing(requests.get(self._mjpeg_url,
auth=HTTPBasicAuth(self._username,
self._password),
stream=True)) as response:
return process_response(response)
else:
with closing(requests.get(self._mjpeg_url,
stream=True)) as response:
return process_response(response)
@property
def name(self):
""" Return the name of this device. """
return self._name

View File

@ -15,7 +15,6 @@ from homeassistant.helpers import generate_entity_id
from homeassistant.const import EVENT_TIME_CHANGED from homeassistant.const import EVENT_TIME_CHANGED
DOMAIN = "configurator" DOMAIN = "configurator"
DEPENDENCIES = []
ENTITY_ID_FORMAT = DOMAIN + ".{}" ENTITY_ID_FORMAT = DOMAIN + ".{}"
SERVICE_CONFIGURE = "configure" SERVICE_CONFIGURE = "configure"

View File

@ -4,7 +4,7 @@ homeassistant.components.conversation
Provides functionality to have conversations with Home Assistant. Provides functionality to have conversations with Home Assistant.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/conversation.html https://home-assistant.io/components/conversation/
""" """
import logging import logging
import re import re
@ -14,7 +14,6 @@ from homeassistant.const import (
ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF) ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF)
DOMAIN = "conversation" DOMAIN = "conversation"
DEPENDENCIES = []
SERVICE_PROCESS = "process" SERVICE_PROCESS = "process"

View File

@ -10,14 +10,26 @@ import homeassistant.core as ha
import homeassistant.bootstrap as bootstrap import homeassistant.bootstrap as bootstrap
import homeassistant.loader as loader import homeassistant.loader as loader
from homeassistant.const import ( from homeassistant.const import (
CONF_PLATFORM, ATTR_ENTITY_PICTURE, ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME) CONF_PLATFORM, ATTR_ENTITY_ID)
DOMAIN = "demo" DOMAIN = "demo"
DEPENDENCIES = ['introduction', 'conversation'] DEPENDENCIES = ['conversation', 'introduction', 'zone']
COMPONENTS_WITH_DEMO_PLATFORM = [ COMPONENTS_WITH_DEMO_PLATFORM = [
'switch', 'light', 'sensor', 'thermostat', 'media_player', 'notify'] 'alarm_control_panel',
'binary_sensor',
'camera',
'device_tracker',
'light',
'lock',
'media_player',
'notify',
'rollershutter',
'sensor',
'switch',
'thermostat',
]
def setup(hass, config): def setup(hass, config):
@ -54,23 +66,6 @@ def setup(hass, config):
group.setup_group(hass, 'bedroom', [lights[0], switches[1], group.setup_group(hass, 'bedroom', [lights[0], switches[1],
media_players[0]]) media_players[0]])
# Setup IP Camera
bootstrap.setup_component(
hass, 'camera',
{'camera': {
'platform': 'generic',
'name': 'IP Camera',
'still_image_url': 'http://home-assistant.io/demo/webcam.jpg',
}})
# Setup alarm_control_panel
bootstrap.setup_component(
hass, 'alarm_control_panel',
{'alarm_control_panel': {
'platform': 'manual',
'name': 'Test Alarm',
}})
# Setup scripts # Setup scripts
bootstrap.setup_component( bootstrap.setup_component(
hass, 'script', hass, 'script',
@ -110,25 +105,6 @@ def setup(hass, config):
}}, }},
]}) ]})
# Setup fake device tracker
hass.states.set("device_tracker.paulus", "home",
{ATTR_ENTITY_PICTURE:
"http://graph.facebook.com/297400035/picture",
ATTR_FRIENDLY_NAME: 'Paulus'})
hass.states.set("device_tracker.anne_therese", "not_home",
{ATTR_FRIENDLY_NAME: 'Anne Therese',
'latitude': hass.config.latitude + 0.002,
'longitude': hass.config.longitude + 0.002})
hass.states.set("group.all_devices", "home",
{
"auto": True,
ATTR_ENTITY_ID: [
"device_tracker.paulus",
"device_tracker.anne_therese"
]
})
# Setup configurator # Setup configurator
configurator_ids = [] configurator_ids = []

View File

@ -1,9 +1,11 @@
""" """
homeassistant.components.device_sun_light_trigger homeassistant.components.device_sun_light_trigger
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides functionality to turn on lights based on the state of the sun and
devices.
Provides functionality to turn on lights based on For more details about this component, please refer to the documentation at
the state of the sun and devices. https://home-assistant.io/components/device_sun_light_trigger/
""" """
import logging import logging
from datetime import timedelta from datetime import timedelta

View File

@ -1,25 +1,10 @@
""" """
homeassistant.components.device_tracker homeassistant.components.device_tracker
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides functionality to keep track of devices. Provides functionality to keep track of devices.
device_tracker: For more details about this component, please refer to the documentation at
platform: netgear https://home-assistant.io/components/device_tracker/
# Optional
# How many seconds to wait after not seeing device to consider it not home
consider_home: 180
# Seconds between each scan
interval_seconds: 12
# New found devices auto found
track_new_devices: yes
# Maximum distance from home we consider people home
range_home: 100
""" """
# pylint: disable=too-many-instance-attributes, too-many-arguments # pylint: disable=too-many-instance-attributes, too-many-arguments
# pylint: disable=too-many-locals # pylint: disable=too-many-locals

View File

@ -5,7 +5,7 @@ Device tracker platform that supports scanning an Actiontec MI424WR
(Verizon FIOS) router for device presence. (Verizon FIOS) router for device presence.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.actiontec.html https://home-assistant.io/components/device_tracker.actiontec/
""" """
import logging import logging
from datetime import timedelta from datetime import timedelta

View File

@ -5,7 +5,7 @@ Device tracker platform that supports scanning a Aruba Access Point for device
presence. presence.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.aruba.html https://home-assistant.io/components/device_tracker.aruba/
""" """
import logging import logging
from datetime import timedelta from datetime import timedelta

View File

@ -4,32 +4,8 @@ homeassistant.components.device_tracker.asuswrt
Device tracker platform that supports scanning a ASUSWRT router for device Device tracker platform that supports scanning a ASUSWRT router for device
presence. presence.
This device tracker needs telnet to be enabled on the router. For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.asuswrt/
Configuration:
To use the ASUSWRT tracker you will need to add something like the following
to your configuration.yaml file.
device_tracker:
platform: asuswrt
host: YOUR_ROUTER_IP
username: YOUR_ADMIN_USERNAME
password: YOUR_ADMIN_PASSWORD
Variables:
host
*Required
The IP address of your router, e.g. 192.168.1.1.
username
*Required
The username of an user with administrative privileges, usually 'admin'.
password
*Required
The password for your given admin account.
""" """
import logging import logging
from datetime import timedelta from datetime import timedelta
@ -158,10 +134,13 @@ class AsusWrtDeviceScanner(object):
for lease in leases_result: for lease in leases_result:
match = _LEASES_REGEX.search(lease.decode('utf-8')) match = _LEASES_REGEX.search(lease.decode('utf-8'))
if not match:
_LOGGER.warning("Could not parse lease row: %s", lease)
continue
# For leases where the client doesn't set a hostname, ensure # For leases where the client doesn't set a hostname, ensure
# it is blank and not '*', which breaks the entity_id down # it is blank and not '*', which breaks the entity_id down
# the line # the line
if match:
host = match.group('host') host = match.group('host')
if host == '*': if host == '*':
host = '' host = ''
@ -175,6 +154,9 @@ class AsusWrtDeviceScanner(object):
for neighbor in neighbors: for neighbor in neighbors:
match = _IP_NEIGH_REGEX.search(neighbor.decode('utf-8')) match = _IP_NEIGH_REGEX.search(neighbor.decode('utf-8'))
if match and match.group('ip') in devices: if not match:
_LOGGER.warning("Could not parse neighbor row: %s", neighbor)
continue
if match.group('ip') in devices:
devices[match.group('ip')]['status'] = match.group('status') devices[match.group('ip')]['status'] = match.group('status')
return devices return devices

View File

@ -5,7 +5,7 @@ Device tracker platform that supports scanning a DD-WRT router for device
presence. presence.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.ddwrt.html https://home-assistant.io/components/device_tracker.ddwrt/
""" """
import logging import logging
from datetime import timedelta from datetime import timedelta

View File

@ -1,7 +1,6 @@
""" """
homeassistant.components.device_tracker.demo homeassistant.components.device_tracker.demo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo platform for the device tracker. Demo platform for the device tracker.
device_tracker: device_tracker:

View File

@ -4,9 +4,8 @@ homeassistant.components.device_tracker.geofancy
Geofancy platform for the device tracker. Geofancy platform for the device tracker.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.geofancy.html https://home-assistant.io/components/device_tracker.geofancy/
""" """
from homeassistant.const import ( from homeassistant.const import (
HTTP_UNPROCESSABLE_ENTITY, HTTP_INTERNAL_SERVER_ERROR) HTTP_UNPROCESSABLE_ENTITY, HTTP_INTERNAL_SERVER_ERROR)

View File

@ -5,7 +5,7 @@ Device tracker platform that supports scanning a OpenWRT router for device
presence. presence.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.luci.html https://home-assistant.io/components/device_tracker.luci/
""" """
import logging import logging
import json import json

View File

@ -4,7 +4,7 @@ homeassistant.components.device_tracker.mqtt
MQTT platform for the device tracker. MQTT platform for the device tracker.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.mqtt.html https://home-assistant.io/components/device_tracker.mqtt/
""" """
import logging import logging
from homeassistant import util from homeassistant import util

View File

@ -5,7 +5,7 @@ Device tracker platform that supports scanning a Netgear router for device
presence. presence.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.netgear.html https://home-assistant.io/components/device_tracker.netgear/
""" """
import logging import logging
from datetime import timedelta from datetime import timedelta

View File

@ -4,7 +4,7 @@ homeassistant.components.device_tracker.nmap
Device tracker platform that supports scanning a network with nmap. Device tracker platform that supports scanning a network with nmap.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.nmap_scanner.html https://home-assistant.io/components/device_tracker.nmap_scanner/
""" """
import logging import logging
from datetime import timedelta from datetime import timedelta
@ -98,7 +98,7 @@ class NmapDeviceScanner(object):
from nmap import PortScanner, PortScannerError from nmap import PortScanner, PortScannerError
scanner = PortScanner() scanner = PortScanner()
options = "-F --host-timeout 5" options = "-F --host-timeout 5s"
if self.home_interval: if self.home_interval:
boundary = dt_util.now() - self.home_interval boundary = dt_util.now() - self.home_interval

View File

@ -4,7 +4,7 @@ homeassistant.components.device_tracker.owntracks
OwnTracks platform for the device tracker. OwnTracks platform for the device tracker.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.owntracks.html https://home-assistant.io/components/device_tracker.owntracks/
""" """
import json import json
import logging import logging

View File

@ -5,7 +5,7 @@ Device tracker platform that supports fetching WiFi associations
through SNMP. through SNMP.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.snmp.html https://home-assistant.io/components/device_tracker.snmp/
""" """
import logging import logging
from datetime import timedelta from datetime import timedelta
@ -45,9 +45,12 @@ class SnmpScanner(object):
This class queries any SNMP capable Acces Point for connected devices. This class queries any SNMP capable Acces Point for connected devices.
""" """
def __init__(self, config): def __init__(self, config):
self.host = config[CONF_HOST] from pysnmp.entity.rfc3413.oneliner import cmdgen
self.community = config[CONF_COMMUNITY] self.snmp = cmdgen.CommandGenerator()
self.baseoid = config[CONF_BASEOID]
self.host = cmdgen.UdpTransportTarget((config[CONF_HOST], 161))
self.community = cmdgen.CommunityData(config[CONF_COMMUNITY])
self.baseoid = cmdgen.MibVariable(config[CONF_BASEOID])
self.lock = threading.Lock() self.lock = threading.Lock()
@ -91,16 +94,11 @@ class SnmpScanner(object):
def get_snmp_data(self): def get_snmp_data(self):
""" Fetch mac addresses from WAP via SNMP. """ """ Fetch mac addresses from WAP via SNMP. """
from pysnmp.entity.rfc3413.oneliner import cmdgen
devices = [] devices = []
snmp = cmdgen.CommandGenerator() errindication, errstatus, errindex, restable = self.snmp.nextCmd(
errindication, errstatus, errindex, restable = snmp.nextCmd( self.community, self.host, self.baseoid)
cmdgen.CommunityData(self.community),
cmdgen.UdpTransportTarget((self.host, 161)),
cmdgen.MibVariable(self.baseoid)
)
if errindication: if errindication:
_LOGGER.error("SNMPLIB error: %s", errindication) _LOGGER.error("SNMPLIB error: %s", errindication)

View File

@ -5,7 +5,7 @@ Device tracker platform that supports scanning a THOMSON router for device
presence. presence.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.thomson.html https://home-assistant.io/components/device_tracker.thomson/
""" """
import logging import logging
from datetime import timedelta from datetime import timedelta

View File

@ -5,7 +5,7 @@ Device tracker platform that supports scanning a Tomato router for device
presence. presence.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.tomato.html https://home-assistant.io/components/device_tracker.tomato/
""" """
import logging import logging
import json import json

View File

@ -5,7 +5,7 @@ Device tracker platform that supports scanning a TP-Link router for device
presence. presence.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.tplink.html https://home-assistant.io/components/device_tracker.tplink/
""" """
import base64 import base64
import logging import logging

View File

@ -5,7 +5,7 @@ Device tracker platform that supports scanning a OpenWRT router for device
presence. presence.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.ubus.html https://home-assistant.io/components/device_tracker.ubus/
""" """
import logging import logging
import json import json

View File

@ -1,7 +1,6 @@
""" """
homeassistant.components.discovery homeassistant.components.discovery
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Starts a service to scan in intervals for new devices. Starts a service to scan in intervals for new devices.
Will emit EVENT_PLATFORM_DISCOVERED whenever a new service has been discovered. Will emit EVENT_PLATFORM_DISCOVERED whenever a new service has been discovered.
@ -18,8 +17,7 @@ from homeassistant.const import (
ATTR_SERVICE, ATTR_DISCOVERED) ATTR_SERVICE, ATTR_DISCOVERED)
DOMAIN = "discovery" DOMAIN = "discovery"
DEPENDENCIES = [] REQUIREMENTS = ['netdisco==0.5.2']
REQUIREMENTS = ['netdisco==0.5.1']
SCAN_INTERVAL = 300 # seconds SCAN_INTERVAL = 300 # seconds

View File

@ -4,7 +4,7 @@ homeassistant.components.downloader
Provides functionality to download files. Provides functionality to download files.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/downloader.html https://home-assistant.io/components/downloader/
""" """
import os import os
import logging import logging
@ -15,7 +15,6 @@ from homeassistant.helpers import validate_config
from homeassistant.util import sanitize_filename from homeassistant.util import sanitize_filename
DOMAIN = "downloader" DOMAIN = "downloader"
DEPENDENCIES = []
SERVICE_DOWNLOAD_FILE = "download_file" SERVICE_DOWNLOAD_FILE = "download_file"

View File

@ -0,0 +1,155 @@
"""
homeassistant.components.ecobee
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ecobee Component
This component adds support for Ecobee3 Wireless Thermostats.
You will need to setup developer access to your thermostat,
and create and API key on the ecobee website.
The first time you run this component you will see a configuration
component card in Home Assistant. This card will contain a PIN code
that you will need to use to authorize access to your thermostat. You
can do this at https://www.ecobee.com/consumerportal/index.html
Click My Apps, Add application, Enter Pin and click Authorize.
After authorizing the application click the button in the configuration
card. Now your thermostat and sensors should shown in home-assistant.
You can use the optional hold_temp parameter to set whether or not holds
are set indefintely or until the next scheduled event.
ecobee:
api_key: asdfasdfasdfasdfasdfaasdfasdfasdfasdf
hold_temp: True
"""
from datetime import timedelta
import logging
import os
from homeassistant.loader import get_component
from homeassistant import bootstrap
from homeassistant.util import Throttle
from homeassistant.const import (
EVENT_PLATFORM_DISCOVERED, ATTR_SERVICE, ATTR_DISCOVERED, CONF_API_KEY)
DOMAIN = "ecobee"
DISCOVER_THERMOSTAT = "ecobee.thermostat"
DISCOVER_SENSORS = "ecobee.sensor"
NETWORK = None
HOLD_TEMP = 'hold_temp'
REQUIREMENTS = [
'https://github.com/nkgilley/python-ecobee-api/archive/'
'5645f843b64ac4f6e59dfb96233a07083c5e10c1.zip#python-ecobee==0.0.3']
_LOGGER = logging.getLogger(__name__)
ECOBEE_CONFIG_FILE = 'ecobee.conf'
_CONFIGURING = {}
# Return cached results if last scan was less then this time ago
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=180)
def request_configuration(network, hass, config):
""" Request configuration steps from the user. """
configurator = get_component('configurator')
if 'ecobee' in _CONFIGURING:
configurator.notify_errors(
_CONFIGURING['ecobee'], "Failed to register, please try again.")
return
# pylint: disable=unused-argument
def ecobee_configuration_callback(callback_data):
""" Actions to do when our configuration callback is called. """
network.request_tokens()
network.update()
setup_ecobee(hass, network, config)
_CONFIGURING['ecobee'] = configurator.request_config(
hass, "Ecobee", ecobee_configuration_callback,
description=(
'Please authorize this app at https://www.ecobee.com/consumer'
'portal/index.html with pin code: ' + network.pin),
description_image="/static/images/config_ecobee_thermostat.png",
submit_caption="I have authorized the app."
)
def setup_ecobee(hass, network, config):
""" Setup ecobee thermostat """
# If ecobee has a PIN then it needs to be configured.
if network.pin is not None:
request_configuration(network, hass, config)
return
if 'ecobee' in _CONFIGURING:
configurator = get_component('configurator')
configurator.request_done(_CONFIGURING.pop('ecobee'))
# Ensure component is loaded
bootstrap.setup_component(hass, 'thermostat', config)
bootstrap.setup_component(hass, 'sensor', config)
hold_temp = config[DOMAIN].get(HOLD_TEMP, False)
# Fire thermostat discovery event
hass.bus.fire(EVENT_PLATFORM_DISCOVERED, {
ATTR_SERVICE: DISCOVER_THERMOSTAT,
ATTR_DISCOVERED: {'hold_temp': hold_temp}
})
# Fire sensor discovery event
hass.bus.fire(EVENT_PLATFORM_DISCOVERED, {
ATTR_SERVICE: DISCOVER_SENSORS,
ATTR_DISCOVERED: {}
})
# pylint: disable=too-few-public-methods
class EcobeeData(object):
""" Gets the latest data and update the states. """
def __init__(self, config_file):
from pyecobee import Ecobee
self.ecobee = Ecobee(config_file)
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
""" Get the latest data from pyecobee. """
self.ecobee.update()
_LOGGER.info("ecobee data updated successfully.")
def setup(hass, config):
"""
Setup Ecobee.
Will automatically load thermostat and sensor components to support
devices discovered on the network.
"""
# pylint: disable=global-statement, import-error
global NETWORK
if 'ecobee' in _CONFIGURING:
return
from pyecobee import config_from_file
# Create ecobee.conf if it doesn't exist
if not os.path.isfile(hass.config.path(ECOBEE_CONFIG_FILE)):
if config[DOMAIN].get(CONF_API_KEY) is None:
_LOGGER.error("No ecobee api_key found in config.")
return
jsonconfig = {"API_KEY": config[DOMAIN].get(CONF_API_KEY)}
config_from_file(hass.config.path(ECOBEE_CONFIG_FILE), jsonconfig)
NETWORK = EcobeeData(hass.config.path(ECOBEE_CONFIG_FILE))
setup_ecobee(hass, NETWORK.ecobee, config)
return True

View File

@ -8,7 +8,7 @@ import re
import os import os
import logging import logging
from . import version from . import version, mdi_version
import homeassistant.util as util import homeassistant.util as util
from homeassistant.const import URL_ROOT, HTTP_OK from homeassistant.const import URL_ROOT, HTTP_OK
from homeassistant.config import get_default_config_dir from homeassistant.config import get_default_config_dir
@ -22,7 +22,7 @@ _LOGGER = logging.getLogger(__name__)
FRONTEND_URLS = [ FRONTEND_URLS = [
URL_ROOT, '/logbook', '/history', '/map', '/devService', '/devState', URL_ROOT, '/logbook', '/history', '/map', '/devService', '/devState',
'/devEvent'] '/devEvent', '/devInfo']
STATES_URL = re.compile(r'/states(/([a-zA-Z\._\-0-9/]+)|)') STATES_URL = re.compile(r'/states(/([a-zA-Z\._\-0-9/]+)|)')
_FINGERPRINT = re.compile(r'^(\w+)-[a-z0-9]{32}\.(\w+)$', re.IGNORECASE) _FINGERPRINT = re.compile(r'^(\w+)-[a-z0-9]{32}\.(\w+)$', re.IGNORECASE)
@ -54,8 +54,7 @@ def setup(hass, config):
def _handle_get_root(handler, path_match, data): def _handle_get_root(handler, path_match, data):
""" Renders the debug interface. """ """ Renders the frontend. """
handler.send_response(HTTP_OK) handler.send_response(HTTP_OK)
handler.send_header('Content-type', 'text/html; charset=utf-8') handler.send_header('Content-type', 'text/html; charset=utf-8')
handler.end_headers() handler.end_headers()
@ -66,7 +65,7 @@ def _handle_get_root(handler, path_match, data):
app_url = "frontend-{}.html".format(version.VERSION) app_url = "frontend-{}.html".format(version.VERSION)
# auto login if no password was set, else check api_password param # auto login if no password was set, else check api_password param
auth = ('no_password_set' if handler.server.no_password_set auth = ('no_password_set' if handler.server.api_password is None
else data.get('api_password', '')) else data.get('api_password', ''))
with open(INDEX_PATH) as template_file: with open(INDEX_PATH) as template_file:
@ -74,6 +73,7 @@ def _handle_get_root(handler, path_match, data):
template_html = template_html.replace('{{ app_url }}', app_url) template_html = template_html.replace('{{ app_url }}', app_url)
template_html = template_html.replace('{{ auth }}', auth) template_html = template_html.replace('{{ auth }}', auth)
template_html = template_html.replace('{{ icons }}', mdi_version.VERSION)
handler.wfile.write(template_html.encode("UTF-8")) handler.wfile.write(template_html.encode("UTF-8"))

View File

@ -4,16 +4,13 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>Home Assistant</title> <title>Home Assistant</title>
<link rel='manifest' href='/static/manifest.json' /> <link rel='manifest' href='/static/manifest.json'>
<link rel='shortcut icon' href='/static/favicon.ico' /> <link rel='icon' href='/static/favicon.ico'>
<link rel='icon' type='image/png'
href='/static/favicon-192x192.png' sizes='192x192'>
<link rel='apple-touch-icon' sizes='180x180' <link rel='apple-touch-icon' sizes='180x180'
href='/static/favicon-apple-180x180.png'> href='/static/favicon-apple-180x180.png'>
<meta name='apple-mobile-web-app-capable' content='yes'> <meta name='apple-mobile-web-app-capable' content='yes'>
<meta name='mobile-web-app-capable' content='yes'> <meta name='mobile-web-app-capable' content='yes'>
<meta name='viewport' content='width=device-width, <meta name='viewport' content='width=device-width, user-scalable=no'>
user-scalable=no' />
<meta name='theme-color' content='#03a9f4'> <meta name='theme-color' content='#03a9f4'>
<style> <style>
#init { #init {
@ -26,26 +23,19 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
text-align: center; text-align: center;
font-family: 'Roboto', 'Noto', sans-serif;
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
right: 0; right: 0;
bottom: 0; bottom: 0;
} margin-bottom: 123px;
#init div {
line-height: 34px;
margin-bottom: 89px;
} }
</style> </style>
</head> </head>
<body fullbleed> <body fullbleed>
<div id='init'> <div id='init'><img src='/static/favicon-192x192.png' height='192'></div>
<img src='/static/splash.png' height='230' />
<div>Initializing</div>
</div>
<script src='/static/webcomponents-lite.min.js'></script> <script src='/static/webcomponents-lite.min.js'></script>
<link rel='import' href='/static/{{ app_url }}' /> <link rel='import' href='/static/{{ app_url }}' />
<home-assistant auth='{{ auth }}'></home-assistant> <home-assistant auth='{{ auth }}' icons='{{ icons }}'></home-assistant>
</body> </body>
</html> </html>

View File

@ -0,0 +1,2 @@
""" DO NOT MODIFY. Auto-generated by update_mdi script """
VERSION = "7d76081c37634d36af21f5cc1ca79408"

View File

@ -1,2 +1,2 @@
""" DO NOT MODIFY. Auto-generated by build_frontend script """ """ DO NOT MODIFY. Auto-generated by build_frontend script """
VERSION = "beb922c55bb26ea576581b453f6d7c04" VERSION = "33a9830ccda8000eb88700de9d4cd03b"

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

File diff suppressed because one or more lines are too long

@ -1 +1 @@
Subproject commit 24623ff26ab8cbf7b39f0a25c26d9d991063b61a Subproject commit 2e8ad266eeb8cd0136df498b995f584e01338000

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -3,12 +3,17 @@
"short_name": "Assistant", "short_name": "Assistant",
"start_url": "/", "start_url": "/",
"display": "standalone", "display": "standalone",
"theme_color": "#03A9F4",
"icons": [ "icons": [
{ {
"src": "\/static\/favicon-192x192.png", "src": "/static/favicon-192x192.png",
"sizes": "192x192", "sizes": "192x192",
"type": "image\/png", "type": "image/png",
"density": "4.0" },
{
"src": "/static/favicon-384x384.png",
"sizes": "384x384",
"type": "image/png",
} }
] ]
} }

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@ homeassistant.components.group
Provides functionality to group devices that can be turned on or off. Provides functionality to group devices that can be turned on or off.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/group.html https://home-assistant.io/components/group/
""" """
import homeassistant.core as ha import homeassistant.core as ha
from homeassistant.helpers import generate_entity_id from homeassistant.helpers import generate_entity_id
@ -17,7 +17,6 @@ from homeassistant.const import (
STATE_UNKNOWN) STATE_UNKNOWN)
DOMAIN = "group" DOMAIN = "group"
DEPENDENCIES = []
ENTITY_ID_FORMAT = DOMAIN + ".{}" ENTITY_ID_FORMAT = DOMAIN + ".{}"

View File

@ -4,7 +4,7 @@ homeassistant.components.history
Provide pre-made queries on top of the recorder component. Provide pre-made queries on top of the recorder component.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/history.html https://home-assistant.io/components/history/
""" """
import re import re
from datetime import timedelta from datetime import timedelta

View File

@ -4,7 +4,7 @@ homeassistant.components.http
This module provides an API and a HTTP interface for debug purposes. This module provides an API and a HTTP interface for debug purposes.
For more details about the RESTful API, please refer to the documentation at For more details about the RESTful API, please refer to the documentation at
https://home-assistant.io/developers/api.html https://home-assistant.io/developers/api/
""" """
import json import json
import threading import threading
@ -12,10 +12,7 @@ import logging
import time import time
import gzip import gzip
import os import os
import random
import string
from datetime import timedelta from datetime import timedelta
from homeassistant.util import Throttle
from http.server import SimpleHTTPRequestHandler, HTTPServer from http.server import SimpleHTTPRequestHandler, HTTPServer
from http import cookies from http import cookies
from socketserver import ThreadingMixIn from socketserver import ThreadingMixIn
@ -34,7 +31,6 @@ import homeassistant.util.dt as date_util
import homeassistant.bootstrap as bootstrap import homeassistant.bootstrap as bootstrap
DOMAIN = "http" DOMAIN = "http"
DEPENDENCIES = []
CONF_API_PASSWORD = "api_password" CONF_API_PASSWORD = "api_password"
CONF_SERVER_HOST = "server_host" CONF_SERVER_HOST = "server_host"
@ -45,40 +41,30 @@ CONF_SESSIONS_ENABLED = "sessions_enabled"
DATA_API_PASSWORD = 'api_password' DATA_API_PASSWORD = 'api_password'
# Throttling time in seconds for expired sessions check # Throttling time in seconds for expired sessions check
MIN_SEC_SESSION_CLEARING = timedelta(seconds=20) SESSION_CLEAR_INTERVAL = timedelta(seconds=20)
SESSION_TIMEOUT_SECONDS = 1800 SESSION_TIMEOUT_SECONDS = 1800
SESSION_KEY = 'sessionId' SESSION_KEY = 'sessionId'
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
def setup(hass, config=None): def setup(hass, config):
""" Sets up the HTTP API and debug interface. """ """ Sets up the HTTP API and debug interface. """
if config is None or DOMAIN not in config: conf = config.get(DOMAIN, {})
config = {DOMAIN: {}}
api_password = util.convert(config[DOMAIN].get(CONF_API_PASSWORD), str) api_password = util.convert(conf.get(CONF_API_PASSWORD), str)
no_password_set = api_password is None
if no_password_set:
api_password = util.get_random_string()
# If no server host is given, accept all incoming requests # If no server host is given, accept all incoming requests
server_host = config[DOMAIN].get(CONF_SERVER_HOST, '0.0.0.0') server_host = conf.get(CONF_SERVER_HOST, '0.0.0.0')
server_port = conf.get(CONF_SERVER_PORT, SERVER_PORT)
server_port = config[DOMAIN].get(CONF_SERVER_PORT, SERVER_PORT) development = str(conf.get(CONF_DEVELOPMENT, "")) == "1"
development = str(config[DOMAIN].get(CONF_DEVELOPMENT, "")) == "1"
sessions_enabled = config[DOMAIN].get(CONF_SESSIONS_ENABLED, True)
try: try:
server = HomeAssistantHTTPServer( server = HomeAssistantHTTPServer(
(server_host, server_port), RequestHandler, hass, api_password, (server_host, server_port), RequestHandler, hass, api_password,
development, no_password_set, sessions_enabled) development)
except OSError: except OSError:
# Happens if address already in use # If address already in use
_LOGGER.exception("Error setting up HTTP server") _LOGGER.exception("Error setting up HTTP server")
return False return False
@ -103,17 +89,15 @@ class HomeAssistantHTTPServer(ThreadingMixIn, HTTPServer):
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def __init__(self, server_address, request_handler_class, def __init__(self, server_address, request_handler_class,
hass, api_password, development, no_password_set, hass, api_password, development):
sessions_enabled):
super().__init__(server_address, request_handler_class) super().__init__(server_address, request_handler_class)
self.server_address = server_address self.server_address = server_address
self.hass = hass self.hass = hass
self.api_password = api_password self.api_password = api_password
self.development = development self.development = development
self.no_password_set = no_password_set
self.paths = [] self.paths = []
self.sessions = SessionStore(sessions_enabled) self.sessions = SessionStore()
# We will lazy init this one if needed # We will lazy init this one if needed
self.event_forwarder = None self.event_forwarder = None
@ -162,12 +146,13 @@ class RequestHandler(SimpleHTTPRequestHandler):
def __init__(self, req, client_addr, server): def __init__(self, req, client_addr, server):
""" Contructor, call the base constructor and set up session """ """ Contructor, call the base constructor and set up session """
self._session = None # Track if this was an authenticated request
self.authenticated = False
SimpleHTTPRequestHandler.__init__(self, req, client_addr, server) SimpleHTTPRequestHandler.__init__(self, req, client_addr, server)
def log_message(self, fmt, *arguments): def log_message(self, fmt, *arguments):
""" Redirect built-in log to HA logging """ """ Redirect built-in log to HA logging """
if self.server.no_password_set: if self.server.api_password is None:
_LOGGER.info(fmt, *arguments) _LOGGER.info(fmt, *arguments)
else: else:
_LOGGER.info( _LOGGER.info(
@ -202,18 +187,17 @@ class RequestHandler(SimpleHTTPRequestHandler):
"Error parsing JSON", HTTP_UNPROCESSABLE_ENTITY) "Error parsing JSON", HTTP_UNPROCESSABLE_ENTITY)
return return
self._session = self.get_session() if self.server.api_password is None:
if self.server.no_password_set: self.authenticated = True
api_password = self.server.api_password elif HTTP_HEADER_HA_AUTH in self.headers:
else:
api_password = self.headers.get(HTTP_HEADER_HA_AUTH) api_password = self.headers.get(HTTP_HEADER_HA_AUTH)
if not api_password and DATA_API_PASSWORD in data: if not api_password and DATA_API_PASSWORD in data:
api_password = data[DATA_API_PASSWORD] api_password = data[DATA_API_PASSWORD]
if not api_password and self._session is not None: self.authenticated = api_password == self.server.api_password
api_password = self._session.cookie_values.get( else:
CONF_API_PASSWORD) self.authenticated = self.verify_session()
if '_METHOD' in data: if '_METHOD' in data:
method = data.pop('_METHOD') method = data.pop('_METHOD')
@ -246,16 +230,11 @@ class RequestHandler(SimpleHTTPRequestHandler):
# Did we find a handler for the incoming request? # Did we find a handler for the incoming request?
if handle_request_method: if handle_request_method:
# For some calls we need a valid password # For some calls we need a valid password
if require_auth and api_password != self.server.api_password: if require_auth and not self.authenticated:
self.write_json_message( self.write_json_message(
"API password missing or incorrect.", HTTP_UNAUTHORIZED) "API password missing or incorrect.", HTTP_UNAUTHORIZED)
return
else:
if self._session is None and require_auth:
self._session = self.server.sessions.create(
api_password)
handle_request_method(self, path_match, data) handle_request_method(self, path_match, data)
@ -308,18 +287,19 @@ class RequestHandler(SimpleHTTPRequestHandler):
json.dumps(data, indent=4, sort_keys=True, json.dumps(data, indent=4, sort_keys=True,
cls=rem.JSONEncoder).encode("UTF-8")) cls=rem.JSONEncoder).encode("UTF-8"))
def write_file(self, path): def write_file(self, path, cache_headers=True):
""" Returns a file to the user. """ """ Returns a file to the user. """
try: try:
with open(path, 'rb') as inp: with open(path, 'rb') as inp:
self.write_file_pointer(self.guess_type(path), inp) self.write_file_pointer(self.guess_type(path), inp,
cache_headers)
except IOError: except IOError:
self.send_response(HTTP_NOT_FOUND) self.send_response(HTTP_NOT_FOUND)
self.end_headers() self.end_headers()
_LOGGER.exception("Unable to serve %s", path) _LOGGER.exception("Unable to serve %s", path)
def write_file_pointer(self, content_type, inp): def write_file_pointer(self, content_type, inp, cache_headers=True):
""" """
Helper function to write a file pointer to the user. Helper function to write a file pointer to the user.
Does not do error handling. Does not do error handling.
@ -329,6 +309,7 @@ class RequestHandler(SimpleHTTPRequestHandler):
self.send_response(HTTP_OK) self.send_response(HTTP_OK)
self.send_header(HTTP_HEADER_CONTENT_TYPE, content_type) self.send_header(HTTP_HEADER_CONTENT_TYPE, content_type)
if cache_headers:
self.set_cache_header() self.set_cache_header()
self.set_session_cookie_header() self.set_session_cookie_header()
@ -356,7 +337,9 @@ class RequestHandler(SimpleHTTPRequestHandler):
def set_cache_header(self): def set_cache_header(self):
""" Add cache headers if not in development """ """ Add cache headers if not in development """
if not self.server.development: if self.server.development:
return
# 1 year in seconds # 1 year in seconds
cache_time = 365 * 86400 cache_time = 365 * 86400
@ -368,63 +351,67 @@ class RequestHandler(SimpleHTTPRequestHandler):
self.date_time_string(time.time()+cache_time)) self.date_time_string(time.time()+cache_time))
def set_session_cookie_header(self): def set_session_cookie_header(self):
""" Add the header for the session cookie """ """ Add the header for the session cookie and return session id. """
if self.server.sessions.enabled and self._session is not None: if not self.authenticated:
existing_sess_id = self.get_current_session_id() return
session_id = self.get_cookie_session_id()
if session_id is not None:
self.server.sessions.extend_validation(session_id)
return
if existing_sess_id != self._session.session_id:
self.send_header( self.send_header(
'Set-Cookie', 'Set-Cookie',
SESSION_KEY+'='+self._session.session_id) '{}={}'.format(SESSION_KEY, self.server.sessions.create())
)
def get_session(self): return session_id
""" Get the requested session object from cookie value """
if self.server.sessions.enabled is not True:
return None
session_id = self.get_current_session_id() def verify_session(self):
if session_id is not None: """ Verify that we are in a valid session. """
session = self.server.sessions.get(session_id) return self.get_cookie_session_id() is not None
if session is not None:
session.reset_expiry()
return session
return None def get_cookie_session_id(self):
def get_current_session_id(self):
""" """
Extracts the current session id from the Extracts the current session id from the
cookie or returns None if not set cookie or returns None if not set or invalid
""" """
if 'Cookie' not in self.headers:
return None
cookie = cookies.SimpleCookie() cookie = cookies.SimpleCookie()
try:
cookie.load(self.headers["Cookie"])
except cookies.CookieError:
return None
if self.headers.get('Cookie', None) is not None: morsel = cookie.get(SESSION_KEY)
cookie.load(self.headers.get("Cookie"))
if cookie.get(SESSION_KEY, False): if morsel is None:
return cookie[SESSION_KEY].value return None
session_id = cookie[SESSION_KEY].value
if self.server.sessions.is_valid(session_id):
return session_id
return None return None
def destroy_session(self):
""" Destroys session. """
session_id = self.get_cookie_session_id()
class ServerSession: if session_id is None:
""" A very simple session class """ return
def __init__(self, session_id):
""" Set up the expiry time on creation """
self._expiry = 0
self.reset_expiry()
self.cookie_values = {}
self.session_id = session_id
def reset_expiry(self): self.send_header('Set-Cookie', '')
""" Resets the expiry based on current time """ self.server.sessions.destroy(session_id)
self._expiry = date_util.utcnow() + timedelta(
seconds=SESSION_TIMEOUT_SECONDS)
@property
def is_expired(self): def session_valid_time():
""" Return true if the session is expired based on the expiry time """ """ Time till when a session will be valid. """
return self._expiry < date_util.utcnow() return date_util.utcnow() + timedelta(seconds=SESSION_TIMEOUT_SECONDS)
class SessionStore(object): class SessionStore(object):
@ -432,47 +419,42 @@ class SessionStore(object):
def __init__(self, enabled=True): def __init__(self, enabled=True):
""" Set up the session store """ """ Set up the session store """
self._sessions = {} self._sessions = {}
self.enabled = enabled self.lock = threading.RLock()
self.session_lock = threading.RLock()
@Throttle(MIN_SEC_SESSION_CLEARING) @util.Throttle(SESSION_CLEAR_INTERVAL)
def remove_expired(self): def _remove_expired(self):
""" Remove any expired sessions. """ """ Remove any expired sessions. """
if self.session_lock.acquire(False): now = date_util.utcnow()
try: for key in [key for key, valid_time in self._sessions.items()
keys = [] if valid_time < now]:
for key in self._sessions.keys(): self._sessions.pop(key)
keys.append(key)
for key in keys: def is_valid(self, key):
if self._sessions[key].is_expired: """ Return True if a valid session is given. """
del self._sessions[key] with self.lock:
_LOGGER.info("Cleared expired session %s", key) self._remove_expired()
finally:
self.session_lock.release()
def add(self, key, session): return (key in self._sessions and
""" Add a new session to the list of tracked sessions """ self._sessions[key] > date_util.utcnow())
self.remove_expired()
with self.session_lock:
self._sessions[key] = session
def get(self, key): def extend_validation(self, key):
""" get a session by key """ """ Extend a session validation time. """
self.remove_expired() with self.lock:
session = self._sessions.get(key, None) self._sessions[key] = session_valid_time()
if session is not None and session.is_expired:
return None
return session
def create(self, api_password): def destroy(self, key):
""" Creates a new session and adds it to the sessions """ """ Destroy a session by key. """
if self.enabled is not True: with self.lock:
return None self._sessions.pop(key, None)
chars = string.ascii_letters + string.digits def create(self):
session_id = ''.join([random.choice(chars) for i in range(20)]) """ Creates a new session. """
session = ServerSession(session_id) with self.lock:
session.cookie_values[CONF_API_PASSWORD] = api_password session_id = util.get_random_string(20)
self.add(session_id, session)
return session while session_id in self._sessions:
session_id = util.get_random_string(20)
self._sessions[session_id] = session_valid_time()
return session_id

View File

@ -4,7 +4,7 @@ homeassistant.components.ifttt
This component enable you to trigger Maker IFTTT recipes. This component enable you to trigger Maker IFTTT recipes.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/ifttt.html https://home-assistant.io/components/ifttt/
""" """
import logging import logging
import requests import requests
@ -22,13 +22,11 @@ ATTR_VALUE1 = 'value1'
ATTR_VALUE2 = 'value2' ATTR_VALUE2 = 'value2'
ATTR_VALUE3 = 'value3' ATTR_VALUE3 = 'value3'
DEPENDENCIES = []
REQUIREMENTS = ['pyfttt==0.3'] REQUIREMENTS = ['pyfttt==0.3']
def trigger(hass, event, value1=None, value2=None, value3=None): def trigger(hass, event, value1=None, value2=None, value3=None):
""" Trigger a Maker IFTTT recipe """ """ Trigger a Maker IFTTT recipe. """
data = { data = {
ATTR_EVENT: event, ATTR_EVENT: event,
ATTR_VALUE1: value1, ATTR_VALUE1: value1,
@ -39,7 +37,7 @@ def trigger(hass, event, value1=None, value2=None, value3=None):
def setup(hass, config): def setup(hass, config):
""" Setup the ifttt service component """ """ Setup the ifttt service component. """
if not validate_config(config, {DOMAIN: ['key']}, _LOGGER): if not validate_config(config, {DOMAIN: ['key']}, _LOGGER):
return False return False

View File

@ -4,12 +4,11 @@ homeassistant.components.introduction
Component that will help guide the user taking its first steps. Component that will help guide the user taking its first steps.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/introduction.html https://home-assistant.io/components/introduction/
""" """
import logging import logging
DOMAIN = 'introduction' DOMAIN = 'introduction'
DEPENDENCIES = []
def setup(hass, config=None): def setup(hass, config=None):

View File

@ -5,7 +5,7 @@ Connects to an ISY-994 controller and loads relevant components to control its
devices. Also contains the base classes for ISY Sensors, Lights, and Switches. devices. Also contains the base classes for ISY Sensors, Lights, and Switches.
For configuration details please visit the documentation for this component at For configuration details please visit the documentation for this component at
https://home-assistant.io/components/isy994.html https://home-assistant.io/components/isy994/
""" """
import logging import logging
from urllib.parse import urlparse from urllib.parse import urlparse
@ -20,7 +20,6 @@ from homeassistant.const import (
ATTR_FRIENDLY_NAME) ATTR_FRIENDLY_NAME)
DOMAIN = "isy994" DOMAIN = "isy994"
DEPENDENCIES = []
REQUIREMENTS = ['PyISY==1.0.5'] REQUIREMENTS = ['PyISY==1.0.5']
DISCOVER_LIGHTS = "isy994.lights" DISCOVER_LIGHTS = "isy994.lights"
DISCOVER_SWITCHES = "isy994.switches" DISCOVER_SWITCHES = "isy994.switches"
@ -117,7 +116,6 @@ class ISYDeviceABC(ToggleEntity):
def __init__(self, node): def __init__(self, node):
# setup properties # setup properties
self.node = node self.node = node
self.hidden = HIDDEN_STRING in self.raw_name
# track changes # track changes
self._change_handler = self.node.status. \ self._change_handler = self.node.status. \
@ -182,6 +180,11 @@ class ISYDeviceABC(ToggleEntity):
return self.raw_name.replace(HIDDEN_STRING, '').strip() \ return self.raw_name.replace(HIDDEN_STRING, '').strip() \
.replace('_', ' ') .replace('_', ' ')
@property
def hidden(self):
""" Suggestion if the entity should be hidden from UIs. """
return HIDDEN_STRING in self.raw_name
def update(self): def update(self):
""" Update state of the sensor. """ """ Update state of the sensor. """
# ISY objects are automatically updated by the ISY's event stream # ISY objects are automatically updated by the ISY's event stream

View File

@ -4,7 +4,7 @@ homeassistant.components.keyboard
Provides functionality to emulate keyboard presses on host machine. Provides functionality to emulate keyboard presses on host machine.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/keyboard.html https://home-assistant.io/components/keyboard/
""" """
import logging import logging
@ -15,7 +15,6 @@ from homeassistant.const import (
DOMAIN = "keyboard" DOMAIN = "keyboard"
DEPENDENCIES = []
REQUIREMENTS = ['pyuserinput==0.1.9'] REQUIREMENTS = ['pyuserinput==0.1.9']

View File

@ -1,61 +1,16 @@
""" """
homeassistant.components.light homeassistant.components.light
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides functionality to interact with lights. Provides functionality to interact with lights.
It offers the following services: For more details about this component, please refer to the documentation at
https://home-assistant.io/components/light/
TURN_OFF - Turns one or multiple lights off.
Supports following parameters:
- transition
Integer that represents the time the light should take to transition to
the new state.
- entity_id
String or list of strings that point at entity_ids of lights.
TURN_ON - Turns one or multiple lights on and change attributes.
Supports following parameters:
- transition
Integer that represents the time the light should take to transition to
the new state.
- entity_id
String or list of strings that point at entity_ids of lights.
- profile
String with the name of one of the built-in profiles (relax, energize,
concentrate, reading) or one of the custom profiles defined in
light_profiles.csv in the current working directory.
Light profiles define a xy color and a brightness.
If a profile is given and a brightness or xy color then the profile values
will be overwritten.
- xy_color
A list containing two floats representing the xy color you want the light
to be.
- rgb_color
A list containing three integers representing the xy color you want the
light to be.
- color_temp
An INT in mireds represending the color temperature you want the light to be
- brightness
Integer between 0 and 255 representing how bright you want the light to be.
""" """
import logging import logging
import os import os
import csv import csv
from homeassistant.components import group, discovery, wink, isy994 from homeassistant.components import group, discovery, wink, isy994, zwave
from homeassistant.config import load_yaml_config_file from homeassistant.config import load_yaml_config_file
from homeassistant.const import ( from homeassistant.const import (
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, ATTR_ENTITY_ID) STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, ATTR_ENTITY_ID)
@ -66,7 +21,6 @@ import homeassistant.util.color as color_util
DOMAIN = "light" DOMAIN = "light"
DEPENDENCIES = []
SCAN_INTERVAL = 30 SCAN_INTERVAL = 30
GROUP_NAME_ALL_LIGHTS = 'all lights' GROUP_NAME_ALL_LIGHTS = 'all lights'
@ -96,6 +50,7 @@ FLASH_LONG = "long"
# Apply an effect to the light, can be EFFECT_COLORLOOP # Apply an effect to the light, can be EFFECT_COLORLOOP
ATTR_EFFECT = "effect" ATTR_EFFECT = "effect"
EFFECT_COLORLOOP = "colorloop" EFFECT_COLORLOOP = "colorloop"
EFFECT_WHITE = "white"
LIGHT_PROFILES_FILE = "light_profiles.csv" LIGHT_PROFILES_FILE = "light_profiles.csv"
@ -104,12 +59,14 @@ DISCOVERY_PLATFORMS = {
wink.DISCOVER_LIGHTS: 'wink', wink.DISCOVER_LIGHTS: 'wink',
isy994.DISCOVER_LIGHTS: 'isy994', isy994.DISCOVER_LIGHTS: 'isy994',
discovery.SERVICE_HUE: 'hue', discovery.SERVICE_HUE: 'hue',
zwave.DISCOVER_LIGHTS: 'zwave',
} }
PROP_TO_ATTR = { PROP_TO_ATTR = {
'brightness': ATTR_BRIGHTNESS, 'brightness': ATTR_BRIGHTNESS,
'color_xy': ATTR_XY_COLOR,
'color_temp': ATTR_COLOR_TEMP, 'color_temp': ATTR_COLOR_TEMP,
'rgb_color': ATTR_RGB_COLOR,
'xy_color': ATTR_XY_COLOR,
} }
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -156,7 +113,7 @@ def turn_off(hass, entity_id=None, transition=None):
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data) hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
# pylint: disable=too-many-branches, too-many-locals # pylint: disable=too-many-branches, too-many-locals, too-many-statements
def setup(hass, config): def setup(hass, config):
""" Exposes light control via statemachine and services. """ """ Exposes light control via statemachine and services. """
@ -262,26 +219,17 @@ def setup(hass, config):
if len(rgb_color) == 3: if len(rgb_color) == 3:
params[ATTR_RGB_COLOR] = [int(val) for val in rgb_color] params[ATTR_RGB_COLOR] = [int(val) for val in rgb_color]
params[ATTR_XY_COLOR] = \
color_util.color_RGB_to_xy(int(rgb_color[0]),
int(rgb_color[1]),
int(rgb_color[2]))
except (TypeError, ValueError): except (TypeError, ValueError):
# TypeError if rgb_color is not iterable # TypeError if rgb_color is not iterable
# ValueError if not all values can be converted to int # ValueError if not all values can be converted to int
pass pass
if ATTR_FLASH in dat: if dat.get(ATTR_FLASH) in (FLASH_SHORT, FLASH_LONG):
if dat[ATTR_FLASH] == FLASH_SHORT: params[ATTR_FLASH] = dat[ATTR_FLASH]
params[ATTR_FLASH] = FLASH_SHORT
elif dat[ATTR_FLASH] == FLASH_LONG: if dat.get(ATTR_EFFECT) in (EFFECT_COLORLOOP, EFFECT_WHITE):
params[ATTR_FLASH] = FLASH_LONG params[ATTR_EFFECT] = dat[ATTR_EFFECT]
if ATTR_EFFECT in dat:
if dat[ATTR_EFFECT] == EFFECT_COLORLOOP:
params[ATTR_EFFECT] = EFFECT_COLORLOOP
for light in target_lights: for light in target_lights:
light.turn_on(**params) light.turn_on(**params)
@ -312,10 +260,15 @@ class Light(ToggleEntity):
return None return None
@property @property
def color_xy(self): def xy_color(self):
""" XY color value [float, float]. """ """ XY color value [float, float]. """
return None return None
@property
def rgb_color(self):
""" RGB color value [int, int, int] """
return None
@property @property
def color_temp(self): def color_temp(self):
""" CT color value in mirads. """ """ CT color value in mirads. """
@ -337,6 +290,12 @@ class Light(ToggleEntity):
if value: if value:
data[attr] = value data[attr] = value
if ATTR_RGB_COLOR not in data and ATTR_XY_COLOR in data and \
ATTR_BRIGHTNESS in data:
data[ATTR_RGB_COLOR] = color_util.color_xy_brightness_to_RGB(
data[ATTR_XY_COLOR][0], data[ATTR_XY_COLOR][1],
data[ATTR_BRIGHTNESS])
device_attr = self.device_state_attributes device_attr = self.device_state_attributes
if device_attr is not None: if device_attr is not None:

View File

@ -4,24 +4,23 @@ homeassistant.components.light.blinksticklight
Support for Blinkstick lights. Support for Blinkstick lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.blinksticklight.html https://home-assistant.io/components/light.blinksticklight/
""" """
import logging import logging
from blinkstick import blinkstick from homeassistant.components.light import Light, ATTR_RGB_COLOR
from homeassistant.components.light import (Light, ATTR_RGB_COLOR)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ["blinkstick==1.1.7"] REQUIREMENTS = ["blinkstick==1.1.7"]
DEPENDENCIES = []
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Add device specified by serial number. """ """ Add device specified by serial number. """
from blinkstick import blinkstick
stick = blinkstick.find_by_serial(config['serial']) stick = blinkstick.find_by_serial(config['serial'])
add_devices_callback([BlinkStickLight(stick, config['name'])]) add_devices_callback([BlinkStickLight(stick, config['name'])])

View File

@ -1,40 +1,39 @@
""" """
homeassistant.components.light.demo homeassistant.components.light.demo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo platform that implements lights. Demo platform that implements lights.
""" """
import random import random
from homeassistant.components.light import ( from homeassistant.components.light import (
Light, ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_COLOR_TEMP) Light, ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_COLOR_TEMP)
LIGHT_COLORS = [ LIGHT_COLORS = [
[0.368, 0.180], [237, 224, 33],
[0.460, 0.470], [255, 63, 111],
] ]
LIGHT_TEMPS = [160, 500] LIGHT_TEMPS = [240, 380]
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return demo lights. """ """ Find and return demo lights. """
add_devices_callback([ add_devices_callback([
DemoLight("Bed Light", False), DemoLight("Bed Light", False),
DemoLight("Ceiling Lights", True, LIGHT_TEMPS[1], LIGHT_COLORS[0]), DemoLight("Ceiling Lights", True, LIGHT_COLORS[0], LIGHT_TEMPS[1]),
DemoLight("Kitchen Lights", True, LIGHT_TEMPS[0], LIGHT_COLORS[1]) DemoLight("Kitchen Lights", True, LIGHT_COLORS[1], LIGHT_TEMPS[0])
]) ])
class DemoLight(Light): class DemoLight(Light):
""" Provides a demo switch. """ """ Provides a demo switch. """
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def __init__(self, name, state, xy=None, ct=None, brightness=180): def __init__(self, name, state, rgb=None, ct=None, brightness=180):
self._name = name self._name = name
self._state = state self._state = state
self._xy = xy or random.choice(LIGHT_COLORS) self._rgb = rgb or random.choice(LIGHT_COLORS)
self._ct = ct or random.choice(LIGHT_TEMPS) self._ct = ct or random.choice(LIGHT_TEMPS)
self._brightness = brightness self._brightness = brightness
@ -54,9 +53,9 @@ class DemoLight(Light):
return self._brightness return self._brightness
@property @property
def color_xy(self): def rgb_color(self):
""" XY color value. """ """ rgb color value. """
return self._xy return self._rgb
@property @property
def color_temp(self): def color_temp(self):
@ -72,8 +71,8 @@ class DemoLight(Light):
""" Turn the device on. """ """ Turn the device on. """
self._state = True self._state = True
if ATTR_XY_COLOR in kwargs: if ATTR_RGB_COLOR in kwargs:
self._xy = kwargs[ATTR_XY_COLOR] self._rgb = kwargs[ATTR_RGB_COLOR]
if ATTR_COLOR_TEMP in kwargs: if ATTR_COLOR_TEMP in kwargs:
self._ct = kwargs[ATTR_COLOR_TEMP] self._ct = kwargs[ATTR_COLOR_TEMP]

View File

@ -3,20 +3,24 @@ homeassistant.components.light.hue
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Hue lights. Support for Hue lights.
https://home-assistant.io/components/light.hue.html For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.hue/
""" """
import json
import logging import logging
import os
import socket import socket
from datetime import timedelta from datetime import timedelta
from urllib.parse import urlparse from urllib.parse import urlparse
from homeassistant.loader import get_component from homeassistant.loader import get_component
import homeassistant.util as util import homeassistant.util as util
import homeassistant.util.color as color_util
from homeassistant.const import CONF_HOST, DEVICE_DEFAULT_NAME from homeassistant.const import CONF_HOST, DEVICE_DEFAULT_NAME
from homeassistant.components.light import ( from homeassistant.components.light import (
Light, ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_COLOR_TEMP, Light, ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_COLOR_TEMP,
ATTR_TRANSITION, ATTR_FLASH, FLASH_LONG, FLASH_SHORT, ATTR_TRANSITION, ATTR_FLASH, FLASH_LONG, FLASH_SHORT,
ATTR_EFFECT, EFFECT_COLORLOOP) ATTR_EFFECT, EFFECT_COLORLOOP, ATTR_RGB_COLOR)
REQUIREMENTS = ['phue==0.8'] REQUIREMENTS = ['phue==0.8']
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10) MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
@ -30,21 +34,37 @@ _CONFIGURING = {}
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
def _find_host_from_config(hass):
""" Attempt to detect host based on existing configuration. """
path = hass.config.path(PHUE_CONFIG_FILE)
if not os.path.isfile(path):
return None
try:
with open(path) as inp:
return next(json.loads(''.join(inp)).keys().__iter__())
except (ValueError, AttributeError, StopIteration):
# ValueError if can't parse as JSON
# AttributeError if JSON value is not a dict
# StopIteration if no keys
return None
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Gets the Hue lights. """ """ Gets the Hue lights. """
try:
# pylint: disable=unused-variable
import phue # noqa
except ImportError:
_LOGGER.exception("Error while importing dependency phue.")
return
if discovery_info is not None: if discovery_info is not None:
host = urlparse(discovery_info[1]).hostname host = urlparse(discovery_info[1]).hostname
else: else:
host = config.get(CONF_HOST, None) host = config.get(CONF_HOST, None)
if host is None:
host = _find_host_from_config(hass)
if host is None:
_LOGGER.error('No host found in configuration')
return False
# Only act if we are not already configuring this host # Only act if we are not already configuring this host
if host in _CONFIGURING: if host in _CONFIGURING:
return return
@ -165,7 +185,7 @@ class HueLight(Light):
return self.info['state']['bri'] return self.info['state']['bri']
@property @property
def color_xy(self): def xy_color(self):
""" XY color value. """ """ XY color value. """
return self.info['state'].get('xy') return self.info['state'].get('xy')
@ -186,15 +206,16 @@ class HueLight(Light):
command = {'on': True} command = {'on': True}
if ATTR_TRANSITION in kwargs: if ATTR_TRANSITION in kwargs:
# Transition time is in 1/10th seconds and cannot exceed command['transitiontime'] = kwargs[ATTR_TRANSITION] * 10
# 900 seconds.
command['transitiontime'] = min(9000, kwargs[ATTR_TRANSITION] * 10)
if ATTR_BRIGHTNESS in kwargs: if ATTR_BRIGHTNESS in kwargs:
command['bri'] = kwargs[ATTR_BRIGHTNESS] command['bri'] = kwargs[ATTR_BRIGHTNESS]
if ATTR_XY_COLOR in kwargs: if ATTR_XY_COLOR in kwargs:
command['xy'] = kwargs[ATTR_XY_COLOR] command['xy'] = kwargs[ATTR_XY_COLOR]
elif ATTR_RGB_COLOR in kwargs:
command['xy'] = color_util.color_RGB_to_xy(
*(int(val) for val in kwargs[ATTR_RGB_COLOR]))
if ATTR_COLOR_TEMP in kwargs: if ATTR_COLOR_TEMP in kwargs:
command['ct'] = kwargs[ATTR_COLOR_TEMP] command['ct'] = kwargs[ATTR_COLOR_TEMP]

View File

@ -3,7 +3,8 @@ homeassistant.components.light.hyperion
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Hyperion remotes. Support for Hyperion remotes.
https://home-assistant.io/components/light.hyperion.html For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.hyperion/
""" """
import logging import logging
import socket import socket

View File

@ -2,6 +2,9 @@
homeassistant.components.light.isy994 homeassistant.components.light.isy994
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for ISY994 lights. Support for ISY994 lights.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/isy994/
""" """
import logging import logging

View File

@ -1,179 +1,284 @@
""" """
homeassistant.components.light.limitlessled homeassistant.components.light.limitlessled
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for LimitlessLED bulbs.
Support for LimitlessLED bulbs, also known as... For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.limitlessled/
- EasyBulb
- AppLight
- AppLamp
- MiLight
- LEDme
- dekolight
- iLight
https://home-assistant.io/components/light.limitlessled.html
""" """
import logging import logging
from homeassistant.const import DEVICE_DEFAULT_NAME
from homeassistant.components.light import (Light, ATTR_BRIGHTNESS, from homeassistant.components.light import (Light, ATTR_BRIGHTNESS,
ATTR_XY_COLOR) ATTR_RGB_COLOR, ATTR_EFFECT,
from homeassistant.util.color import color_RGB_to_xy ATTR_COLOR_TEMP, ATTR_TRANSITION,
ATTR_FLASH, FLASH_LONG,
EFFECT_COLORLOOP, EFFECT_WHITE)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['ledcontroller==1.1.0'] REQUIREMENTS = ['limitlessled==1.0.0']
RGB_BOUNDARY = 40
DEFAULT_TRANSITION = 0
DEFAULT_PORT = 8899
DEFAULT_VERSION = 5
DEFAULT_LED_TYPE = 'rgbw'
WHITE = [255, 255, 255]
def rewrite_legacy(config):
""" Rewrite legacy configuration to new format. """
bridges = config.get('bridges', [config])
new_bridges = []
for bridge_conf in bridges:
groups = []
if 'groups' in bridge_conf:
groups = bridge_conf['groups']
else:
_LOGGER.warning("Legacy configuration format detected")
for i in range(1, 5):
name_key = 'group_%d_name' % i
if name_key in bridge_conf:
groups.append({
'number': i,
'type': bridge_conf.get('group_%d_type' % i,
DEFAULT_LED_TYPE),
'name': bridge_conf.get(name_key)
})
new_bridges.append({
'host': bridge_conf.get('host'),
'groups': groups
})
return {'bridges': new_bridges}
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Gets the LimitlessLED lights. """ """ Gets the LimitlessLED lights. """
import ledcontroller from limitlessled.bridge import Bridge
# Handle old configuration format: # Two legacy configuration formats are supported to
bridges = config.get('bridges', [config]) # maintain backwards compatibility.
config = rewrite_legacy(config)
for bridge_id, bridge in enumerate(bridges):
bridge['id'] = bridge_id
pool = ledcontroller.LedControllerPool([x['host'] for x in bridges])
# Use the expanded configuration format.
lights = [] lights = []
for bridge in bridges: for bridge_conf in config.get('bridges'):
for i in range(1, 5): bridge = Bridge(bridge_conf.get('host'),
name_key = 'group_%d_name' % i port=bridge_conf.get('port', DEFAULT_PORT),
if name_key in bridge: version=bridge_conf.get('version', DEFAULT_VERSION))
group_type = bridge.get('group_%d_type' % i, 'rgbw') for group_conf in bridge_conf.get('groups'):
lights.append(LimitlessLED.factory(pool, bridge['id'], i, group = bridge.add_group(group_conf.get('number'),
bridge[name_key], group_conf.get('name'),
group_type)) group_conf.get('type', DEFAULT_LED_TYPE))
lights.append(LimitlessLEDGroup.factory(group))
add_devices_callback(lights) add_devices_callback(lights)
class LimitlessLED(Light): def state(new_state):
""" Represents a LimitlessLED light """ """ State decorator.
Specify True (turn on) or False (turn off).
"""
def decorator(function):
""" Decorator function. """
# pylint: disable=no-member,protected-access
def wrapper(self, **kwargs):
""" Wrap a group state change. """
from limitlessled.pipeline import Pipeline
pipeline = Pipeline()
transition_time = DEFAULT_TRANSITION
# Stop any repeating pipeline.
if self.repeating:
self.repeating = False
self.group.stop()
# Not on and should be? Turn on.
if not self.is_on and new_state is True:
pipeline.on()
# Set transition time.
if ATTR_TRANSITION in kwargs:
transition_time = kwargs[ATTR_TRANSITION]
# Do group type-specific work.
function(self, transition_time, pipeline, **kwargs)
# Update state.
self._is_on = new_state
self.group.enqueue(pipeline)
self.update_ha_state()
return wrapper
return decorator
class LimitlessLEDGroup(Light):
""" LimitessLED group. """
def __init__(self, group):
""" Initialize a group. """
self.group = group
self.repeating = False
self._is_on = False
self._brightness = None
@staticmethod @staticmethod
def factory(pool, controller_id, group, name, group_type): def factory(group):
''' Construct a Limitless LED of the appropriate type ''' """ Produce LimitlessLEDGroup objects. """
if group_type == 'white': from limitlessled.group.rgbw import RgbwGroup
return WhiteLimitlessLED(pool, controller_id, group, name) from limitlessled.group.white import WhiteGroup
elif group_type == 'rgbw': if isinstance(group, WhiteGroup):
return RGBWLimitlessLED(pool, controller_id, group, name) return LimitlessLEDWhiteGroup(group)
elif isinstance(group, RgbwGroup):
# pylint: disable=too-many-arguments return LimitlessLEDRGBWGroup(group)
def __init__(self, pool, controller_id, group, name, group_type):
self.pool = pool
self.controller_id = controller_id
self.group = group
self.pool.execute(self.controller_id, "set_group_type", self.group,
group_type)
# LimitlessLEDs don't report state, we have track it ourselves.
self.pool.execute(self.controller_id, "off", self.group)
self._name = name or DEVICE_DEFAULT_NAME
self._state = False
@property @property
def should_poll(self): def should_poll(self):
""" No polling needed. """ """ No polling needed.
LimitlessLED state cannot be fetched.
"""
return False return False
@property @property
def name(self): def name(self):
""" Returns the name of the device if any. """ """ Returns the name of the group. """
return self._name return self.group.name
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """ True if device is on. """
return self._state return self._is_on
def turn_off(self, **kwargs):
""" Turn the device off. """
self._state = False
self.pool.execute(self.controller_id, "off", self.group)
self.update_ha_state()
class RGBWLimitlessLED(LimitlessLED):
""" Represents a RGBW LimitlessLED light """
def __init__(self, pool, controller_id, group, name):
super().__init__(pool, controller_id, group, name, 'rgbw')
self._brightness = 100
self._xy_color = color_RGB_to_xy(255, 255, 255)
# Build a color table that maps an RGB color to a color string
# recognized by LedController's set_color method
self._color_table = [(color_RGB_to_xy(*x[0]), x[1]) for x in [
((0xFF, 0xFF, 0xFF), 'white'),
((0xEE, 0x82, 0xEE), 'violet'),
((0x41, 0x69, 0xE1), 'royal_blue'),
((0x87, 0xCE, 0xFA), 'baby_blue'),
((0x00, 0xFF, 0xFF), 'aqua'),
((0x7F, 0xFF, 0xD4), 'royal_mint'),
((0x2E, 0x8B, 0x57), 'seafoam_green'),
((0x00, 0x80, 0x00), 'green'),
((0x32, 0xCD, 0x32), 'lime_green'),
((0xFF, 0xFF, 0x00), 'yellow'),
((0xDA, 0xA5, 0x20), 'yellow_orange'),
((0xFF, 0xA5, 0x00), 'orange'),
((0xFF, 0x00, 0x00), 'red'),
((0xFF, 0xC0, 0xCB), 'pink'),
((0xFF, 0x00, 0xFF), 'fusia'),
((0xDA, 0x70, 0xD6), 'lilac'),
((0xE6, 0xE6, 0xFA), 'lavendar'),
]]
@property @property
def brightness(self): def brightness(self):
""" Brightness property. """
return self._brightness return self._brightness
@state(False)
def turn_off(self, transition_time, pipeline, **kwargs):
""" Turn off a group. """
if self.is_on:
pipeline.transition(transition_time, brightness=0.0).off()
class LimitlessLEDWhiteGroup(LimitlessLEDGroup):
""" LimitlessLED White group. """
def __init__(self, group):
""" Initialize White group. """
super().__init__(group)
# Initialize group with known values.
self.group.on = True
self.group.temperature = 1.0
self.group.brightness = 0.0
self._brightness = _to_hass_brightness(1.0)
self._temperature = _to_hass_temperature(self.group.temperature)
self.group.on = False
@property @property
def color_xy(self): def color_temp(self):
return self._xy_color """ Temperature property. """
return self._temperature
def _xy_to_led_color(self, xy_color):
""" Convert an XY color to the closest LedController color string. """
def abs_dist_squared(p_0, p_1):
""" Returns the absolute value of the squared distance """
return abs((p_0[0] - p_1[0])**2 + (p_0[1] - p_1[1])**2)
candidates = [(abs_dist_squared(xy_color, x[0]), x[1]) for x in
self._color_table]
# First candidate in the sorted list is closest to desired color:
return sorted(candidates)[0][1]
def turn_on(self, **kwargs):
""" Turn the device on. """
self._state = True
@state(True)
def turn_on(self, transition_time, pipeline, **kwargs):
""" Turn on (or adjust property of) a group. """
# Check arguments.
if ATTR_BRIGHTNESS in kwargs: if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs[ATTR_BRIGHTNESS] self._brightness = kwargs[ATTR_BRIGHTNESS]
if ATTR_COLOR_TEMP in kwargs:
if ATTR_XY_COLOR in kwargs: self._temperature = kwargs[ATTR_COLOR_TEMP]
self._xy_color = kwargs[ATTR_XY_COLOR] # Set up transition.
pipeline.transition(transition_time,
self.pool.execute(self.controller_id, "set_color", brightness=_from_hass_brightness(
self._xy_to_led_color(self._xy_color), self.group) self._brightness),
self.pool.execute(self.controller_id, "set_brightness", temperature=_from_hass_temperature(
self._brightness / 255.0, self.group) self._temperature))
self.update_ha_state()
class WhiteLimitlessLED(LimitlessLED): class LimitlessLEDRGBWGroup(LimitlessLEDGroup):
""" Represents a White LimitlessLED light """ """ LimitlessLED RGBW group. """
def __init__(self, group):
""" Initialize RGBW group. """
super().__init__(group)
# Initialize group with known values.
self.group.on = True
self.group.white()
self._color = WHITE
self.group.brightness = 0.0
self._brightness = _to_hass_brightness(1.0)
self.group.on = False
def __init__(self, pool, controller_id, group, name): @property
super().__init__(pool, controller_id, group, name, 'white') def rgb_color(self):
""" Color property. """
return self._color
def turn_on(self, **kwargs): @state(True)
""" Turn the device on. """ def turn_on(self, transition_time, pipeline, **kwargs):
self._state = True """ Turn on (or adjust property of) a group. """
self.pool.execute(self.controller_id, "on", self.group) from limitlessled.presets import COLORLOOP
self.update_ha_state() # Check arguments.
if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs[ATTR_BRIGHTNESS]
if ATTR_RGB_COLOR in kwargs:
self._color = kwargs[ATTR_RGB_COLOR]
# White is a special case.
if min(self._color) > 256 - RGB_BOUNDARY:
pipeline.white()
self._color = WHITE
# Set up transition.
pipeline.transition(transition_time,
brightness=_from_hass_brightness(
self._brightness),
color=_from_hass_color(self._color))
# Flash.
if ATTR_FLASH in kwargs:
duration = 0
if kwargs[ATTR_FLASH] == FLASH_LONG:
duration = 1
pipeline.flash(duration=duration)
# Add effects.
if ATTR_EFFECT in kwargs:
if kwargs[ATTR_EFFECT] == EFFECT_COLORLOOP:
self.repeating = True
pipeline.append(COLORLOOP)
if kwargs[ATTR_EFFECT] == EFFECT_WHITE:
pipeline.white()
self._color = WHITE
def _from_hass_temperature(temperature):
""" Convert Home Assistant color temperature
units to percentage.
"""
return (temperature - 154) / 346
def _to_hass_temperature(temperature):
""" Convert percentage to Home Assistant
color temperature units.
"""
return int(temperature * 346) + 154
def _from_hass_brightness(brightness):
""" Convert Home Assistant brightness units
to percentage.
"""
return brightness / 255
def _to_hass_brightness(brightness):
""" Convert percentage to Home Assistant
brightness units.
"""
return int(brightness * 255)
def _from_hass_color(color):
""" Convert Home Assistant RGB list
to Color tuple.
"""
from limitlessled import Color
return Color(*tuple(color))
def _to_hass_color(color):
""" Convert from Color tuple to
Home Assistant RGB list.
"""
return list([int(c) for c in color])

View File

@ -0,0 +1,175 @@
"""
homeassistant.components.light.mqtt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to configure a MQTT light.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.mqtt/
"""
import logging
import homeassistant.components.mqtt as mqtt
from homeassistant.components.light import (Light,
ATTR_BRIGHTNESS, ATTR_RGB_COLOR)
_LOGGER = logging.getLogger(__name__)
DEFAULT_NAME = "MQTT Light"
DEFAULT_QOS = 0
DEFAULT_PAYLOAD_ON = "on"
DEFAULT_PAYLOAD_OFF = "off"
DEFAULT_OPTIMISTIC = False
DEPENDENCIES = ['mqtt']
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Add MQTT Light. """
if config.get('command_topic') is None:
_LOGGER.error("Missing required variable: command_topic")
return False
add_devices_callback([MqttLight(
hass,
config.get('name', DEFAULT_NAME),
{
"state_topic": config.get('state_topic'),
"command_topic": config.get('command_topic'),
"brightness_state_topic": config.get('brightness_state_topic'),
"brightness_command_topic": config.get('brightness_command_topic'),
"rgb_state_topic": config.get('rgb_state_topic'),
"rgb_command_topic": config.get('rgb_command_topic')
},
config.get('qos', DEFAULT_QOS),
{
"on": config.get('payload_on', DEFAULT_PAYLOAD_ON),
"off": config.get('payload_off', DEFAULT_PAYLOAD_OFF)
},
config.get('optimistic', DEFAULT_OPTIMISTIC))])
class MqttLight(Light):
""" Provides a MQTT light. """
# pylint: disable=too-many-arguments,too-many-instance-attributes
def __init__(self, hass, name, topic, qos, payload, optimistic):
self._hass = hass
self._name = name
self._topic = topic
self._qos = qos
self._payload = payload
self._optimistic = optimistic or topic["state_topic"] is None
self._optimistic_rgb = optimistic or topic["rgb_state_topic"] is None
self._optimistic_brightness = (optimistic or
topic["brightness_state_topic"] is None)
self._state = False
def state_received(topic, payload, qos):
""" A new MQTT message has been received. """
if payload == self._payload["on"]:
self._state = True
elif payload == self._payload["off"]:
self._state = False
self.update_ha_state()
if self._topic["state_topic"] is not None:
mqtt.subscribe(self._hass, self._topic["state_topic"],
state_received, self._qos)
def brightness_received(topic, payload, qos):
""" A new MQTT message for the brightness has been received. """
self._brightness = int(payload)
self.update_ha_state()
if self._topic["brightness_state_topic"] is not None:
mqtt.subscribe(self._hass, self._topic["brightness_state_topic"],
brightness_received, self._qos)
self._brightness = 255
else:
self._brightness = None
def rgb_received(topic, payload, qos):
""" A new MQTT message has been received. """
self._rgb = [int(val) for val in payload.split(',')]
self.update_ha_state()
if self._topic["rgb_state_topic"] is not None:
mqtt.subscribe(self._hass, self._topic["rgb_state_topic"],
rgb_received, self._qos)
self._rgb = [255, 255, 255]
else:
self._rgb = None
@property
def brightness(self):
""" Brightness of this light between 0..255. """
return self._brightness
@property
def rgb_color(self):
""" RGB color value. """
return self._rgb
@property
def should_poll(self):
""" No polling needed for a MQTT light. """
return False
@property
def name(self):
""" Returns the name of the device if any. """
return self._name
@property
def is_on(self):
""" True if device is on. """
return self._state
def turn_on(self, **kwargs):
""" Turn the device on. """
should_update = False
if ATTR_RGB_COLOR in kwargs and \
self._topic["rgb_command_topic"] is not None:
mqtt.publish(self._hass, self._topic["rgb_command_topic"],
"{},{},{}".format(*kwargs[ATTR_RGB_COLOR]), self._qos)
if self._optimistic_rgb:
self._rgb = kwargs[ATTR_RGB_COLOR]
should_update = True
if ATTR_BRIGHTNESS in kwargs and \
self._topic["brightness_command_topic"] is not None:
mqtt.publish(self._hass, self._topic["brightness_command_topic"],
kwargs[ATTR_BRIGHTNESS], self._qos)
if self._optimistic_brightness:
self._brightness = kwargs[ATTR_BRIGHTNESS]
should_update = True
mqtt.publish(self._hass, self._topic["command_topic"],
self._payload["on"], self._qos)
if self._optimistic:
# optimistically assume that switch has changed state
self._state = True
should_update = True
if should_update:
self.update_ha_state()
def turn_off(self, **kwargs):
""" Turn the device off. """
mqtt.publish(self._hass, self._topic["command_topic"],
self._payload["off"], self._qos)
if self._optimistic:
# optimistically assume that switch has changed state
self._state = False
self.update_ha_state()

View File

@ -4,15 +4,19 @@ homeassistant.components.light.rfxtrx
Support for RFXtrx lights. Support for RFXtrx lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.rfxtrx.html https://home-assistant.io/components/light.rfxtrx/
""" """
import logging import logging
import homeassistant.components.rfxtrx as rfxtrx import homeassistant.components.rfxtrx as rfxtrx
import RFXtrx as rfxtrxmod
from homeassistant.components.light import Light from homeassistant.components.light import Light
from homeassistant.util import slugify from homeassistant.util import slugify
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.components.rfxtrx import ATTR_STATE, ATTR_FIREEVENT, ATTR_PACKETID, \
ATTR_NAME, EVENT_BUTTON_PRESSED
DEPENDENCIES = ['rfxtrx'] DEPENDENCIES = ['rfxtrx']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -20,14 +24,24 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Setup the RFXtrx platform. """ """ Setup the RFXtrx platform. """
import RFXtrx as rfxtrxmod
lights = [] lights = []
devices = config.get('devices', None) devices = config.get('devices', None)
if devices: if devices:
for entity_id, entity_info in devices.items(): for entity_id, entity_info in devices.items():
if entity_id not in rfxtrx.RFX_DEVICES: if entity_id not in rfxtrx.RFX_DEVICES:
_LOGGER.info("Add %s rfxtrx.light", entity_info['name']) _LOGGER.info("Add %s rfxtrx.light", entity_info[ATTR_NAME])
rfxobject = rfxtrx.get_rfx_object(entity_info['packetid'])
new_light = RfxtrxLight(entity_info['name'], rfxobject, False) # Check if i must fire event
fire_event = entity_info.get(ATTR_FIREEVENT, False)
datas = {ATTR_STATE: False, ATTR_FIREEVENT: fire_event}
rfxobject = rfxtrx.get_rfx_object(entity_info[ATTR_PACKETID])
new_light = RfxtrxLight(
entity_info[ATTR_NAME], rfxobject, datas
)
rfxtrx.RFX_DEVICES[entity_id] = new_light rfxtrx.RFX_DEVICES[entity_id] = new_light
lights.append(new_light) lights.append(new_light)
@ -53,18 +67,37 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
) )
pkt_id = "".join("{0:02x}".format(x) for x in event.data) pkt_id = "".join("{0:02x}".format(x) for x in event.data)
entity_name = "%s : %s" % (entity_id, pkt_id) entity_name = "%s : %s" % (entity_id, pkt_id)
new_light = RfxtrxLight(entity_name, event, False) datas = {ATTR_STATE: False, ATTR_FIREEVENT: False}
new_light = RfxtrxLight(entity_name, event, datas)
rfxtrx.RFX_DEVICES[entity_id] = new_light rfxtrx.RFX_DEVICES[entity_id] = new_light
add_devices_callback([new_light]) add_devices_callback([new_light])
# Check if entity exists or previously added automatically # Check if entity exists or previously added automatically
if entity_id in rfxtrx.RFX_DEVICES: if entity_id in rfxtrx.RFX_DEVICES \
and isinstance(rfxtrx.RFX_DEVICES[entity_id], RfxtrxLight):
_LOGGER.debug(
"EntityID: %s light_update. Command: %s",
entity_id,
event.values['Command']
)
if event.values['Command'] == 'On'\ if event.values['Command'] == 'On'\
or event.values['Command'] == 'Off': or event.values['Command'] == 'Off':
if event.values['Command'] == 'On':
rfxtrx.RFX_DEVICES[entity_id].turn_on() # Update the rfxtrx device state
else: is_on = event.values['Command'] == 'On'
rfxtrx.RFX_DEVICES[entity_id].turn_off() # pylint: disable=protected-access
rfxtrx.RFX_DEVICES[entity_id]._state = is_on
rfxtrx.RFX_DEVICES[entity_id].update_ha_state()
# Fire event
if rfxtrx.RFX_DEVICES[entity_id].should_fire_event:
rfxtrx.RFX_DEVICES[entity_id].hass.bus.fire(
EVENT_BUTTON_PRESSED, {
ATTR_ENTITY_ID:
rfxtrx.RFX_DEVICES[entity_id].entity_id,
ATTR_STATE: event.values['Command'].lower()
}
)
# Subscribe to main rfxtrx events # Subscribe to main rfxtrx events
if light_update not in rfxtrx.RECEIVED_EVT_SUBSCRIBERS: if light_update not in rfxtrx.RECEIVED_EVT_SUBSCRIBERS:
@ -73,10 +106,11 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class RfxtrxLight(Light): class RfxtrxLight(Light):
""" Provides a RFXtrx light. """ """ Provides a RFXtrx light. """
def __init__(self, name, event, state): def __init__(self, name, event, datas):
self._name = name self._name = name
self._event = event self._event = event
self._state = state self._state = datas[ATTR_STATE]
self._should_fire_event = datas[ATTR_FIREEVENT]
@property @property
def should_poll(self): def should_poll(self):
@ -88,6 +122,11 @@ class RfxtrxLight(Light):
""" Returns the name of the light if any. """ """ Returns the name of the light if any. """
return self._name return self._name
@property
def should_fire_event(self):
""" Returns is the device must fire event"""
return self._should_fire_event
@property @property
def is_on(self): def is_on(self):
""" True if light is on. """ """ True if light is on. """

View File

@ -4,37 +4,32 @@ homeassistant.components.light.tellstick
Support for Tellstick lights. Support for Tellstick lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.tellstick.html https://home-assistant.io/components/light.tellstick/
""" """
import logging
# pylint: disable=no-name-in-module, import-error
from homeassistant.components.light import Light, ATTR_BRIGHTNESS from homeassistant.components.light import Light, ATTR_BRIGHTNESS
from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, from homeassistant.const import (EVENT_HOMEASSISTANT_STOP,
ATTR_FRIENDLY_NAME) ATTR_FRIENDLY_NAME)
import tellcore.constants as tellcore_constants
from tellcore.library import DirectCallbackDispatcher
REQUIREMENTS = ['tellcore-py==1.1.2'] REQUIREMENTS = ['tellcore-py==1.1.2']
SIGNAL_REPETITIONS = 1
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return Tellstick lights. """ """ Find and return Tellstick lights. """
try:
import tellcore.telldus as telldus import tellcore.telldus as telldus
except ImportError: from tellcore.library import DirectCallbackDispatcher
logging.getLogger(__name__).exception( import tellcore.constants as tellcore_constants
"Failed to import tellcore")
return []
core = telldus.TelldusCore(callback_dispatcher=DirectCallbackDispatcher()) core = telldus.TelldusCore(callback_dispatcher=DirectCallbackDispatcher())
signal_repetitions = config.get('signal_repetitions', SIGNAL_REPETITIONS)
switches_and_lights = core.devices() switches_and_lights = core.devices()
lights = [] lights = []
for switch in switches_and_lights: for switch in switches_and_lights:
if switch.methods(tellcore_constants.TELLSTICK_DIM): if switch.methods(tellcore_constants.TELLSTICK_DIM):
lights.append(TellstickLight(switch)) lights.append(TellstickLight(switch, signal_repetitions))
def _device_event_callback(id_, method, data, cid): def _device_event_callback(id_, method, data, cid):
""" Called from the TelldusCore library to update one device """ """ Called from the TelldusCore library to update one device """
@ -58,16 +53,21 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class TellstickLight(Light): class TellstickLight(Light):
""" Represents a Tellstick light. """ """ Represents a Tellstick light. """
last_sent_command_mask = (tellcore_constants.TELLSTICK_TURNON |
def __init__(self, tellstick_device, signal_repetitions):
import tellcore.constants as tellcore_constants
self.tellstick_device = tellstick_device
self.state_attr = {ATTR_FRIENDLY_NAME: tellstick_device.name}
self.signal_repetitions = signal_repetitions
self._brightness = 0
self.last_sent_command_mask = (tellcore_constants.TELLSTICK_TURNON |
tellcore_constants.TELLSTICK_TURNOFF | tellcore_constants.TELLSTICK_TURNOFF |
tellcore_constants.TELLSTICK_DIM | tellcore_constants.TELLSTICK_DIM |
tellcore_constants.TELLSTICK_UP | tellcore_constants.TELLSTICK_UP |
tellcore_constants.TELLSTICK_DOWN) tellcore_constants.TELLSTICK_DOWN)
self.update()
def __init__(self, tellstick_device):
self.tellstick_device = tellstick_device
self.state_attr = {ATTR_FRIENDLY_NAME: tellstick_device.name}
self._brightness = 0
@property @property
def name(self): def name(self):
@ -86,6 +86,7 @@ class TellstickLight(Light):
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turns the switch off. """ """ Turns the switch off. """
for _ in range(self.signal_repetitions):
self.tellstick_device.turn_off() self.tellstick_device.turn_off()
self._brightness = 0 self._brightness = 0
self.update_ha_state() self.update_ha_state()
@ -99,11 +100,14 @@ class TellstickLight(Light):
else: else:
self._brightness = brightness self._brightness = brightness
for _ in range(self.signal_repetitions):
self.tellstick_device.dim(self._brightness) self.tellstick_device.dim(self._brightness)
self.update_ha_state() self.update_ha_state()
def update(self): def update(self):
""" Update state of the light. """ """ Update state of the light. """
import tellcore.constants as tellcore_constants
last_command = self.tellstick_device.last_sent_command( last_command = self.tellstick_device.last_sent_command(
self.last_sent_command_mask) self.last_sent_command_mask)

View File

@ -4,7 +4,7 @@ homeassistant.components.light.vera
Support for Vera lights. Support for Vera lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.vera.html https://home-assistant.io/components/light.vera/
""" """
import logging import logging
import time import time

View File

@ -4,7 +4,7 @@ homeassistant.components.light.wink
Support for Wink lights. Support for Wink lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.wink.html https://home-assistant.io/components/light.wink/
""" """
import logging import logging
@ -13,8 +13,8 @@ from homeassistant.components.wink import WinkToggleDevice
from homeassistant.const import CONF_ACCESS_TOKEN from homeassistant.const import CONF_ACCESS_TOKEN
REQUIREMENTS = ['https://github.com/balloob/python-wink/archive/' REQUIREMENTS = ['https://github.com/balloob/python-wink/archive/'
'c2b700e8ca866159566ecf5e644d9c297f69f257.zip' '42fdcfa721b1bc583688e3592d8427f4c13ba6d9.zip'
'#python-wink==0.1'] '#python-wink==0.2']
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):

View File

@ -0,0 +1,127 @@
"""
homeassistant.components.light.zwave
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Z-Wave lights.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.zwave/
"""
# Because we do not compile openzwave on CI
# pylint: disable=import-error
from threading import Timer
from homeassistant.const import STATE_ON, STATE_OFF
from homeassistant.components.light import (Light, ATTR_BRIGHTNESS)
import homeassistant.components.zwave as zwave
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Find and add Z-Wave lights. """
if discovery_info is None:
return
node = zwave.NETWORK.nodes[discovery_info[zwave.ATTR_NODE_ID]]
value = node.values[discovery_info[zwave.ATTR_VALUE_ID]]
if value.command_class != zwave.COMMAND_CLASS_SWITCH_MULTILEVEL:
return
if value.type != zwave.TYPE_BYTE:
return
if value.genre != zwave.GENRE_USER:
return
value.set_change_verified(False)
add_devices([ZwaveDimmer(value)])
def brightness_state(value):
"""
Returns the brightness and state according to the current data of given
value.
"""
if value.data > 0:
return (value.data / 99) * 255, STATE_ON
else:
return 255, STATE_OFF
class ZwaveDimmer(Light):
""" Provides a Z-Wave dimmer. """
# pylint: disable=too-many-arguments
def __init__(self, value):
from openzwave.network import ZWaveNetwork
from pydispatch import dispatcher
self._value = value
self._node = value.node
self._brightness, self._state = brightness_state(value)
# Used for value change event handling
self._refreshing = False
self._timer = None
dispatcher.connect(
self._value_changed, ZWaveNetwork.SIGNAL_VALUE_CHANGED)
def _value_changed(self, value):
""" Called when a value has changed on the network. """
if self._value.value_id != value.value_id:
return
if self._refreshing:
self._refreshing = False
self._brightness, self._state = brightness_state(value)
else:
def _refresh_value():
"""Used timer callback for delayed value refresh."""
self._refreshing = True
self._value.refresh()
if self._timer is not None and self._timer.isAlive():
self._timer.cancel()
self._timer = Timer(2, _refresh_value)
self._timer.start()
self.update_ha_state()
@property
def should_poll(self):
""" No polling needed for a light. """
return False
@property
def name(self):
""" Returns the name of the device if any. """
name = self._node.name or "{}".format(self._node.product_name)
return "{}".format(name or self._value.label)
@property
def brightness(self):
""" Brightness of this light between 0..255. """
return self._brightness
@property
def is_on(self):
""" True if device is on. """
return self._state == STATE_ON
def turn_on(self, **kwargs):
""" Turn the device on. """
if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs[ATTR_BRIGHTNESS]
# Zwave multilevel switches use a range of [0, 99] to control
# brightness.
brightness = (self._brightness / 255) * 99
if self._node.set_dimmer(self._value.value_id, brightness):
self._state = STATE_ON
def turn_off(self, **kwargs):
""" Turn the device off. """
if self._node.set_dimmer(self._value.value_id, 0):
self._state = STATE_OFF

View File

@ -0,0 +1,112 @@
"""
homeassistant.components.lock
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component to interface with various locks that can be controlled remotely.
For more details about this component, please refer to the documentation
at https://home-assistant.io/components/lock/
"""
from datetime import timedelta
import logging
import os
from homeassistant.config import load_yaml_config_file
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.entity import Entity
from homeassistant.const import (
STATE_LOCKED, STATE_UNLOCKED, STATE_UNKNOWN, SERVICE_LOCK, SERVICE_UNLOCK,
ATTR_ENTITY_ID)
from homeassistant.components import (group, wink)
DOMAIN = 'lock'
SCAN_INTERVAL = 30
GROUP_NAME_ALL_LOCKS = 'all locks'
ENTITY_ID_ALL_LOCKS = group.ENTITY_ID_FORMAT.format('all_locks')
ENTITY_ID_FORMAT = DOMAIN + '.{}'
ATTR_LOCKED = "locked"
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
# Maps discovered services to their platforms
DISCOVERY_PLATFORMS = {
wink.DISCOVER_LOCKS: 'wink'
}
_LOGGER = logging.getLogger(__name__)
def is_locked(hass, entity_id=None):
""" Returns if the lock is locked based on the statemachine. """
entity_id = entity_id or ENTITY_ID_ALL_LOCKS
return hass.states.is_state(entity_id, STATE_LOCKED)
def lock(hass, entity_id=None):
""" Locks all or specified locks. """
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.services.call(DOMAIN, SERVICE_LOCK, data)
def unlock(hass, entity_id=None):
""" Unlocks all or specified locks. """
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.services.call(DOMAIN, SERVICE_UNLOCK, data)
def setup(hass, config):
""" Track states and offer events for locks. """
component = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL, DISCOVERY_PLATFORMS,
GROUP_NAME_ALL_LOCKS)
component.setup(config)
def handle_lock_service(service):
""" Handles calls to the lock services. """
target_locks = component.extract_from_service(service)
for item in target_locks:
if service.service == SERVICE_LOCK:
item.lock()
else:
item.unlock()
if item.should_poll:
item.update_ha_state(True)
descriptions = load_yaml_config_file(
os.path.join(os.path.dirname(__file__), 'services.yaml'))
hass.services.register(DOMAIN, SERVICE_UNLOCK, handle_lock_service,
descriptions.get(SERVICE_UNLOCK))
hass.services.register(DOMAIN, SERVICE_LOCK, handle_lock_service,
descriptions.get(SERVICE_LOCK))
return True
class LockDevice(Entity):
""" Represents a lock within Home Assistant. """
# pylint: disable=no-self-use
@property
def is_locked(self):
""" Is the lock locked or unlocked. """
return None
def lock(self):
""" Locks the lock. """
raise NotImplementedError()
def unlock(self):
""" Unlocks the lock. """
raise NotImplementedError()
@property
def state(self):
locked = self.is_locked
if locked is None:
return STATE_UNKNOWN
return STATE_LOCKED if locked else STATE_UNLOCKED

View File

@ -0,0 +1,49 @@
"""
homeassistant.components.lock.demo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo platform that has two fake locks.
"""
from homeassistant.components.lock import LockDevice
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return demo locks. """
add_devices_callback([
DemoLock('Front Door', STATE_LOCKED),
DemoLock('Kitchen Door', STATE_UNLOCKED)
])
class DemoLock(LockDevice):
""" Provides a demo lock. """
def __init__(self, name, state):
self._name = name
self._state = state
@property
def should_poll(self):
""" No polling needed for a demo lock. """
return False
@property
def name(self):
""" Returns the name of the device if any. """
return self._name
@property
def is_locked(self):
""" True if device is locked. """
return self._state == STATE_LOCKED
def lock(self, **kwargs):
""" Lock the device. """
self._state = STATE_LOCKED
self.update_ha_state()
def unlock(self, **kwargs):
""" Unlock the device. """
self._state = STATE_UNLOCKED
self.update_ha_state()

View File

@ -0,0 +1,68 @@
"""
homeassistant.components.lock.wink
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Wink locks.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/lock.wink/
"""
import logging
from homeassistant.components.lock import LockDevice
from homeassistant.const import CONF_ACCESS_TOKEN
REQUIREMENTS = ['https://github.com/balloob/python-wink/archive/'
'42fdcfa721b1bc583688e3592d8427f4c13ba6d9.zip'
'#python-wink==0.2']
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Wink platform. """
import pywink
if discovery_info is None:
token = config.get(CONF_ACCESS_TOKEN)
if token is None:
logging.getLogger(__name__).error(
"Missing wink access_token. "
"Get one at https://winkbearertoken.appspot.com/")
return
pywink.set_bearer_token(token)
add_devices(WinkLockDevice(lock) for lock in pywink.get_locks())
class WinkLockDevice(LockDevice):
""" Represents a Wink lock. """
def __init__(self, wink):
self.wink = wink
@property
def unique_id(self):
""" Returns the id of this wink lock """
return "{}.{}".format(self.__class__, self.wink.deviceId())
@property
def name(self):
""" Returns the name of the lock if any. """
return self.wink.name()
def update(self):
""" Update the state of the lock. """
self.wink.updateState()
@property
def is_locked(self):
""" True if device is locked. """
return self.wink.state()
def lock(self):
""" Lock the device. """
self.wink.setState(True)
def unlock(self):
""" Unlock the device. """
self.wink.setState(False)

View File

@ -4,7 +4,7 @@ homeassistant.components.logbook
Parses events and generates a human log. Parses events and generates a human log.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/logbook.html https://home-assistant.io/components/logbook/
""" """
from datetime import timedelta from datetime import timedelta
from itertools import groupby from itertools import groupby

View File

@ -0,0 +1,83 @@
"""
homeassistant.components.logger
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component that will help set the level of logging for components.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/logger/
"""
import logging
from collections import OrderedDict
DOMAIN = 'logger'
LOGSEVERITY = {
'CRITICAL': 50,
'FATAL': 50,
'ERROR': 40,
'WARNING': 30,
'WARN': 30,
'INFO': 20,
'DEBUG': 10,
'NOTSET': 0
}
LOGGER_DEFAULT = 'default'
LOGGER_LOGS = 'logs'
class HomeAssistantLogFilter(logging.Filter):
""" A log filter. """
# pylint: disable=no-init,too-few-public-methods
def __init__(self, logfilter):
super().__init__()
self.logfilter = logfilter
def filter(self, record):
# Log with filtered severity
if LOGGER_LOGS in self.logfilter:
for filtername in self.logfilter[LOGGER_LOGS]:
logseverity = self.logfilter[LOGGER_LOGS][filtername]
if record.name.startswith(filtername):
return record.levelno >= logseverity
# Log with default severity
default = self.logfilter[LOGGER_DEFAULT]
return record.levelno >= default
def setup(hass, config=None):
""" Setup the logger component. """
logfilter = dict()
# Set default log severity
logfilter[LOGGER_DEFAULT] = LOGSEVERITY['DEBUG']
if LOGGER_DEFAULT in config.get(DOMAIN):
logfilter[LOGGER_DEFAULT] = LOGSEVERITY[
config.get(DOMAIN)[LOGGER_DEFAULT].upper()
]
# Compute log severity for components
if LOGGER_LOGS in config.get(DOMAIN):
for key, value in config.get(DOMAIN)[LOGGER_LOGS].items():
config.get(DOMAIN)[LOGGER_LOGS][key] = LOGSEVERITY[value.upper()]
logs = OrderedDict(
sorted(
config.get(DOMAIN)[LOGGER_LOGS].items(),
key=lambda t: len(t[0]),
reverse=True
)
)
logfilter[LOGGER_LOGS] = logs
# Set log filter for all log handler
for handler in logging.root.handlers:
handler.addFilter(HomeAssistantLogFilter(logfilter))
return True

View File

@ -1,8 +1,10 @@
""" """
homeassistant.components.media_player homeassistant.components.media_player
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component to interface with various media players. Component to interface with various media players.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/media_player/
""" """
import logging import logging
import os import os
@ -20,7 +22,6 @@ from homeassistant.const import (
SERVICE_MEDIA_NEXT_TRACK, SERVICE_MEDIA_PREVIOUS_TRACK, SERVICE_MEDIA_SEEK) SERVICE_MEDIA_NEXT_TRACK, SERVICE_MEDIA_PREVIOUS_TRACK, SERVICE_MEDIA_SEEK)
DOMAIN = 'media_player' DOMAIN = 'media_player'
DEPENDENCIES = []
SCAN_INTERVAL = 10 SCAN_INTERVAL = 10
ENTITY_ID_FORMAT = DOMAIN + '.{}' ENTITY_ID_FORMAT = DOMAIN + '.{}'

Some files were not shown because too many files have changed in this diff Show More