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 default
This commit is contained in:
parent
03dd1e6870
commit
32cb666dac
2 changed files with 25 additions and 35 deletions
|
@ -9,23 +9,23 @@ import time
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_DEVICES, CONF_NAME, \
|
|
||||||
CONF_USERNAME, CONF_PASSWORD
|
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light,
|
ATTR_BRIGHTNESS, PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS, Light)
|
||||||
PLATFORM_SCHEMA)
|
from homeassistant.const import (
|
||||||
|
CONF_API_KEY, CONF_DEVICES, CONF_ID, CONF_NAME, CONF_PASSWORD,
|
||||||
|
CONF_USERNAME)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['avion==0.7']
|
REQUIREMENTS = ['antsar-avion==0.9.1']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SUPPORT_AVION_LED = (SUPPORT_BRIGHTNESS)
|
SUPPORT_AVION_LED = SUPPORT_BRIGHTNESS
|
||||||
|
|
||||||
DEVICE_SCHEMA = vol.Schema({
|
DEVICE_SCHEMA = vol.Schema({
|
||||||
vol.Optional(CONF_NAME): cv.string,
|
|
||||||
vol.Required(CONF_API_KEY): 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({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
@ -42,24 +42,18 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
|
|
||||||
lights = []
|
lights = []
|
||||||
if CONF_USERNAME in config and CONF_PASSWORD in config:
|
if CONF_USERNAME in config and CONF_PASSWORD in config:
|
||||||
data = avion.avion_info(config[CONF_USERNAME], config[CONF_PASSWORD])
|
devices = avion.get_devices(
|
||||||
for location in data['locations']:
|
config[CONF_USERNAME], config[CONF_PASSWORD])
|
||||||
for avion_device in location['location']['devices']:
|
for device in 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))
|
lights.append(AvionLight(device))
|
||||||
|
|
||||||
for address, device_config in config[CONF_DEVICES].items():
|
for address, device_config in config[CONF_DEVICES].items():
|
||||||
device = {}
|
device = avion.Avion(
|
||||||
device['name'] = device_config[CONF_NAME]
|
mac=address,
|
||||||
device['key'] = device_config[CONF_API_KEY]
|
passphrase=device_config[CONF_API_KEY],
|
||||||
device['address'] = address
|
name=device_config.get(CONF_NAME),
|
||||||
|
object_id=device_config.get(CONF_ID),
|
||||||
|
connect=False)
|
||||||
lights.append(AvionLight(device))
|
lights.append(AvionLight(device))
|
||||||
|
|
||||||
add_entities(lights)
|
add_entities(lights)
|
||||||
|
@ -70,15 +64,11 @@ class AvionLight(Light):
|
||||||
|
|
||||||
def __init__(self, device):
|
def __init__(self, device):
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
# pylint: disable=no-member
|
self._name = device.name
|
||||||
import avion
|
self._address = device.mac
|
||||||
|
|
||||||
self._name = device['name']
|
|
||||||
self._address = device['address']
|
|
||||||
self._key = device['key']
|
|
||||||
self._brightness = 255
|
self._brightness = 255
|
||||||
self._state = False
|
self._state = False
|
||||||
self._switch = avion.avion(self._address, self._key)
|
self._switch = device
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
|
@ -129,7 +119,7 @@ class AvionLight(Light):
|
||||||
try:
|
try:
|
||||||
self._switch.set_brightness(brightness)
|
self._switch.set_brightness(brightness)
|
||||||
break
|
break
|
||||||
except avion.avionException:
|
except avion.AvionException:
|
||||||
self._switch.connect()
|
self._switch.connect()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,9 @@ anel_pwrctrl-homeassistant==0.0.1.dev2
|
||||||
# homeassistant.components.media_player.anthemav
|
# homeassistant.components.media_player.anthemav
|
||||||
anthemav==1.1.8
|
anthemav==1.1.8
|
||||||
|
|
||||||
|
# homeassistant.components.light.avion
|
||||||
|
# antsar-avion==0.9.1
|
||||||
|
|
||||||
# homeassistant.components.apcupsd
|
# homeassistant.components.apcupsd
|
||||||
apcaccess==0.0.13
|
apcaccess==0.0.13
|
||||||
|
|
||||||
|
@ -158,9 +161,6 @@ asterisk_mbox==0.5.0
|
||||||
# homeassistant.components.media_player.dlna_dmr
|
# homeassistant.components.media_player.dlna_dmr
|
||||||
async-upnp-client==0.13.0
|
async-upnp-client==0.13.0
|
||||||
|
|
||||||
# homeassistant.components.light.avion
|
|
||||||
# avion==0.7
|
|
||||||
|
|
||||||
# homeassistant.components.axis
|
# homeassistant.components.axis
|
||||||
axis==16
|
axis==16
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue