Migrate to voluptuous (#3280)

This commit is contained in:
Fabian Affolter 2016-09-11 11:19:10 +02:00 committed by GitHub
parent f5df5615be
commit 1b77b2c3a3

View file

@ -7,30 +7,38 @@ https://home-assistant.io/components/wink/
import logging import logging
import json import json
from homeassistant.helpers import validate_config, discovery import voluptuous as vol
from homeassistant.helpers import discovery
from homeassistant.const import CONF_ACCESS_TOKEN, ATTR_BATTERY_LEVEL from homeassistant.const import CONF_ACCESS_TOKEN, ATTR_BATTERY_LEVEL
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
import homeassistant.helpers.config_validation as cv
DOMAIN = "wink"
REQUIREMENTS = ['python-wink==0.7.13', 'pubnub==3.8.2'] REQUIREMENTS = ['python-wink==0.7.13', 'pubnub==3.8.2']
SUBSCRIPTION_HANDLER = None _LOGGER = logging.getLogger(__name__)
CHANNELS = [] CHANNELS = []
DOMAIN = 'wink'
SUBSCRIPTION_HANDLER = None
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Optional(CONF_ACCESS_TOKEN): cv.string,
}),
}, extra=vol.ALLOW_EXTRA)
def setup(hass, config): def setup(hass, config):
"""Setup the Wink component.""" """Setup the Wink component."""
logger = logging.getLogger(__name__)
if not validate_config(config, {DOMAIN: [CONF_ACCESS_TOKEN]}, logger):
return False
import pywink import pywink
from pubnub import Pubnub from pubnub import Pubnub
pywink.set_bearer_token(config[DOMAIN][CONF_ACCESS_TOKEN]) pywink.set_bearer_token(config[DOMAIN][CONF_ACCESS_TOKEN])
global SUBSCRIPTION_HANDLER global SUBSCRIPTION_HANDLER
SUBSCRIPTION_HANDLER = Pubnub("N/A", pywink.get_subscription_key(), SUBSCRIPTION_HANDLER = Pubnub(
ssl_on=True) 'N/A', pywink.get_subscription_key(), ssl_on=True)
SUBSCRIPTION_HANDLER.set_heartbeat(120) SUBSCRIPTION_HANDLER.set_heartbeat(120)
# Load components for the devices in the Wink that we support # Load components for the devices in the Wink that we support
@ -51,7 +59,7 @@ def setup(hass, config):
class WinkDevice(Entity): class WinkDevice(Entity):
"""Represents a base Wink device.""" """Representation a base Wink device."""
def __init__(self, wink): def __init__(self, wink):
"""Initialize the Wink device.""" """Initialize the Wink device."""
@ -59,7 +67,7 @@ class WinkDevice(Entity):
self.wink = wink self.wink = wink
self._battery = self.wink.battery_level self._battery = self.wink.battery_level
if self.wink.pubnub_channel in CHANNELS: if self.wink.pubnub_channel in CHANNELS:
pubnub = Pubnub("N/A", self.wink.pubnub_key, ssl_on=True) pubnub = Pubnub('N/A', self.wink.pubnub_key, ssl_on=True)
pubnub.set_heartbeat(120) pubnub.set_heartbeat(120)
pubnub.subscribe(self.wink.pubnub_channel, pubnub.subscribe(self.wink.pubnub_channel,
self._pubnub_update, self._pubnub_update,
@ -75,13 +83,12 @@ class WinkDevice(Entity):
self.update_ha_state() self.update_ha_state()
def _pubnub_error(self, message): def _pubnub_error(self, message):
logging.getLogger(__name__).error( _LOGGER.error("Error on pubnub update for " + self.wink.name())
"Error on pubnub update for " + self.wink.name())
@property @property
def unique_id(self): def unique_id(self):
"""Return the ID of this Wink device.""" """Return the ID of this Wink device."""
return "{}.{}".format(self.__class__, self.wink.device_id()) return '{}.{}'.format(self.__class__, self.wink.device_id())
@property @property
def name(self): def name(self):