rename _device and _state to avoid conflicts with Entity

This commit is contained in:
Tom Harris
2018-02-19 16:12:25 -05:00
parent e077806bc2
commit 5bef1fc741
6 changed files with 99 additions and 99 deletions

View File

@@ -27,14 +27,14 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
state_list = []
plm = hass.data['insteon_plm']
for deviceInfo in discovery_info:
address = deviceInfo['address']
for device_info in discovery_info:
address = device_info['address']
device = plm.devices[address]
stateKey = deviceInfo['stateKey']
state_key = device_info['state_key']
state_list.append(InsteonPLMBinarySensor(hass,
device,
stateKey))
state_key))
async_add_devices(state_list)
@@ -42,14 +42,14 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
class InsteonPLMBinarySensor(BinarySensorDevice):
"""A Class for an Insteon device state."""
def __init__(self, hass, device, stateKey):
def __init__(self, hass, device, state_key):
"""Initialize the binarysensor."""
self._hass = hass
self._state = device.states[stateKey]
self._device = device
self._sensor_type = SENSOR_TYPES.get(self._state.name, None)
self._insteon_device_state = device.states[state_key]
self._insteon_device = device
self._sensor_type = SENSOR_TYPES.get(self._insteon_device_state.name, None)
self._state.register_updates(self.async_binarysensor_update)
self._insteon_device_state.register_updates(self.async_binarysensor_update)
@property
def should_poll(self):
@@ -59,23 +59,23 @@ class InsteonPLMBinarySensor(BinarySensorDevice):
@property
def address(self):
"""Return the address of the node."""
return self._device.address.human
return self._insteon_device.address.human
@property
def name(self):
"""Return the name of the node. (used for Entity_ID)"""
name = ''
if self._state.group == 0x01:
name = self._device.id
if self._insteon_device_state.group == 0x01:
name = self._insteon_device.id
else:
name = '{:s}_{:d}'.format(self._device.id, self._state.group)
name = '{:s}_{:d}'.format(self._insteon_device.id, self._insteon_device_state.group)
return name
@property
def device_state_attributes(self):
"""Provide attributes for display on device card."""
insteon_plm = get_component('insteon_plm')
return insteon_plm.common_attributes(self._device, self._state)
return insteon_plm.common_attributes(self._insteon_device, self._insteon_device_state)
@callback
def async_binarysensor_update(self, deviceid, statename, val):
@@ -90,5 +90,5 @@ class InsteonPLMBinarySensor(BinarySensorDevice):
@property
def is_on(self):
"""Return the boolean response if the node is on."""
sensorstate = self._state.value
sensorstate = self._insteon_device_state.value
return bool(sensorstate)

View File

