Merge insteon_plm and insteon_local to insteon component (#16102)
* Implement X10 * Add X10 after add_device_callback * Ref device by id not hex and add x10OnOffSwitch name * X10 services and add sensor device * Correctly reference X10_HOUSECODE_SCHEMA * Log adding of X10 devices * Add X10 All Units Off, All Lights On and All Lights Off devices * Correct ref to X10 states vs devices * Add X10 All Units Off, All Lights On and All Lights Off devices * Correct X10 config * Debug x10 device additions * Config x10 from bool to housecode char * Pass PLM to X10 device create * Remove PLM to call to add_x10_device * Unconfuse x10 config and method names * Correct spelling of x10_all_lights_off_housecode * Bump insteonplm to 0.10.0 to support X10 * Add host to config options * Add username and password to config for hub connectivity * Add username and password to config for hub * Convert port to int if host is defined * Add KeypadLinc * Update config schema to require either port or host * Solidify Hub and PLM configuration to ensure proper settings * Update hub schema * Bump insteonplm version * Fix pylint and flake issues * Bump insteonplm to 0.12.1 * Merge insteon_plm and insteon_local to insteon * Rename insteon_plm to insteon * Bump insteonplm to 0.12.2 * Flake8 cleanup * Update .coveragerc for insteon_plm, insteon_local and insteon changes * Add persistent notification * Fix reference to insteon_plm * Fix indentation * Shorten message and fix grammer * Add comment to remove in release 0.90 * Hound fix
This commit is contained in:
1 parent
6864a44b5a
commit
a31501d99e
14 files changed
+204
-474
No files matched your search
+12
-13
@@ -2,26 +2,26 @@
|
||||
Support for INSTEON dimmers via PowerLinc Modem.
|
||||
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/switch.insteon_plm/
|
||||
https://home-assistant.io/components/switch.insteon/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from homeassistant.components.insteon_plm import InsteonPLMEntity
|
||||
from homeassistant.components.insteon import InsteonEntity
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
|
||||
DEPENDENCIES = ['insteon_plm']
|
||||
DEPENDENCIES = ['insteon']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
"""Set up the INSTEON PLM device class for the hass platform."""
|
||||
plm = hass.data['insteon_plm'].get('plm')
|
||||
"""Set up the INSTEON device class for the hass platform."""
|
||||
insteon_modem = hass.data['insteon'].get('modem')
|
||||
|
||||
address = discovery_info['address']
|
||||
device = plm.devices[address]
|
||||
device = insteon_modem.devices[address]
|
||||
state_key = discovery_info['state_key']
|
||||
|
||||
state_name = device.states[state_key].name
|
||||
@@ -30,17 +30,16 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
device.address.hex, device.states[state_key].name)
|
||||
|
||||
new_entity = None
|
||||
if state_name in ['lightOnOff', 'outletTopOnOff', 'outletBottomOnOff',
|
||||
'x10OnOffSwitch']:
|
||||
new_entity = InsteonPLMSwitchDevice(device, state_key)
|
||||
elif state_name == 'openClosedRelay':
|
||||
new_entity = InsteonPLMOpenClosedDevice(device, state_key)
|
||||
if state_name == 'openClosedRelay':
|
||||
new_entity = InsteonOpenClosedDevice(device, state_key)
|
||||
else:
|
||||
new_entity = InsteonSwitchDevice(device, state_key)
|
||||
|
||||
if new_entity is not None:
|
||||
async_add_devices([new_entity])
|
||||
|
||||
|
||||
class InsteonPLMSwitchDevice(InsteonPLMEntity, SwitchDevice):
|
||||
class InsteonSwitchDevice(InsteonEntity, SwitchDevice):
|
||||
"""A Class for an Insteon device."""
|
||||
|
||||
@property
|
||||
@@ -59,7 +58,7 @@ class InsteonPLMSwitchDevice(InsteonPLMEntity, SwitchDevice):
|
||||
self._insteon_device_state.off()
|
||||
|
||||
|
||||
class InsteonPLMOpenClosedDevice(InsteonPLMEntity, SwitchDevice):
|
||||
class InsteonOpenClosedDevice(InsteonEntity, SwitchDevice):
|
||||
"""A Class for an Insteon device."""
|
||||
|
||||
@property
|
||||
@@ -1,83 +0,0 @@
|
||||
"""
|
||||
Support for Insteon switch devices via local hub support.
|
||||
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/switch.insteon_local/
|
||||
"""
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant import util
|
||||
|
||||
_CONFIGURING = {}
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEPENDENCIES = ['insteon_local']
|
||||
DOMAIN = 'switch'
|
||||
|
||||
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100)
|
||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the Insteon local switch platform."""
|
||||
insteonhub = hass.data['insteon_local']
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
linked = discovery_info['linked']
|
||||
device_list = []
|
||||
for device_id in linked:
|
||||
if linked[device_id]['cat_type'] == 'switch':
|
||||
device = insteonhub.switch(device_id)
|
||||
device_list.append(
|
||||
InsteonLocalSwitchDevice(device)
|
||||
)
|
||||
|
||||
add_devices(device_list)
|
||||
|
||||
|
||||
class InsteonLocalSwitchDevice(SwitchDevice):
|
||||
"""An abstract Class for an Insteon node."""
|
||||
|
||||
def __init__(self, node):
|
||||
"""Initialize the device."""
|
||||
self.node = node
|
||||
self._state = False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the node."""
|
||||
return self.node.device_id
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the ID of this Insteon node."""
|
||||
return self.node.device_id
|
||||
|
||||
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
|
||||
def update(self):
|
||||
"""Get the updated status of the switch."""
|
||||
resp = self.node.status(0)
|
||||
|
||||
while 'error' in resp and resp['error'] is True:
|
||||
resp = self.node.status(0)
|
||||
|
||||
if 'cmd2' in resp:
|
||||
self._state = int(resp['cmd2'], 16) > 0
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return the boolean response if the node is on."""
|
||||
return self._state
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn device on."""
|
||||
self.node.on()
|
||||
self._state = True
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn device off."""
|
||||
self.node.off()
|
||||
self._state = False
|
||||
Reference in new issue
Block a user