Migrate to voluptuous (#3234)
This commit is contained in:
1 parent
165871d48a
commit
6a837f3aad
5 files changed
+100
-40
No files matched your search
@@ -9,19 +9,26 @@ import pickle
|
||||
from binascii import hexlify, unhexlify
|
||||
from base64 import b64encode, b64decode
|
||||
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
EVENT_HOMEASSISTANT_STOP, CONF_DEVICE, CONF_NAME, CONF_PIN)
|
||||
from homeassistant.core import JobPriority
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
|
||||
DOMAIN = "zigbee"
|
||||
REQUIREMENTS = ("xbee-helper==0.0.7",)
|
||||
REQUIREMENTS = ['xbee-helper==0.0.7']
|
||||
|
||||
EVENT_ZIGBEE_FRAME_RECEIVED = "zigbee_frame_received"
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_DEVICE = "device"
|
||||
CONF_BAUD = "baud"
|
||||
DOMAIN = 'zigbee'
|
||||
|
||||
DEFAULT_DEVICE = "/dev/ttyUSB0"
|
||||
EVENT_ZIGBEE_FRAME_RECEIVED = 'zigbee_frame_received'
|
||||
|
||||
CONF_ADDRESS = 'address'
|
||||
CONF_BAUD = 'baud'
|
||||
|
||||
DEFAULT_DEVICE = '/dev/ttyUSB0'
|
||||
DEFAULT_BAUD = 9600
|
||||
DEFAULT_ADC_MAX_VOLTS = 1.2
|
||||
|
||||
@@ -35,11 +42,22 @@ CONVERT_ADC = None
|
||||
ZIGBEE_EXCEPTION = None
|
||||
ZIGBEE_TX_FAILURE = None
|
||||
|
||||
ATTR_FRAME = "frame"
|
||||
ATTR_FRAME = 'frame'
|
||||
|
||||
DEVICE = None
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Optional(CONF_BAUD, default=DEFAULT_BAUD): cv.string,
|
||||
vol.Optional(CONF_DEVICE, default=DEFAULT_DEVICE): cv.string,
|
||||
}),
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
PLATFORM_SCHEMA = vol.Schema({
|
||||
vol.Required(CONF_NAME): cv.string,
|
||||
vol.Required(CONF_PIN): cv.positive_int,
|
||||
vol.Optional(CONF_ADDRESS): cv.string,
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
@@ -101,9 +119,9 @@ def close_serial_port(*args):
|
||||
|
||||
def frame_is_relevant(entity, frame):
|
||||
"""Test whether the frame is relevant to the entity."""
|
||||
if frame.get("source_addr_long") != entity.config.address:
|
||||
if frame.get('source_addr_long') != entity.config.address:
|
||||
return False
|
||||
if "samples" not in frame:
|
||||
if 'samples' not in frame:
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -279,7 +297,7 @@ class ZigBeeDigitalIn(Entity):
|
||||
"""
|
||||
if not frame_is_relevant(self, frame):
|
||||
return
|
||||
sample = frame["samples"].pop()
|
||||
sample = frame['samples'].pop()
|
||||
pin_name = DIGITAL_PINS[self._config.pin]
|
||||
if pin_name not in sample:
|
||||
# Doesn't contain information about our pin
|
||||
@@ -402,7 +420,7 @@ class ZigBeeAnalogIn(Entity):
|
||||
"""
|
||||
if not frame_is_relevant(self, frame):
|
||||
return
|
||||
sample = frame["samples"].pop()
|
||||
sample = frame['samples'].pop()
|
||||
pin_name = ANALOG_PINS[self._config.pin]
|
||||
if pin_name not in sample:
|
||||
# Doesn't contain information about our pin
|
||||
|
||||
Reference in new issue
Block a user