@@ -34,14 +34,14 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
state_list = []
plm = hass.data['insteon_plm']
for deviceInfo in discovery_info:
address = deviceInfo['address']
for device_info in discovery_info:
address = device_info['address']
device = plm.devices[address]
stateKey = deviceInfo['stateKey']
state_key = device_info['state_key']
state_list.append(InsteonPLMFan(hass,
device,
stateKey,
state_key,
SUPPORT_SET_SPEED))
async_add_devices(state_list)
@@ -50,15 +50,15 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
class InsteonPLMFan(FanEntity):
"""An INSTEON fan component."""
def __init__(self, hass, device, stateKey,
def __init__(self, hass, device, state_key,
supported_features: int, ) -> None:
"""Initialize the entity."""
self._hass = hass
self._state = device.states[stateKey]
self._device = device
self._insteon_device_state = device.states[state_key]
self._insteon_device = device
self._supported_features = supported_features
self._state.register_updates(self.async_fan_update)
self._insteon_device_state.register_updates(self.async_fan_update)
@property
def should_poll(self):
@@ -68,28 +68,28 @@ class InsteonPLMFan(FanEntity):
@property
def address(self):
"""Return the address of the node."""
return self._device.address.human
return self._insteon_device.address.human
@property
def name(self):
"""Return the name of the node. (used for Entity_ID)"""
name = ''
if self._state.group == 0x01:
name = self._device.id
if self._insteon_device_state.group == 0x01:
name = self._insteon_device.id
else:
name = '{:s}_{:d}'.format(self._device.id, self._state.group)
name = '{:s}_{:d}'.format(self._insteon_device.id, self._insteon_device_state.group)
return name
@property
def device_state_attributes(self):
"""Provide attributes for display on device card."""
insteon_plm = get_component('insteon_plm')
return insteon_plm.common_attributes(self._device, self._state)
return insteon_plm.common_attributes(self._insteon_device, self._insteon_device_state)
@property
def speed(self) -> str:
"""Return the current speed."""
return self._hex_to_speed(self._state.value)
return self._hex_to_speed(self._insteon_device_state.value)
@property
def speed_list(self) -> list:
@@ -108,11 +108,11 @@ class InsteonPLMFan(FanEntity):
def async_set_speed(self, speed: str) -> None:
"""Set the speed of the fan."""
fanSpeed = SPEED_TO_HEX[speed]
if fanSpeed == 0x00:
self._state.off()
fan_speed = SPEED_TO_HEX[speed]
if fan_speed == 0x00:
self._insteon_device_state.off()
else:
self._state.set_level(fanSpeed)
self._insteon_device_state.set_level(fan_speed)
@callback
def async_fan_update(self, deviceid, statename, val):

View File

@@ -47,20 +47,20 @@ def async_setup(hass, config):
def async_plm_new_device(device):
"""Detect device from transport to be delegated to platform."""
for stateKey in device.states:
platformInfo = ipdb[device.states[stateKey]]
platform = platformInfo.platform
for state_key in device.states:
platform_info = ipdb[device.states[state_key]]
platform = platform_info.platform
if platform is not None:
_LOGGER.info("New INSTEON PLM device: %s (%s) %s",
device.address,
device.states[stateKey].name,
device.states[state_key].name,
platform)
hass.async_add_job(
discovery.async_load_platform(
hass, platform, DOMAIN,
discovered=[{'address': device.address.hex,
'stateKey': stateKey}],
'state_key': state_key}],
hass_config=config))
_LOGGER.info("Looking for PLM on %s", port)

View File

@@ -26,14 +26,14 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
state_list = []
plm = hass.data['insteon_plm']
for deviceInfo in discovery_info:
address = deviceInfo['address']
for device_info in discovery_info:
address = device_info['address']
device = plm.devices[address]
stateKey = deviceInfo['stateKey']
state_key = device_info['state_key']
state_list.append(InsteonPLMDimmerDevice(hass,
device,
stateKey))
state_key))
async_add_devices(state_list)
@@ -41,13 +41,13 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
class InsteonPLMDimmerDevice(Light):
"""A Class for an Insteon device."""
def __init__(self, hass, device, stateKey):
def __init__(self, hass, device, state_key):
"""Initialize the light."""
self._hass = hass
self._state = device.states[stateKey]
self._device = device
self._insteon_device_state = device.states[state_key]
self._insteon_device = device
self._state.register_updates(self.async_light_update)
self._insteon_device_state.register_updates(self.async_light_update)
@property
def should_poll(self):
@@ -57,22 +57,22 @@ class InsteonPLMDimmerDevice(Light):
@property
def address(self):
"""Return the address of the node."""
return self._device.address.human
return self._insteon_device.address.human
@property
def name(self):
"""Return the name of the node. (used for Entity_ID)"""
name = ''
if self._state.group == 0x01:
name = self._device.id
if self._insteon_device_state.group == 0x01:
name = self._insteon_device.id
else:
name = '{:s}_{:d}'.format(self._device.id, self._state.group)
name = '{:s}_{:d}'.format(self._insteon_device.id, self._insteon_device_state.group)
return name
@property
def brightness(self):
"""Return the brightness of this light between 0..255."""
onlevel = self._state.value
onlevel = self._insteon_device_state.value
return int(onlevel)
@property
@@ -89,7 +89,7 @@ class InsteonPLMDimmerDevice(Light):
def device_state_attributes(self):
"""Provide attributes for display on device card."""
insteon_plm = get_component('insteon_plm')
return insteon_plm.common_attributes(self._device, self._state)
return insteon_plm.common_attributes(self._insteon_device, self._insteon_device_state)
@callback
def async_light_update(self, entity_id, statename, val):
@@ -101,11 +101,11 @@ class InsteonPLMDimmerDevice(Light):
"""Turn device on."""
if ATTR_BRIGHTNESS in kwargs:
brightness = int(kwargs[ATTR_BRIGHTNESS])
self._state.set_level(brightness)
self._insteon_device_state.set_level(brightness)
else:
self._state.on()
self._insteon_device_state.on()
@asyncio.coroutine
def async_turn_off(self, **kwargs):
"""Turn device off."""
self._state.off()
self._insteon_device_state.off()

