Code review adjustments
parent
7037b08f45
commit
2a7cc56208
|
@ -15,6 +15,10 @@ DEPENDENCIES = ['insteon_plm']
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SENSOR_TYPES = {'openClosedSensor': 'opening',
|
||||
'motionSensor': 'motion',
|
||||
'doorSensor': 'door',
|
||||
'leakSensor': 'moisture'}
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
|
@ -29,9 +33,6 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||
stateKey = deviceInfo['stateKey']
|
||||
newnames = deviceInfo['newnames']
|
||||
|
||||
_LOGGER.info(
|
||||
'Registered device %s state %s with binary_sensor platform %s',
|
||||
device.address, device.states[stateKey].name)
|
||||
state_list.append(InsteonPLMBinarySensor(hass,
|
||||
device,
|
||||
stateKey,
|
||||
|
@ -63,21 +64,18 @@ class InsteonPLMBinarySensor(BinarySensorDevice):
|
|||
"""Return the address of the node."""
|
||||
return self._device.address.human
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""Return the name of the node."""
|
||||
return self._device.id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the node. (used for Entity_ID)"""
|
||||
name = ''
|
||||
if self._newnames:
|
||||
return self._device.id + '_' + self._state.name
|
||||
name = '{:s}_{:s}'.format(self._device.id, self._state.name)
|
||||
else:
|
||||
if self._state.group == 0x01:
|
||||
return self._device.id
|
||||
name = self._device.id
|
||||
else:
|
||||
return self._device.id+'_'+str(self._state.group)
|
||||
name = '{:s}_{:d}'.format(self._device.id, self._state.group)
|
||||
return name
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
|
@ -88,31 +86,16 @@ class InsteonPLMBinarySensor(BinarySensorDevice):
|
|||
@callback
|
||||
def async_binarysensor_update(self, deviceid, statename, val):
|
||||
"""Receive notification from transport that new data exists."""
|
||||
_LOGGER.info('Received update calback from PLM for device %s state %s',
|
||||
deviceid, statename)
|
||||
self._hass.async_add_job(self.async_update_ha_state())
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the class of this sensor."""
|
||||
return self._sensor_type
|
||||
return SENSOR_TYPES.get(self._sensor_type, None)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return the boolean response if the node is on."""
|
||||
sensorstate = self._state.value
|
||||
_LOGGER.info("Sensor for device %s state %s is %s",
|
||||
self.id, self._state.name, sensorstate)
|
||||
return bool(sensorstate)
|
||||
|
||||
def _stateName_to_sensor_type(self, stateName):
|
||||
if stateName == 'openClosedSensor ':
|
||||
return 'opening'
|
||||
elif stateName == 'motionSensor':
|
||||
return 'motion'
|
||||
elif stateName == 'doorSensor':
|
||||
return 'door'
|
||||
elif stateName == 'leakSensor':
|
||||
return 'moisture'
|
||||
else:
|
||||
return ""
|
||||
|
|
|
@ -68,21 +68,18 @@ class InsteonPLMFan(FanEntity):
|
|||
"""Return the address of the node."""
|
||||
return self._device.address.human
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""Return the name of the node."""
|
||||
return self._device.id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the node. (used for Entity_ID)"""
|
||||
name = ''
|
||||
if self._newnames:
|
||||
return self._device.id + '_' + self._state.name
|
||||
name = '{:s}_{:s}'.format(self._device.id, self._state.name)
|
||||
else:
|
||||
if self._state.group == 0x01:
|
||||
return self._device.id
|
||||
name = self._device.id
|
||||
else:
|
||||
return self._device.id+'_'+str(self._state.group)
|
||||
name = '{:s}_{:d}'.format(self._device.id, self._state.group)
|
||||
return name
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
|
@ -121,9 +118,6 @@ class InsteonPLMFan(FanEntity):
|
|||
@callback
|
||||
def async_fan_update(self, deviceid, statename, val):
|
||||
"""Receive notification from transport that new data exists."""
|
||||
_LOGGER.info('Received update calback from PLM for device %s state %s',
|
||||
deviceid,
|
||||
statename)
|
||||
self.hass.async_add_job(self.async_update_ha_state())
|
||||
|
||||
@property
|
||||
|
|
|
@ -27,9 +27,9 @@ CONF_NEWNAMES = 'new_names'
|
|||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Required(CONF_PORT): cv.string,
|
||||
vol.Optional(CONF_OVERRIDE, default=[]): vol.All(
|
||||
vol.Optional(CONF_OVERRIDE): vol.All(
|
||||
cv.ensure_list_csv, vol.Length(min=1)),
|
||||
vol.Optional(CONF_NEWNAMES, default=['no']): cv.string
|
||||
vol.Optional(CONF_NEWNAMES, default=False): cv.boolean
|
||||
})
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
@ -43,21 +43,13 @@ def async_setup(hass, config):
|
|||
|
||||
conf = config[DOMAIN]
|
||||
port = conf.get(CONF_PORT)
|
||||
overrides = conf.get(CONF_OVERRIDE)
|
||||
newnames = conf.get(CONF_NEWNAMES)
|
||||
|
||||
if isinstance(newnames, list):
|
||||
newnames = ''
|
||||
use_newnames = False
|
||||
if newnames.lower() == 'y' or newnames.lower() == 'yes':
|
||||
use_newnames = True
|
||||
overrides = conf.get(CONF_OVERRIDE, [])
|
||||
use_newnames = conf.get(CONF_NEWNAMES)
|
||||
|
||||
@callback
|
||||
def async_plm_new_device(device):
|
||||
"""Detect device from transport to be delegated to platform."""
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
_LOGGER.debug('Starting Home-Assistant async_plm_new_device')
|
||||
_LOGGER.debug(device)
|
||||
|
||||
for stateKey in device.states:
|
||||
platformInfo = ipdb[device.states[stateKey]]
|
||||
platform = platformInfo.platform
|
||||
|
@ -75,8 +67,6 @@ def async_setup(hass, config):
|
|||
'newnames': use_newnames}],
|
||||
hass_config=config))
|
||||
|
||||
_LOGGER.debug('Starting Home-Assistant async_plm_new_device')
|
||||
_LOGGER.info('Config dir %s', hass.config.config_dir)
|
||||
_LOGGER.info("Looking for PLM on %s", port)
|
||||
conn = yield from insteonplm.Connection.create(
|
||||
device=port,
|
||||
|
@ -136,37 +126,37 @@ class IPDB(object):
|
|||
"""Embodies the INSTEON Product Database static data
|
||||
and access methods."""
|
||||
|
||||
from insteonplm.states.onOff import (OnOffSwitch,
|
||||
OnOffSwitch_OutletTop,
|
||||
OnOffSwitch_OutletBottom,
|
||||
OpenClosedRelay)
|
||||
|
||||
from insteonplm.states.dimmable import (DimmableSwitch,
|
||||
DimmableSwitch_Fan)
|
||||
|
||||
from insteonplm.states.sensor import (VariableSensor,
|
||||
OnOffSensor,
|
||||
SmokeCO2Sensor,
|
||||
IoLincSensor)
|
||||
|
||||
states = [
|
||||
State(OnOffSwitch_OutletTop, 'switch'),
|
||||
State(OnOffSwitch_OutletBottom, 'switch'),
|
||||
State(OpenClosedRelay, 'switch'),
|
||||
State(OnOffSwitch, 'switch'),
|
||||
|
||||
State(IoLincSensor, 'binary_sensor'),
|
||||
State(SmokeCO2Sensor, 'sensor'),
|
||||
State(OnOffSensor, 'binary_sensor'),
|
||||
State(VariableSensor, 'sensor'),
|
||||
|
||||
State(DimmableSwitch_Fan, 'fan'),
|
||||
State(DimmableSwitch, 'light')
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
|
||||
from insteonplm.states.onOff import (OnOffSwitch,
|
||||
OnOffSwitch_OutletTop,
|
||||
OnOffSwitch_OutletBottom,
|
||||
OpenClosedRelay)
|
||||
|
||||
from insteonplm.states.dimmable import (DimmableSwitch,
|
||||
DimmableSwitch_Fan)
|
||||
|
||||
from insteonplm.states.sensor import (VariableSensor,
|
||||
OnOffSensor,
|
||||
SmokeCO2Sensor,
|
||||
IoLincSensor)
|
||||
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
self.states = [State(OnOffSwitch_OutletTop, 'switch'),
|
||||
State(OnOffSwitch_OutletBottom, 'switch'),
|
||||
State(OpenClosedRelay, 'switch'),
|
||||
State(OnOffSwitch, 'switch'),
|
||||
|
||||
State(IoLincSensor, 'binary_sensor'),
|
||||
State(SmokeCO2Sensor, 'sensor'),
|
||||
State(OnOffSensor, 'binary_sensor'),
|
||||
State(VariableSensor, 'sensor'),
|
||||
|
||||
State(DimmableSwitch_Fan, 'fan'),
|
||||
State(DimmableSwitch, 'light')
|
||||
]
|
||||
|
||||
def __len__(self):
|
||||
return len(self.states)
|
||||
|
||||
|
|
|
@ -62,34 +62,28 @@ class InsteonPLMDimmerDevice(Light):
|
|||
"""Return the address of the node."""
|
||||
return self._device.address.human
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""Return the name of the node."""
|
||||
return self._device.id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the node. (used for Entity_ID)"""
|
||||
name = ''
|
||||
if self._newnames:
|
||||
return self._device.id + '_' + self._state.name
|
||||
name = '{:s}_{:s}'.format(self._device.id, self._state.name)
|
||||
else:
|
||||
if self._state.group == 0x01:
|
||||
return self._device.id
|
||||
name = self._device.id
|
||||
else:
|
||||
return self._device.id+'_'+str(self._state.group)
|
||||
name = '{:s}_{:d}'.format(self._device.id, self._state.group)
|
||||
return name
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
onlevel = self._state.value
|
||||
_LOGGER.debug("on level for %s is %s", self._device.address, onlevel)
|
||||
return int(onlevel)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return the boolean response if the node is on."""
|
||||
_LOGGER.debug("on level for %s is %s",
|
||||
self._device.id, self.brightness)
|
||||
return bool(self.brightness)
|
||||
|
||||
@property
|
||||
|
@ -106,7 +100,6 @@ class InsteonPLMDimmerDevice(Light):
|
|||
@callback
|
||||
def async_light_update(self, entity_id, statename, val):
|
||||
"""Receive notification from transport that new data exists."""
|
||||
_LOGGER.info("Received update calback from PLM for %s", self.id)
|
||||
self._hass.async_add_job(self.async_update_ha_state())
|
||||
|
||||
@asyncio.coroutine
|
||||
|
|
|
@ -59,27 +59,23 @@ class InsteonPLMSensorDevice(Entity):
|
|||
"""Return the address of the node."""
|
||||
return self._device.address.human
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""Return the name of the node."""
|
||||
return self._device.id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the node. (used for Entity_ID)"""
|
||||
name = ''
|
||||
if self._newnames:
|
||||
return self._device.id + '_' + self._state.name
|
||||
name = '{:s}_{:s}'.format(self._device.id, self._state.name)
|
||||
else:
|
||||
if self._state.group == 0x01:
|
||||
return self._device.id
|
||||
name = self._device.id
|
||||
else:
|
||||
return self._device.id+'_'+str(self._state.group)
|
||||
name = '{:s}_{:d}'.format(self._device.id, self._state.group)
|
||||
return name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
sensorstate = self._state.value
|
||||
_LOGGER.info("Sensor state for {} is {}", self.id, sensorstate)
|
||||
return sensorstate
|
||||
|
||||
@property
|
||||
|
@ -91,5 +87,4 @@ class InsteonPLMSensorDevice(Entity):
|
|||
@callback
|
||||
def async_sensor_update(self, deviceid, statename, val):
|
||||
"""Receive notification from transport that new data exists."""
|
||||
_LOGGER.info("Received update calback from PLM for %s", self.id)
|
||||
self._hass.async_add_job(self.async_update_ha_state())
|
||||
|
|
|
@ -67,27 +67,23 @@ class InsteonPLMSwitchDevice(SwitchDevice):
|
|||
"""Return the address of the node."""
|
||||
return self._device.address.human
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""Return the name of the node."""
|
||||
return self._device.id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the node. (used for Entity_ID)"""
|
||||
name = ''
|
||||
if self._newnames:
|
||||
return self._device.id + '_' + self._state.name
|
||||
name = '{:s}_{:s}'.format(self._device.id, self._state.name)
|
||||
else:
|
||||
if self._state.group == 0x01:
|
||||
return self._device.id
|
||||
name = self._device.id
|
||||
else:
|
||||
return self._device.id+'_'+str(self._state.group)
|
||||
name = '{:s}_{:d}'.format(self._device.id, self._state.group)
|
||||
return name
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return the boolean response if the node is on."""
|
||||
onlevel = self._state.value
|
||||
_LOGGER.debug('on level for %s is %s', self._device.id, onlevel)
|
||||
return bool(onlevel)
|
||||
|
||||
@property
|
||||
|
@ -99,8 +95,6 @@ class InsteonPLMSwitchDevice(SwitchDevice):
|
|||
@callback
|
||||
def async_switch_update(self, deviceid, statename, val):
|
||||
"""Receive notification from transport that new data exists."""
|
||||
_LOGGER.info('Received update calback from PLM for %s',
|
||||
self._device.id)
|
||||
self._hass.async_add_job(self.async_update_ha_state())
|
||||
|
||||
@asyncio.coroutine
|
||||
|
@ -136,11 +130,6 @@ class InsteonPLMOpenClosedDevice(SwitchDevice):
|
|||
"""Return the address of the node."""
|
||||
return self._device.address.human
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""Return the name of the node."""
|
||||
return self._device.id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the node. (used for Entity_ID)"""
|
||||
|
@ -156,7 +145,6 @@ class InsteonPLMOpenClosedDevice(SwitchDevice):
|
|||
def is_on(self):
|
||||
"""Return the boolean response if the node is on."""
|
||||
onlevel = self._state.value
|
||||
_LOGGER.debug('on level for %s is %s', self._device.id, onlevel)
|
||||
return bool(onlevel)
|
||||
|
||||
@property
|
||||
|
@ -168,8 +156,6 @@ class InsteonPLMOpenClosedDevice(SwitchDevice):
|
|||
@callback
|
||||
def async_relay_update(self, deviceid, statename, val):
|
||||
"""Receive notification from transport that new data exists."""
|
||||
_LOGGER.info('Received update calback from PLM for %s',
|
||||
self._device.id)
|
||||
self._hass.async_add_job(self.async_update_ha_state())
|
||||
|
||||
@asyncio.coroutine
|
||||
|
|
Loading…
Reference in New Issue