Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
be3064a
Setup all-linking service
teharris1 Apr 15, 2018
55798c6
Remove extra line
teharris1 Apr 15, 2018
4d9d25d
Remove linefeed and tab escape chars
teharris1 Apr 15, 2018
eda460c
Add services delete_all_link, load_all_link_database and print_all_li…
teharris1 Apr 15, 2018
e81872c
Check if reload is set
teharris1 Apr 15, 2018
145e849
Confirm entity is InsteonPLMEntity before attempting to load or print…
teharris1 Apr 15, 2018
5fe240a
Debug load and print ALDB
teharris1 Apr 15, 2018
ce35e07
Debug print aldb
teharris1 Apr 15, 2018
2378f3a
Debug print_aldb
teharris1 Apr 15, 2018
e805acd
Get entity via platform
teharris1 Apr 16, 2018
603fcdb
Track Insteon entities in component
teharris1 Apr 16, 2018
adc1073
Store entity list in hass.data
teharris1 Apr 16, 2018
db22601
Add entity to hass.data
teharris1 Apr 16, 2018
52c870c
Add ref to hass in InsteonPLMEntity
teharris1 Apr 16, 2018
a51cef8
Pass hass correctly to InsteonPLMBinarySensor
teharris1 Apr 16, 2018
d527435
Fix reference to ALDBStatus.PARTIAL
teharris1 Apr 16, 2018
decc72f
Print ALDB record as string
teharris1 Apr 16, 2018
69f93ae
Get ALDB record from memory address
teharris1 Apr 16, 2018
a0b5082
Reformat ALDB log output
teharris1 Apr 16, 2018
5a9f041
Add print_im_aldb service
teharris1 Apr 20, 2018
1c93eac
Remove reference to self in print_aldb_to_log
teharris1 Apr 20, 2018
8d3332e
Remove reference to self in print_aldb_to_log
teharris1 Apr 20, 2018
3f9804e
Fix spelling issue with load_all_link_database service
teharris1 Apr 20, 2018
875dc50
Merge remote-tracking branch 'remote/dev' into all-linking
teharris1 Apr 21, 2018
1c30d74
Merge remote-tracking branch 'remote/dev' into all-linking
teharris1 Apr 24, 2018
ea3cb13
Bump insteonplm to 0.9.1
teharris1 Apr 24, 2018
fe3f2da
Changes from code review
teharris1 May 3, 2018
a45ef02
Code review changes
teharris1 May 3, 2018
11c7eaf
Merge remote-tracking branch 'remote/dev' into all-linking
teharris1 May 3, 2018
218a8be
Fix syntax error
teharris1 May 3, 2018
cd959f9
Correct reference to cv.boolean and update requirements
teharris1 May 3, 2018
9699000
Update requirements
teharris1 May 3, 2018
52665f6
Fix flake8 errors
teharris1 May 3, 2018
fa63eee
Reload as boolean test
teharris1 May 3, 2018
e4c1ff7
Remove hass from entity init
teharris1 May 3, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/binary_sensor/insteon_plm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@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']
plm = hass.data['insteon_plm'].get('plm')

address = discovery_info['address']
device = plm.devices[address]
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/fan/insteon_plm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@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']
plm = hass.data['insteon_plm'].get('plm')

address = discovery_info['address']
device = plm.devices[address]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

from homeassistant.core import callback
from homeassistant.const import (CONF_PORT, EVENT_HOMEASSISTANT_STOP,
CONF_PLATFORM)
CONF_PLATFORM,
CONF_ENTITY_ID)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers import discovery
from homeassistant.helpers.entity import Entity

REQUIREMENTS = ['insteonplm==0.8.6']
REQUIREMENTS = ['insteonplm==0.9.1']

_LOGGER = logging.getLogger(__name__)

Expand All @@ -29,6 +30,17 @@
CONF_FIRMWARE = 'firmware'
CONF_PRODUCT_KEY = 'product_key'

SRV_ADD_ALL_LINK = 'add_all_link'
SRV_DEL_ALL_LINK = 'delete_all_link'
SRV_LOAD_ALDB = 'load_all_link_database'
SRV_PRINT_ALDB = 'print_all_link_database'
SRV_PRINT_IM_ALDB = 'print_im_all_link_database'
SRV_ALL_LINK_GROUP = 'group'
SRV_ALL_LINK_MODE = 'mode'
SRV_LOAD_DB_RELOAD = 'reload'
SRV_CONTROLLER = 'controller'
SRV_RESPONDER = 'responder'