View File

@@ -23,14 +23,14 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
state_list = []
plm = hass.data['insteon_plm']
for deviceInfo in discovery_info:
address = deviceInfo['address']
for device_info in discovery_info:
address = device_info['address']
device = plm.devices[address]
stateKey = deviceInfo['stateKey']
state_key = device_info['state_key']
state_list.append(InsteonPLMSensorDevice(hass,
device,
stateKey))
state_key))
async_add_devices(state_list)
@@ -38,13 +38,13 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
class InsteonPLMSensorDevice(Entity):
"""A Class for an Insteon device."""
def __init__(self, hass, device, stateKey):
def __init__(self, hass, device, state_key):
"""Initialize the binarysensor."""
self._hass = hass
self._state = device.states[stateKey]
self._device = device
self._insteon_device_state = device.states[state_key]
self._insteon_device = device
self._state.register_updates(self.async_sensor_update)
self._insteon_device_state.register_updates(self.async_sensor_update)
@property
def should_poll(self):
@@ -54,29 +54,29 @@ class InsteonPLMSensorDevice(Entity):
@property
def address(self):
"""Return the address of the node."""
return self._device.address.human
return self._insteon_device.address.human
@property
def name(self):
"""Return the name of the node. (used for Entity_ID)"""
name = ''
if self._state.group == 0x01:
name = self._device.id
if self._insteon_device_state.group == 0x01:
name = self._insteon_device.id
else:
name = '{:s}_{:d}'.format(self._device.id, self._state.group)
name = '{:s}_{:d}'.format(self._insteon_device.id, self._insteon_device_state.group)
return name
@property
def state(self):
"""Return the state of the sensor."""
sensorstate = self._state.value
sensorstate = self._insteon_device_state.value
return sensorstate
@property
def device_state_attributes(self):
"""Provide attributes for display on device card."""
insteon_plm = get_component('insteon_plm')
return insteon_plm.common_attributes(self._device, self._state)
return insteon_plm.common_attributes(self._insteon_device, self._insteon_device_state)
@callback
def async_sensor_update(self, deviceid, statename, val):

View File

