Use voluptuous for Verisure (#3169)

* Migrate to voluptuous

* Update type and add missing config variable
This commit is contained in:
Fabian Affolter 2016-09-07 03:18:34 +02:00 committed by Paulus Schoutsen
parent abff2f2b36
commit 7aafa309c9
5 changed files with 47 additions and 26 deletions

View File

@ -8,7 +8,7 @@ import logging
import homeassistant.components.alarm_control_panel as alarm import homeassistant.components.alarm_control_panel as alarm
from homeassistant.components.verisure import HUB as hub from homeassistant.components.verisure import HUB as hub
from homeassistant.components.verisure import (CONF_ALARM, CONF_CODE_DIGITS)
from homeassistant.const import ( from homeassistant.const import (
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED, STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED,
STATE_UNKNOWN) STATE_UNKNOWN)
@ -19,7 +19,7 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Verisure platform.""" """Setup the Verisure platform."""
alarms = [] alarms = []
if int(hub.config.get('alarm', '1')): if int(hub.config.get(CONF_ALARM, 1)):
hub.update_alarms() hub.update_alarms()
alarms.extend([ alarms.extend([
VerisureAlarm(value.id) VerisureAlarm(value.id)
@ -36,7 +36,7 @@ class VerisureAlarm(alarm.AlarmControlPanel):
"""Initalize the Verisure alarm panel.""" """Initalize the Verisure alarm panel."""
self._id = device_id self._id = device_id
self._state = STATE_UNKNOWN self._state = STATE_UNKNOWN
self._digits = int(hub.config.get('code_digits', '4')) self._digits = hub.config.get(CONF_CODE_DIGITS)
self._changed_by = None self._changed_by = None
@property @property

View File

@ -7,6 +7,7 @@ https://home-assistant.io/components/verisure/
import logging import logging
from homeassistant.components.verisure import HUB as hub from homeassistant.components.verisure import HUB as hub
from homeassistant.components.verisure import (CONF_LOCKS, CONF_CODE_DIGITS)
from homeassistant.components.lock import LockDevice from homeassistant.components.lock import LockDevice
from homeassistant.const import ( from homeassistant.const import (
ATTR_CODE, STATE_LOCKED, STATE_UNKNOWN, STATE_UNLOCKED) ATTR_CODE, STATE_LOCKED, STATE_UNKNOWN, STATE_UNLOCKED)
@ -17,7 +18,7 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Verisure platform.""" """Setup the Verisure platform."""
locks = [] locks = []
if int(hub.config.get('locks', '1')): if int(hub.config.get(CONF_LOCKS, 1)):
hub.update_locks() hub.update_locks()
locks.extend([ locks.extend([
VerisureDoorlock(device_id) VerisureDoorlock(device_id)
@ -34,7 +35,7 @@ class VerisureDoorlock(LockDevice):
"""Initialize the lock.""" """Initialize the lock."""
self._id = device_id self._id = device_id
self._state = STATE_UNKNOWN self._state = STATE_UNKNOWN
self._digits = int(hub.config.get('code_digits', '4')) self._digits = hub.config.get(CONF_CODE_DIGITS)
self._changed_by = None self._changed_by = None
@property @property

View File

@ -2,11 +2,13 @@
Interfaces with Verisure sensors. Interfaces with Verisure sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
documentation at https://home-assistant.io/components/verisure/ https://home-assistant.io/components/sensor.verisure/
""" """
import logging import logging
from homeassistant.components.verisure import HUB as hub from homeassistant.components.verisure import HUB as hub
from homeassistant.components.verisure import (
CONF_THERMOMETERS, CONF_HYDROMETERS, CONF_MOUSE)
from homeassistant.const import TEMP_CELSIUS from homeassistant.const import TEMP_CELSIUS
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -17,7 +19,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Verisure platform.""" """Setup the Verisure platform."""
sensors = [] sensors = []
if int(hub.config.get('thermometers', '1')): if int(hub.config.get(CONF_THERMOMETERS, 1)):
hub.update_climate() hub.update_climate()
sensors.extend([ sensors.extend([
VerisureThermometer(value.id) VerisureThermometer(value.id)
@ -25,7 +27,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
if hasattr(value, 'temperature') and value.temperature if hasattr(value, 'temperature') and value.temperature
]) ])
if int(hub.config.get('hygrometers', '1')): if int(hub.config.get(CONF_HYDROMETERS, 1)):
hub.update_climate() hub.update_climate()
sensors.extend([ sensors.extend([
VerisureHygrometer(value.id) VerisureHygrometer(value.id)
@ -33,7 +35,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
if hasattr(value, 'humidity') and value.humidity if hasattr(value, 'humidity') and value.humidity
]) ])
if int(hub.config.get('mouse', '1')): if int(hub.config.get(CONF_MOUSE, 1)):
hub.update_mousedetection() hub.update_mousedetection()
sensors.extend([ sensors.extend([
VerisureMouseDetection(value.deviceLabel) VerisureMouseDetection(value.deviceLabel)
@ -56,8 +58,7 @@ class VerisureThermometer(Entity):
def name(self): def name(self):
"""Return the name of the device.""" """Return the name of the device."""
return '{} {}'.format( return '{} {}'.format(
hub.climate_status[self._id].location, hub.climate_status[self._id].location, 'Temperature')
"Temperature")
@property @property
def state(self): def state(self):
@ -91,8 +92,7 @@ class VerisureHygrometer(Entity):
def name(self): def name(self):
"""Return the name of the sensor.""" """Return the name of the sensor."""
return '{} {}'.format( return '{} {}'.format(
hub.climate_status[self._id].location, hub.climate_status[self._id].location, 'Humidity')
"Humidity")
@property @property
def state(self): def state(self):
@ -126,8 +126,7 @@ class VerisureMouseDetection(Entity):
def name(self): def name(self):
"""Return the name of the sensor.""" """Return the name of the sensor."""
return '{} {}'.format( return '{} {}'.format(
hub.mouse_status[self._id].location, hub.mouse_status[self._id].location, 'Mouse')
"Mouse")
@property @property
def state(self): def state(self):

View File

@ -2,11 +2,12 @@
Support for Verisure Smartplugs. Support for Verisure Smartplugs.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
documentation at https://home-assistant.io/components/verisure/ https://home-assistant.io/components/switch.verisure/
""" """
import logging import logging
from homeassistant.components.verisure import HUB as hub from homeassistant.components.verisure import HUB as hub
from homeassistant.components.verisure import CONF_SMARTPLUGS
from homeassistant.components.switch import SwitchDevice from homeassistant.components.switch import SwitchDevice
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -14,7 +15,7 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Verisure switch platform.""" """Setup the Verisure switch platform."""
if not int(hub.config.get('smartplugs', '1')): if not int(hub.config.get(CONF_SMARTPLUGS, 1)):
return False return False
hub.update_smartplugs() hub.update_smartplugs()

View File

@ -9,26 +9,46 @@ import threading
import time import time
from datetime import timedelta from datetime import timedelta
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME import voluptuous as vol
from homeassistant.helpers import validate_config, discovery
from homeassistant.util import Throttle
DOMAIN = "verisure" from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.helpers import discovery
from homeassistant.util import Throttle
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['vsure==0.10.2'] REQUIREMENTS = ['vsure==0.10.2']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONF_ALARM = 'alarm'
CONF_CODE_DIGITS = 'code_digits'
CONF_HYDROMETERS = 'hygrometers'
CONF_LOCKS = 'locks'
CONF_MOUSE = 'mouse'
CONF_SMARTPLUGS = 'smartplugs'
CONF_THERMOMETERS = 'thermometers'
DOMAIN = 'verisure'
HUB = None HUB = None
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Optional(CONF_ALARM, default=True): cv.boolean,
vol.Optional(CONF_CODE_DIGITS, default=4): cv.positive_int,
vol.Optional(CONF_HYDROMETERS, default=True): cv.boolean,
vol.Optional(CONF_LOCKS, default=True): cv.boolean,
vol.Optional(CONF_MOUSE, default=True): cv.boolean,
vol.Optional(CONF_SMARTPLUGS, default=True): cv.boolean,
vol.Optional(CONF_THERMOMETERS, default=True): cv.boolean,
}),
}, extra=vol.ALLOW_EXTRA)
def setup(hass, config): def setup(hass, config):
"""Setup the Verisure component.""" """Setup the Verisure component."""
if not validate_config(config,
{DOMAIN: [CONF_USERNAME, CONF_PASSWORD]},
_LOGGER):
return False
import verisure import verisure
global HUB global HUB
HUB = VerisureHub(config[DOMAIN], verisure) HUB = VerisureHub(config[DOMAIN], verisure)