Fix insteon Hub v1 support (#16472)

* Fix support for Hub version 1 (i.e. pre-2014 Hub model 2242)

* Bump insteonplm to 0.14.1

* Code review changes

* Clean up and better document set_default_port

* Simplify set_default_port based on code review

* Remove Callable type import

* Simplify port setup
pull/16547/head
Tom Harris 2018-09-10 10:54:17 -04:00 committed by Martin Hjelmare
parent f858938ada
commit dcd7b9a529
2 changed files with 28 additions and 14 deletions

View File

@ -7,6 +7,8 @@ https://home-assistant.io/components/insteon/
import asyncio import asyncio
import collections import collections
import logging import logging
from typing import Dict
import voluptuous as vol import voluptuous as vol
from homeassistant.core import callback from homeassistant.core import callback
@ -18,7 +20,7 @@ import homeassistant.helpers.config_validation as cv
from homeassistant.helpers import discovery from homeassistant.helpers import discovery
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['insteonplm==0.13.1'] REQUIREMENTS = ['insteonplm==0.14.2']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -27,9 +29,9 @@ DOMAIN = 'insteon'
CONF_IP_PORT = 'ip_port' CONF_IP_PORT = 'ip_port'
CONF_HUB_USERNAME = 'username' CONF_HUB_USERNAME = 'username'
CONF_HUB_PASSWORD = 'password' CONF_HUB_PASSWORD = 'password'
CONF_HUB_VERSION = 'hub_version'
CONF_OVERRIDE = 'device_override' CONF_OVERRIDE = 'device_override'
CONF_PLM_HUB_MSG = ('Must configure either a PLM port or a Hub host, username ' CONF_PLM_HUB_MSG = 'Must configure either a PLM port or a Hub host'
'and password')
CONF_ADDRESS = 'address' CONF_ADDRESS = 'address'
CONF_CAT = 'cat' CONF_CAT = 'cat'
CONF_SUBCAT = 'subcat' CONF_SUBCAT = 'subcat'
@ -66,6 +68,22 @@ EVENT_BUTTON_ON = 'insteon.button_on'
EVENT_BUTTON_OFF = 'insteon.button_off' EVENT_BUTTON_OFF = 'insteon.button_off'
EVENT_CONF_BUTTON = 'button' EVENT_CONF_BUTTON = 'button'
def set_default_port(schema: Dict) -> Dict:
"""Set the default port based on the Hub version."""
# If the ip_port is found do nothing
# If it is not found the set the default
ip_port = schema.get(CONF_IP_PORT)
if not ip_port:
hub_version = schema.get(CONF_HUB_VERSION)
# Found hub_version but not ip_port
if hub_version == 1:
schema[CONF_IP_PORT] = 9761
else:
schema[CONF_IP_PORT] = 25105
return schema
CONF_DEVICE_OVERRIDE_SCHEMA = vol.All( CONF_DEVICE_OVERRIDE_SCHEMA = vol.All(
cv.deprecated(CONF_PLATFORM), vol.Schema({ cv.deprecated(CONF_PLATFORM), vol.Schema({
vol.Required(CONF_ADDRESS): cv.string, vol.Required(CONF_ADDRESS): cv.string,
@ -88,12 +106,13 @@ CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.All( DOMAIN: vol.All(
vol.Schema( vol.Schema(
{vol.Exclusive(CONF_PORT, 'plm_or_hub', {vol.Exclusive(CONF_PORT, 'plm_or_hub',
msg=CONF_PLM_HUB_MSG): cv.isdevice, msg=CONF_PLM_HUB_MSG): cv.string,
vol.Exclusive(CONF_HOST, 'plm_or_hub', vol.Exclusive(CONF_HOST, 'plm_or_hub',
msg=CONF_PLM_HUB_MSG): cv.string, msg=CONF_PLM_HUB_MSG): cv.string,
vol.Optional(CONF_IP_PORT, default=25105): int, vol.Optional(CONF_IP_PORT): cv.port,
vol.Optional(CONF_HUB_USERNAME): cv.string, vol.Optional(CONF_HUB_USERNAME): cv.string,
vol.Optional(CONF_HUB_PASSWORD): cv.string, vol.Optional(CONF_HUB_PASSWORD): cv.string,
vol.Optional(CONF_HUB_VERSION, default=2): vol.In([1, 2]),
vol.Optional(CONF_OVERRIDE): vol.All( vol.Optional(CONF_OVERRIDE): vol.All(
cv.ensure_list_csv, [CONF_DEVICE_OVERRIDE_SCHEMA]), cv.ensure_list_csv, [CONF_DEVICE_OVERRIDE_SCHEMA]),
vol.Optional(CONF_X10_ALL_UNITS_OFF): vol.In(HOUSECODES), vol.Optional(CONF_X10_ALL_UNITS_OFF): vol.In(HOUSECODES),
@ -103,14 +122,7 @@ CONFIG_SCHEMA = vol.Schema({
[CONF_X10_SCHEMA]) [CONF_X10_SCHEMA])
}, extra=vol.ALLOW_EXTRA, required=True), }, extra=vol.ALLOW_EXTRA, required=True),
cv.has_at_least_one_key(CONF_PORT, CONF_HOST), cv.has_at_least_one_key(CONF_PORT, CONF_HOST),
vol.Schema( set_default_port)
{vol.Inclusive(CONF_HOST, 'hub',
msg=CONF_PLM_HUB_MSG): cv.string,
vol.Inclusive(CONF_HUB_USERNAME, 'hub',
msg=CONF_PLM_HUB_MSG): cv.string,
vol.Inclusive(CONF_HUB_PASSWORD, 'hub',
msg=CONF_PLM_HUB_MSG): cv.string,
}, extra=vol.ALLOW_EXTRA, required=True))
}, extra=vol.ALLOW_EXTRA) }, extra=vol.ALLOW_EXTRA)
@ -151,6 +163,7 @@ def async_setup(hass, config):
ip_port = conf.get(CONF_IP_PORT) ip_port = conf.get(CONF_IP_PORT)
username = conf.get(CONF_HUB_USERNAME) username = conf.get(CONF_HUB_USERNAME)
password = conf.get(CONF_HUB_PASSWORD) password = conf.get(CONF_HUB_PASSWORD)
hub_version = conf.get(CONF_HUB_VERSION)
overrides = conf.get(CONF_OVERRIDE, []) overrides = conf.get(CONF_OVERRIDE, [])
x10_devices = conf.get(CONF_X10, []) x10_devices = conf.get(CONF_X10, [])
x10_all_units_off_housecode = conf.get(CONF_X10_ALL_UNITS_OFF) x10_all_units_off_housecode = conf.get(CONF_X10_ALL_UNITS_OFF)
@ -284,6 +297,7 @@ def async_setup(hass, config):
port=ip_port, port=ip_port,
username=username, username=username,
password=password, password=password,
hub_version=hub_version,
loop=hass.loop, loop=hass.loop,
workdir=hass.config.config_dir) workdir=hass.config.config_dir)
else: else:

View File

@ -486,7 +486,7 @@ ihcsdk==2.2.0
influxdb==5.0.0 influxdb==5.0.0
# homeassistant.components.insteon # homeassistant.components.insteon
insteonplm==0.13.1 insteonplm==0.14.2
# homeassistant.components.sensor.iperf3 # homeassistant.components.sensor.iperf3
iperf3==0.1.10 iperf3==0.1.10