added component and sensor

This commit is contained in:
Per Sandstrom 2015-08-11 09:28:07 +02:00
parent ee73bd7dea
commit 92fc7eab36
4 changed files with 127 additions and 0 deletions

3
.gitmodules vendored
View file

@ -10,3 +10,6 @@
[submodule "homeassistant/components/frontend/www_static/home-assistant-polymer"]
path = homeassistant/components/frontend/www_static/home-assistant-polymer
url = https://github.com/balloob/home-assistant-polymer.git
[submodule "homeassistant/external/verisure"]
path = homeassistant/external/verisure
url = https://github.com/persandstrom/python-verisure.git

View file

@ -0,0 +1,65 @@
"""
homeassistant.components.sensor.verisure
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Interfaces with Verisure sensors.
"""
import logging
import homeassistant.components.verisure as verisure
from homeassistant.helpers.entity import Entity
from homeassistant.const import STATE_OPEN, STATE_CLOSED
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Verisure platform. """
if not verisure.MY_PAGES:
_LOGGER.error('A connection has not been made to Verisure mypages.')
return False
sensors = [
VerisureClimateDevice(status) for status
in verisure.MY_PAGES.get_climate_status()]
sensors.extend([
VerisureAlarmDevice(status) for status
in verisure.MY_PAGES.get_alarm_status()])
add_devices(sensors)
class VerisureClimateDevice(Entity):
""" represents a Verisure climate sensor within home assistant. """
def __init__(self, climate_status):
self._status = climate_status
@property
def name(self):
""" Returns the name of the device. """
return self._status.location
@property
def state(self):
""" Returns the state of the device. """
return self._status.temperature
class VerisureAlarmDevice(Entity):
""" represents a Verisure alarm remote control within home assistant. """
def __init__(self, alarm_status):
self._status = alarm_status
@property
def name(self):
""" Returns the name of the device. """
return 'Alarm {}'.format(self._status.id)
@property
def state(self):
""" Returns the state of the device. """
return self._status.status

View file

@ -0,0 +1,57 @@
"""
components.verisure
~~~~~~~~~~~~~~~~~~
"""
import logging
from homeassistant import bootstrap
from homeassistant.helpers import validate_config
from homeassistant.loader import get_component
from homeassistant.const import (
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP,
CONF_USERNAME, CONF_PASSWORD,
EVENT_PLATFORM_DISCOVERED,
ATTR_SERVICE, ATTR_DISCOVERED, ATTR_FRIENDLY_NAME)
DOMAIN = "verisure"
DEPENDENCIES = []
REQUIREMENTS = ['https://github.com/persandstrom/python-verisure/archive/master.zip']
MY_PAGES = None
_LOGGER = logging.getLogger(__name__)
DISCOVER_SENSORS = "wink.sensors"
def setup(hass, config):
""" Setup the Verisure component. """
if not validate_config(config,
{DOMAIN: [CONF_USERNAME, CONF_PASSWORD]},
_LOGGER):
return False
from verisure import MyPages
global MY_PAGES
MY_PAGES = MyPages(config[DOMAIN][CONF_USERNAME], config[DOMAIN][CONF_PASSWORD])
MY_PAGES.login()
component = get_component('sensor')
bootstrap.setup_component(hass, component.DOMAIN, config)
# Fire discovery event
hass.bus.fire(EVENT_PLATFORM_DISCOVERED, {
ATTR_SERVICE: DISCOVER_SENSORS,
ATTR_DISCOVERED: {}
})
def stop_verisure(event):
""" Stop the Arduino service. """
MY_PAGES.logout()
def start_verisure(event):
""" Start the Arduino service. """
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_verisure)
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_verisure)
return True

View file

@ -110,3 +110,5 @@ paho-mqtt>=1.1
# PyModbus (modbus)
https://github.com/bashwork/pymodbus/archive/python3.zip#pymodbus>=1.2.0
# Verisure
https://github.com/persandstrom/python-verisure/archive/master.zip