CONF_DEVICE_OVERRIDE_SCHEMA = vol.All(
cv.deprecated(CONF_PLATFORM), vol.Schema({
vol.Required(CONF_ADDRESS): cv.string,
Expand All @@ -47,13 +59,32 @@
})
}, extra=vol.ALLOW_EXTRA)

ADD_ALL_LINK_SCHEMA = vol.Schema({
vol.Required(SRV_ALL_LINK_GROUP): vol.Range(min=0, max=255),
vol.Required(SRV_ALL_LINK_MODE): vol.In([SRV_CONTROLLER, SRV_RESPONDER]),
})

DEL_ALL_LINK_SCHEMA = vol.Schema({
vol.Required(SRV_ALL_LINK_GROUP): vol.Range(min=0, max=255),
})

LOAD_ALDB_SCHEMA = vol.Schema({
vol.Required(CONF_ENTITY_ID): cv.entity_id,
vol.Optional(SRV_LOAD_DB_RELOAD, default='false'): cv.boolean,
})

PRINT_ALDB_SCHEMA = vol.Schema({
vol.Required(CONF_ENTITY_ID): cv.entity_id,
})


@asyncio.coroutine
def async_setup(hass, config):
"""Set up the connection to the PLM."""
import insteonplm

ipdb = IPDB()
plm = None
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected spaces around keyword / parameter equals

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected spaces around keyword / parameter equals


conf = config[DOMAIN]
port = conf.get(CONF_PORT)
Expand All @@ -79,6 +110,60 @@ def async_plm_new_device(device):
'state_key': state_key},
hass_config=config))

def add_all_link(service):
"""Add an INSTEON All-Link between two devices."""
group = service.data.get(SRV_ALL_LINK_GROUP)
mode = service.data.get(SRV_ALL_LINK_MODE)
link_mode = 1 if mode.lower() == SRV_CONTROLLER else 0
plm.start_all_linking(link_mode, group)

def del_all_link(service):
"""Delete an INSTEON All-Link between two devices."""
group = service.data.get(SRV_ALL_LINK_GROUP)
plm.start_all_linking(255, group)

def load_aldb(service):
"""Load the device All-Link database."""
entity_id = service.data.get(CONF_ENTITY_ID)
reload = service.data.get(SRV_LOAD_DB_RELOAD)
entities = hass.data[DOMAIN].get('entities')
entity = entities.get(entity_id)
if entity:
entity.load_aldb(reload)
else:
_LOGGER.error('Entity %s is not an INSTEON device', entity_id)

def print_aldb(service):
"""Print the All-Link Database for a device."""
# For now this sends logs to the log file.
# Furture direction is to create an INSTEON control panel.
entity_id = service.data.get(CONF_ENTITY_ID)
entities = hass.data[DOMAIN].get('entities')
entity = entities.get(entity_id)
if entity:
entity.print_aldb()
else:
_LOGGER.error('Entity %s is not an INSTEON device', entity_id)

def print_im_aldb(service):
"""Print the All-Link Database for a device."""
# For now this sends logs to the log file.
# Furture direction is to create an INSTEON control panel.
print_aldb_to_log(plm.aldb)

def _register_services():
hass.services.register(DOMAIN, SRV_ADD_ALL_LINK, add_all_link,
schema=ADD_ALL_LINK_SCHEMA)
hass.services.register(DOMAIN, SRV_DEL_ALL_LINK, del_all_link,
schema=DEL_ALL_LINK_SCHEMA)
hass.services.register(DOMAIN, SRV_LOAD_ALDB, load_aldb,
schema=LOAD_ALDB_SCHEMA)
hass.services.register(DOMAIN, SRV_PRINT_ALDB, print_aldb,
schema=PRINT_ALDB_SCHEMA)
hass.services.register(DOMAIN, SRV_PRINT_IM_ALDB, print_im_aldb,
schema=None)
_LOGGER.debug("Insteon_plm Services registered")

_LOGGER.info("Looking for PLM on %s", port)
conn = yield from insteonplm.Connection.create(
device=port,
Expand All @@ -100,11 +185,14 @@ def async_plm_new_device(device):
plm.devices.add_override(address, CONF_PRODUCT_KEY,
device_override[prop])

hass.data['insteon_plm'] = plm
hass.data[DOMAIN] = {}
hass.data[DOMAIN]['plm'] = plm
hass.data[DOMAIN]['entities'] = {}

hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, conn.close)

plm.devices.add_device_callback(async_plm_new_device)
hass.async_add_job(_register_services)

