Skip to content

Commit

Permalink
Use voluptuous for Verisure (#3169)
Browse files Browse the repository at this point in the history
* Migrate to voluptuous

* Update type and add missing config variable
  • Loading branch information
fabaff authored and balloob committed Sep 7, 2016
1 parent abff2f2 commit 7aafa30
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 25 deletions.
6 changes: 3 additions & 3 deletions homeassistant/components/alarm_control_panel/verisure.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import homeassistant.components.alarm_control_panel as alarm
from homeassistant.components.verisure import HUB as hub

from homeassistant.components.verisure import (CONF_ALARM, CONF_CODE_DIGITS)
from homeassistant.const import (
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED,
STATE_UNKNOWN)
Expand All @@ -19,7 +19,7 @@
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Verisure platform."""
alarms = []
if int(hub.config.get('alarm', '1')):
if int(hub.config.get(CONF_ALARM, 1)):
hub.update_alarms()
alarms.extend([
VerisureAlarm(value.id)
Expand All @@ -36,7 +36,7 @@ def __init__(self, device_id):
"""Initalize the Verisure alarm panel."""
self._id = device_id
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

@property
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/lock/verisure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging

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.const import (
ATTR_CODE, STATE_LOCKED, STATE_UNKNOWN, STATE_UNLOCKED)
Expand All @@ -17,7 +18,7 @@
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Verisure platform."""
locks = []
if int(hub.config.get('locks', '1')):
if int(hub.config.get(CONF_LOCKS, 1)):
hub.update_locks()
locks.extend([
VerisureDoorlock(device_id)
Expand All @@ -34,7 +35,7 @@ def __init__(self, device_id):
"""Initialize the lock."""
self._id = device_id
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

@property
Expand Down
19 changes: 9 additions & 10 deletions homeassistant/components/sensor/verisure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
Interfaces with Verisure sensors.
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

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.helpers.entity import Entity

Expand All @@ -17,23 +19,23 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Verisure platform."""
sensors = []

if int(hub.config.get('thermometers', '1')):
if int(hub.config.get(CONF_THERMOMETERS, 1)):
hub.update_climate()
sensors.extend([
VerisureThermometer(value.id)
for value in hub.climate_status.values()
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()
sensors.extend([
VerisureHygrometer(value.id)
for value in hub.climate_status.values()
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()
sensors.extend([
VerisureMouseDetection(value.deviceLabel)
Expand All @@ -56,8 +58,7 @@ def __init__(self, device_id):
def name(self):
"""Return the name of the device."""
return '{} {}'.format(
hub.climate_status[self._id].location,
"Temperature")
hub.climate_status[self._id].location, 'Temperature')

@property
def state(self):
Expand Down Expand Up @@ -91,8 +92,7 @@ def __init__(self, device_id):
def name(self):
"""Return the name of the sensor."""
return '{} {}'.format(
hub.climate_status[self._id].location,
"Humidity")
hub.climate_status[self._id].location, 'Humidity')

@property
def state(self):
Expand Down Expand Up @@ -126,8 +126,7 @@ def __init__(self, device_id):
def name(self):
"""Return the name of the sensor."""
return '{} {}'.format(
hub.mouse_status[self._id].location,
"Mouse")
hub.mouse_status[self._id].location, 'Mouse')

@property
def state(self):
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/switch/verisure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
Support for Verisure Smartplugs.
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

from homeassistant.components.verisure import HUB as hub
from homeassistant.components.verisure import CONF_SMARTPLUGS
from homeassistant.components.switch import SwitchDevice

_LOGGER = logging.getLogger(__name__)


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Verisure switch platform."""
if not int(hub.config.get('smartplugs', '1')):
if not int(hub.config.get(CONF_SMARTPLUGS, 1)):
return False

hub.update_smartplugs()
Expand Down
36 changes: 28 additions & 8 deletions homeassistant/components/verisure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,46 @@
import time
from datetime import timedelta

import voluptuous as vol

from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.helpers import validate_config, discovery
from homeassistant.helpers import discovery
from homeassistant.util import Throttle

DOMAIN = "verisure"
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['vsure==0.10.2']

_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

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):
"""Setup the Verisure component."""
if not validate_config(config,
{DOMAIN: [CONF_USERNAME, CONF_PASSWORD]},
_LOGGER):
return False

import verisure
global HUB
HUB = VerisureHub(config[DOMAIN], verisure)
Expand Down

0 comments on commit 7aafa30

Please sign in to comment.