Set InsteonEntity name to be combo of description and address. (#17262)
* Set InsteonEntity name to be combo of description and address. ie "LampLinc Dimmer 26453a" or "Keypad Dimmer 291abb_2" Using a centralized network name * Updated the name to have a more contextual references for device functions then just the group id. * Cleanup for hound * Removed the _generate_network_address function. Not used anymore * Cleanup for lint * clean for hound * Moved descriptor mapper to be a class variable of the InsteonEntity in order to fix lib loading issue for lint * Well, moved DescriptorMapper instance to a function variable now... * fix hound * Lint Cleanup * Clean up docstrings * Simplify Label lookup based on state name
This commit is contained in:
parent
7f9cc10447
commit
a30921e67d
1 changed files with 66 additions and 9 deletions
|
@ -10,12 +10,12 @@ from typing import Dict
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.core import callback
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.const import (CONF_PORT, EVENT_HOMEASSISTANT_STOP,
|
from homeassistant.const import (CONF_PORT, EVENT_HOMEASSISTANT_STOP,
|
||||||
CONF_PLATFORM,
|
CONF_PLATFORM,
|
||||||
CONF_ENTITY_ID,
|
CONF_ENTITY_ID,
|
||||||
CONF_HOST)
|
CONF_HOST)
|
||||||
import homeassistant.helpers.config_validation as cv
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers import discovery
|
from homeassistant.helpers import discovery
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
|
@ -147,6 +147,45 @@ X10_HOUSECODE_SCHEMA = vol.Schema({
|
||||||
vol.Required(SRV_HOUSECODE): vol.In(HOUSECODES),
|
vol.Required(SRV_HOUSECODE): vol.In(HOUSECODES),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
STATE_NAME_LABEL_MAP = {
|
||||||
|
'keypadButtonA': 'Button A',
|
||||||
|
'keypadButtonB': 'Button B',
|
||||||
|
'keypadButtonC': 'Button C',
|
||||||
|
'keypadButtonD': 'Button D',
|
||||||
|
'keypadButtonE': 'Button E',
|
||||||
|
'keypadButtonF': 'Button F',
|
||||||
|
'keypadButtonG': 'Button G',
|
||||||
|
'keypadButtonH': 'Button H',
|
||||||
|
'keypadButtonMain': 'Main',
|
||||||
|
'onOffButtonA': 'Button A',
|
||||||
|
'onOffButtonB': 'Button B',
|
||||||
|
'onOffButtonC': 'Button C',
|
||||||
|
'onOffButtonD': 'Button D',
|
||||||
|
'onOffButtonE': 'Button E',
|
||||||
|
'onOffButtonF': 'Button F',
|
||||||
|
'onOffButtonG': 'Button G',
|
||||||
|
'onOffButtonH': 'Button H',
|
||||||
|
'onOffButtonMain': 'Main',
|
||||||
|
'fanOnLevel': 'Fan',
|
||||||
|
'lightOnLevel': 'Light',
|
||||||
|
'coolSetPoint': 'Cool Set',
|
||||||
|
'heatSetPoint': 'HeatSet',
|
||||||
|
'statusReport': 'Status',
|
||||||
|
'generalSensor': 'Sensor',
|
||||||
|
'motionSensor': 'Motion',
|
||||||
|
'lightSensor': 'Light',
|
||||||
|
'batterySensor': 'Battery',
|
||||||
|
'dryLeakSensor': 'Dry',
|
||||||
|
'wetLeakSensor': 'Wet',
|
||||||
|
'heartbeatLeakSensor': 'Heartbeat',
|
||||||
|
'openClosedRelay': 'Relay',
|
||||||
|
'openClosedSensor': 'Sensor',
|
||||||
|
'lightOnOff': 'Light',
|
||||||
|
'outletTopOnOff': 'Top',
|
||||||
|
'outletBottomOnOff': 'Bottom',
|
||||||
|
'coverOpenLevel': 'Cover',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass, config):
|
||||||
"""Set up the connection to the modem."""
|
"""Set up the connection to the modem."""
|
||||||
|
@ -478,12 +517,20 @@ class InsteonEntity(Entity):
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the node (used for Entity_ID)."""
|
"""Return the name of the node (used for Entity_ID)."""
|
||||||
name = ''
|
# Set a base description
|
||||||
if self._insteon_device_state.group == 0x01:
|
description = self._insteon_device.description
|
||||||
name = self._insteon_device.id
|
if self._insteon_device.description is None:
|
||||||
else:
|
description = 'Unknown Device'
|
||||||
name = '{:s}_{:d}'.format(self._insteon_device.id,
|
|
||||||
self._insteon_device_state.group)
|
# Get an extension label if there is one
|
||||||
|
extension = self._get_label()
|
||||||
|
if extension:
|
||||||
|
extension = ' ' + extension
|
||||||
|
name = '{:s} {:s}{:s}'.format(
|
||||||
|
description,
|
||||||
|
self._insteon_device.address.human,
|
||||||
|
extension
|
||||||
|
)
|
||||||
return name
|
return name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -526,6 +573,16 @@ class InsteonEntity(Entity):
|
||||||
"""All-Link Database loaded for the device."""
|
"""All-Link Database loaded for the device."""
|
||||||
self.print_aldb()
|
self.print_aldb()
|
||||||
|
|
||||||
|
def _get_label(self):
|
||||||
|
"""Get the device label for grouped devices."""
|
||||||
|
label = ''
|
||||||
|
if len(self._insteon_device.states) > 1:
|
||||||
|
if self._insteon_device_state.name in STATE_NAME_LABEL_MAP:
|
||||||
|
label = STATE_NAME_LABEL_MAP[self._insteon_device_state.name]
|
||||||
|
else:
|
||||||
|
label = 'Group {:d}'.format(self.group)
|
||||||
|
return label
|
||||||
|
|
||||||
|
|
||||||
def print_aldb_to_log(aldb):
|
def print_aldb_to_log(aldb):
|
||||||
"""Print the All-Link Database to the log file."""
|
"""Print the All-Link Database to the log file."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue