Skip to content
Merged
75 changes: 66 additions & 9 deletions homeassistant/components/insteon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

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,
CONF_PLATFORM,
CONF_ENTITY_ID,
CONF_HOST)
import homeassistant.helpers.config_validation as cv
from homeassistant.core import callback
from homeassistant.helpers import discovery
from homeassistant.helpers.entity import Entity

Expand Down Expand Up @@ -91,7 +91,7 @@ def set_default_port(schema: Dict) -> Dict:
vol.Optional(CONF_FIRMWARE): cv.byte,
vol.Optional(CONF_PRODUCT_KEY): cv.byte,
vol.Optional(CONF_PLATFORM): cv.string,
}))
}))

CONF_X10_SCHEMA = vol.All(
vol.Schema({
Expand Down Expand Up @@ -147,6 +147,45 @@ def set_default_port(schema: Dict) -> Dict:
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):
"""Set up the connection to the modem."""
Expand Down Expand Up @@ -478,12 +517,20 @@ def unique_id(self) -> str:
@property
def name(self):
"""Return the name of the node (used for Entity_ID)."""
name = ''
if self._insteon_device_state.group == 0x01:
name = self._insteon_device.id
else:
name = '{:s}_{:d}'.format(self._insteon_device.id,
self._insteon_device_state.group)
# Set a base description
description = self._insteon_device.description
if self._insteon_device.description is None:
description = 'Unknown Device'

# 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

@property
Expand Down Expand Up @@ -526,6 +573,16 @@ def _aldb_loaded(self):
"""All-Link Database loaded for the device."""
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):
"""Print the All-Link Database to the log file."""
Expand Down