Update Avi-On to work with latest API (#17780)
* Update Avi-On to work with the API. * Use voluptuous defaults instead of .get() * Bump library version. * Remove unnecessary voluptuous defaults. Fix manually-configured devices. API-discovered devices are already Avion objects, but manually-configured devices need to be instantiated as Avion objects first. * Use .get() where appropriate. * Remove defaultpull/17969/head
parent
03dd1e6870
commit
32cb666dac
|
@ -9,23 +9,23 @@ import time
|
|||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import CONF_API_KEY, CONF_DEVICES, CONF_NAME, \
|
||||
CONF_USERNAME, CONF_PASSWORD
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light,
|
||||
PLATFORM_SCHEMA)
|
||||
ATTR_BRIGHTNESS, PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS, Light)
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY, CONF_DEVICES, CONF_ID, CONF_NAME, CONF_PASSWORD,
|
||||
CONF_USERNAME)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['avion==0.7']
|
||||
REQUIREMENTS = ['antsar-avion==0.9.1']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SUPPORT_AVION_LED = (SUPPORT_BRIGHTNESS)
|
||||
SUPPORT_AVION_LED = SUPPORT_BRIGHTNESS
|
||||
|
||||
DEVICE_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
vol.Optional(CONF_ID): cv.positive_int,
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
})
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
|
@ -42,24 +42,18 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
|
||||
lights = []
|
||||
if CONF_USERNAME in config and CONF_PASSWORD in config:
|
||||
data = avion.avion_info(config[CONF_USERNAME], config[CONF_PASSWORD])
|
||||
for location in data['locations']:
|
||||
for avion_device in location['location']['devices']:
|
||||
device = {}
|
||||
mac = avion_device['device']['mac_address']
|
||||
device['name'] = avion_device['device']['name']
|
||||
device['key'] = location['location']['passphrase']
|
||||
device['address'] = '%s%s:%s%s:%s%s:%s%s:%s%s:%s%s' % \
|
||||
(mac[8], mac[9], mac[10], mac[11], mac[4],
|
||||
mac[5], mac[6], mac[7], mac[0], mac[1],
|
||||
mac[2], mac[3])
|
||||
lights.append(AvionLight(device))
|
||||
devices = avion.get_devices(
|
||||
config[CONF_USERNAME], config[CONF_PASSWORD])
|
||||
for device in devices:
|
||||
lights.append(AvionLight(device))
|
||||
|
||||
for address, device_config in config[CONF_DEVICES].items():
|
||||
device = {}
|
||||
device['name'] = device_config[CONF_NAME]
|
||||
device['key'] = device_config[CONF_API_KEY]
|
||||
device['address'] = address
|
||||
device = avion.Avion(
|
||||
mac=address,
|
||||
passphrase=device_config[CONF_API_KEY],
|
||||
name=device_config.get(CONF_NAME),
|
||||
object_id=device_config.get(CONF_ID),
|
||||
connect=False)
|
||||
lights.append(AvionLight(device))
|
||||
|
||||
add_entities(lights)
|
||||
|
@ -70,15 +64,11 @@ class AvionLight(Light):
|
|||
|
||||
def __init__(self, device):
|
||||
"""Initialize the light."""
|
||||
# pylint: disable=no-member
|
||||
import avion
|
||||
|
||||
self._name = device['name']
|
||||
self._address = device['address']
|
||||
self._key = device['key']
|
||||
self._name = device.name
|
||||
self._address = device.mac
|
||||
self._brightness = 255
|
||||
self._state = False
|
||||
self._switch = avion.avion(self._address, self._key)
|
||||
self._switch = device
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
@ -129,7 +119,7 @@ class AvionLight(Light):
|
|||
try:
|
||||
self._switch.set_brightness(brightness)
|
||||
break
|
||||
except avion.avionException:
|
||||
except avion.AvionException:
|
||||
self._switch.connect()
|
||||
return True
|
||||
|
||||
|
|
|
@ -142,6 +142,9 @@ anel_pwrctrl-homeassistant==0.0.1.dev2
|
|||
# homeassistant.components.media_player.anthemav
|
||||
anthemav==1.1.8
|
||||
|
||||
# homeassistant.components.light.avion
|
||||
# antsar-avion==0.9.1
|
||||
|
||||
# homeassistant.components.apcupsd
|
||||
apcaccess==0.0.13
|
||||
|
||||
|
@ -158,9 +161,6 @@ asterisk_mbox==0.5.0
|
|||
# homeassistant.components.media_player.dlna_dmr
|
||||
async-upnp-client==0.13.0
|
||||
|
||||
# homeassistant.components.light.avion
|
||||
# avion==0.7
|
||||
|
||||
# homeassistant.components.axis
|
||||
axis==16
|
||||
|
||||
|
|
Loading…
Reference in New Issue