return True

Expand Down Expand Up @@ -169,6 +257,7 @@ def __init__(self, device, state_key):
"""Initialize the INSTEON PLM binary sensor."""
self._insteon_device_state = device.states[state_key]
self._insteon_device = device
self._insteon_device.aldb.add_loaded_callback(self._aldb_loaded)

@property
def should_poll(self):
Expand Down Expand Up @@ -215,3 +304,44 @@ def async_added_to_hass(self):
"""Register INSTEON update events."""
self._insteon_device_state.register_updates(
self.async_entity_update)
self.hass.data[DOMAIN]['entities'][self.entity_id] = self

def load_aldb(self, reload=False):
"""Load the device All-Link Database."""
if reload:
self._insteon_device.aldb.clear()
self._insteon_device.read_aldb()

def print_aldb(self):
"""Print the device ALDB to the log file."""
print_aldb_to_log(self._insteon_device.aldb)

@callback
def _aldb_loaded(self):
"""All-Link Database loaded for the device."""
self.print_aldb()


def print_aldb_to_log(aldb):
"""Print the All-Link Database to the log file."""
from insteonplm.devices import ALDBStatus
_LOGGER.info('ALDB load status is %s', aldb.status.name)
if aldb.status not in [ALDBStatus.LOADED, ALDBStatus.PARTIAL]:
_LOGGER.warning('Device All-Link database not loaded')
_LOGGER.warning('Use service insteon_plm.load_aldb first')
return

_LOGGER.info('RecID In Use Mode HWM Group Address Data 1 Data 2 Data 3')
_LOGGER.info('----- ------ ---- --- ----- -------- ------ ------ ------')
for mem_addr in aldb:
rec = aldb[mem_addr]
# For now we write this to the log
# Roadmap is to create a configuration panel
in_use = 'Y' if rec.control_flags.is_in_use else 'N'
mode = 'C' if rec.control_flags.is_controller else 'R'
hwm = 'Y' if rec.control_flags.is_high_water_mark else 'N'
_LOGGER.info(' {:04x} {:s} {:s} {:s} {:3d} {:s}'
' {:3d} {:3d} {:3d}'.format(
rec.mem_addr, in_use, mode, hwm,
rec.group, rec.address.human,
rec.data1, rec.data2, rec.data3))
32 changes: 32 additions & 0 deletions homeassistant/components/insteon_plm/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
add_all_link:
description: Tells the Insteom Modem (IM) start All-Linking mode. Once the the IM is in All-Linking mode, press the link button on the device to complete All-Linking.
fields:
group:
description: All-Link group number.
example: 1
mode:
description: Linking mode controller - IM is controller responder - IM is responder
example: 'controller'
delete_all_link:
description: Tells the Insteon Modem (IM) to remove an All-Link record from the All-Link Database of the IM and a device. Once the IM is set to delete the link, press the link button on the corresponding device to complete the process.
fields:
group:
description: All-Link group number.
example: 1
load_all_link_database:
description: Load the All-Link Database for a device. WARNING - Loading a device All-LInk database is very time consuming and inconsistant. This may take a LONG time and may need to be repeated to obtain all records.
fields:
entity_id:
description: Name of the device to print
example: 'light.1a2b3c'
reload:
description: Reload all records. If true the current records are cleared from memory (does not effect the device) and the records are reloaded. If false the existing records are left in place and only missing records are added. Default is false.
example: 'true'
print_all_link_database:
description: Print the All-Link Database for a device. Requires that the All-Link Database is loaded into memory.
fields:
entity_id:
description: Name of the device to print
example: 'light.1a2b3c'
print_im_all_link_database:
description: Print the All-Link Database for the INSTEON Modem (IM).
2 changes: 1 addition & 1 deletion homeassistant/components/light/insteon_plm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
"""Set up the Insteon PLM device."""
plm = hass.data['insteon_plm']
plm = hass.data['insteon_plm'].get('plm')

address = discovery_info['address']
device = plm.devices[address]
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/insteon_plm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@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']
plm = hass.data['insteon_plm'].get('plm')

address = discovery_info['address']
device = plm.devices[address]
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/switch/insteon_plm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@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']
plm = hass.data['insteon_plm'].get('plm')

address = discovery_info['address']
device = plm.devices[address]
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ influxdb==5.0.0
insteonlocal==0.53

# homeassistant.components.insteon_plm
insteonplm==0.8.6
insteonplm==0.9.1

# homeassistant.components.verisure
jsonpath==0.75
Expand Down