@@ -23,21 +23,21 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
state_list = []
plm = hass.data['insteon_plm']
for deviceInfo in discovery_info:
address = deviceInfo['address']
for device_info in discovery_info:
address = device_info['address']
device = plm.devices[address]
stateKey = deviceInfo['stateKey']
state_key = device_info['state_key']
stateName = device.states[stateKey].name
stateName = device.states[state_key].name
if stateName in ['lightOnOff', 'outletTopOnOff', 'outletBottomOnOff']:
state_list.append(InsteonPLMSwitchDevice(hass,
device,
stateKey))
state_key))
elif stateName == 'openClosedRelay':
state_list.append(InsteonPLMOpenClosedDevice(hass,
device,
stateKey))
state_key))
async_add_devices(state_list)
@@ -45,13 +45,13 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
class InsteonPLMSwitchDevice(SwitchDevice):
"""A Class for an Insteon device."""
def __init__(self, hass, device, stateKey):
def __init__(self, hass, device, state_key):
"""Initialize the switch."""
self._hass = hass
self._state = device.states[stateKey]
self._device = device
self._insteon_device_state = device.states[state_key]
self._insteon_device = device
self._state.register_updates(self.async_switch_update)
self._insteon_device_state.register_updates(self.async_switch_update)
@property
def should_poll(self):
@@ -61,29 +61,29 @@ class InsteonPLMSwitchDevice(SwitchDevice):
@property
def address(self):
"""Return the address of the node."""
return self._device.address.human
return self._insteon_device.address.human
@property
def name(self):
"""Return the name of the node. (used for Entity_ID)"""
name = ''
if self._state.group == 0x01:
name = self._device.id
if self._insteon_device_state.group == 0x01:
name = self._insteon_device.id
else:
name = '{:s}_{:d}'.format(self._device.id, self._state.group)
name = '{:s}_{:d}'.format(self._insteon_device.id, self._insteon_device_state.group)
return name
@property
def is_on(self):
"""Return the boolean response if the node is on."""
onlevel = self._state.value
onlevel = self._insteon_device_state.value
return bool(onlevel)
@property
def device_state_attributes(self):
"""Provide attributes for display on device card."""
insteon_plm = get_component('insteon_plm')
return insteon_plm.common_attributes(self._device, self._state)
return insteon_plm.common_attributes(self._insteon_device, self._insteon_device_state)
@callback
def async_switch_update(self, deviceid, statename, val):
@@ -93,24 +93,24 @@ class InsteonPLMSwitchDevice(SwitchDevice):
@asyncio.coroutine
def async_turn_on(self, **kwargs):
"""Turn device on."""
self._state.on()
self._insteon_device_state.on()
@asyncio.coroutine
def async_turn_off(self, **kwargs):
"""Turn device off"""
self._state.off()
self._insteon_device_state.off()
class InsteonPLMOpenClosedDevice(SwitchDevice):
"""A Class for an Insteon device."""
def __init__(self, hass, device, stateKey):
def __init__(self, hass, device, state_key):
"""Initialize the switch."""
self._hass = hass
self._state = device.states[stateKey]
self._device = device
self._insteon_device_state = device.states[state_key]
self._insteon_device = device
self._state.register_updates(self.async_relay_update)
self._insteon_device_state.register_updates(self.async_relay_update)
@property
def should_poll(self):
@@ -120,29 +120,29 @@ class InsteonPLMOpenClosedDevice(SwitchDevice):
@property
def address(self):
"""Return the address of the node."""
return self._device.address.human
return self._insteon_device.address.human
@property
def name(self):
"""Return the name of the node. (used for Entity_ID)"""
name = ''
if self._state.group == 0x01:
name = self._device.id
if self._insteon_device_state.group == 0x01:
name = self._insteon_device.id
else:
name = '{:s}_{:d}'.format(self._device.id, self._state.group)
name = '{:s}_{:d}'.format(self._insteon_device.id, self._insteon_device_state.group)
return name
@property
def is_on(self):
"""Return the boolean response if the node is on."""
onlevel = self._state.value
onlevel = self._insteon_device_state.value
return bool(onlevel)
@property
def device_state_attributes(self):
"""Provide attributes for display on device card."""
insteon_plm = get_component('insteon_plm')
return insteon_plm.common_attributes(self._device, self._state)
return insteon_plm.common_attributes(self._insteon_device, self._insteon_device_state)
@callback
def async_relay_update(self, deviceid, statename, val):
@@ -152,9 +152,9 @@ class InsteonPLMOpenClosedDevice(SwitchDevice):
@asyncio.coroutine
def async_turn_on(self, **kwargs):
"""Turn device on."""
self._state.open()
self._insteon_device_state.open()
@asyncio.coroutine
def async_turn_off(self, **kwargs):
"""Turn device off"""
self._state.close()
self._insteon_device_state.close()