2019-02-19 13:09:06 +00:00
|
|
|
"""Support for INSTEON dimmers via PowerLinc Modem."""
|
2018-02-25 19:13:39 +00:00
|
|
|
import logging
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-08-22 07:09:04 +00:00
|
|
|
from homeassistant.components.insteon import InsteonEntity
|
2018-02-25 19:13:39 +00:00
|
|
|
from homeassistant.components.switch import SwitchDevice
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-08-22 07:09:04 +00:00
|
|
|
DEPENDENCIES = ['insteon']
|
2017-02-21 07:53:39 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-02-19 13:09:06 +00:00
|
|
|
async def async_setup_platform(
|
|
|
|
hass, config, async_add_entities, discovery_info=None):
|
2018-08-22 07:09:04 +00:00
|
|
|
"""Set up the INSTEON device class for the hass platform."""
|
|
|
|
insteon_modem = hass.data['insteon'].get('modem')
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-02-25 19:13:39 +00:00
|
|
|
address = discovery_info['address']
|
2018-08-22 07:09:04 +00:00
|
|
|
device = insteon_modem.devices[address]
|
2018-02-25 19:13:39 +00:00
|
|
|
state_key = discovery_info['state_key']
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-02-25 19:13:39 +00:00
|
|
|
state_name = device.states[state_key].name
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2019-02-19 13:09:06 +00:00
|
|
|
_LOGGER.debug("Adding device %s entity %s to Switch platform",
|
2018-02-25 19:13:39 +00:00
|
|
|
device.address.hex, device.states[state_key].name)
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-02-25 19:13:39 +00:00
|
|
|
new_entity = None
|
2018-08-22 07:09:04 +00:00
|
|
|
if state_name == 'openClosedRelay':
|
|
|
|
new_entity = InsteonOpenClosedDevice(device, state_key)
|
|
|
|
else:
|
|
|
|
new_entity = InsteonSwitchDevice(device, state_key)
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-02-25 19:13:39 +00:00
|
|
|
if new_entity is not None:
|
2018-08-24 14:37:30 +00:00
|
|
|
async_add_entities([new_entity])
|
2017-02-21 07:53:39 +00:00
|
|
|
|
|
|
|
|
2018-08-22 07:09:04 +00:00
|
|
|
class InsteonSwitchDevice(InsteonEntity, SwitchDevice):
|
2018-02-25 19:13:39 +00:00
|
|
|
"""A Class for an Insteon device."""
|
2017-02-21 07:53:39 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return the boolean response if the node is on."""
|
2018-07-14 09:04:00 +00:00
|
|
|
return bool(self._insteon_device_state.value)
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-10-01 06:55:00 +00:00
|
|
|
async def async_turn_on(self, **kwargs):
|
2018-02-25 19:13:39 +00:00
|
|
|
"""Turn device on."""
|
|
|
|
self._insteon_device_state.on()
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-10-01 06:55:00 +00:00
|
|
|
async def async_turn_off(self, **kwargs):
|
2018-02-25 19:13:39 +00:00
|
|
|
"""Turn device off."""
|
|
|
|
self._insteon_device_state.off()
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-02-25 19:13:39 +00:00
|
|
|
|
2018-08-22 07:09:04 +00:00
|
|
|
class InsteonOpenClosedDevice(InsteonEntity, SwitchDevice):
|
2018-02-25 19:13:39 +00:00
|
|
|
"""A Class for an Insteon device."""
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-07-14 09:04:00 +00:00
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return the boolean response if the node is on."""
|
|
|
|
return bool(self._insteon_device_state.value)
|
|
|
|
|
2018-10-01 06:55:00 +00:00
|
|
|
async def async_turn_on(self, **kwargs):
|
2017-02-21 07:53:39 +00:00
|
|
|
"""Turn device on."""
|
2018-02-25 19:13:39 +00:00
|
|
|
self._insteon_device_state.open()
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-10-01 06:55:00 +00:00
|
|
|
async def async_turn_off(self, **kwargs):
|
2017-02-21 07:53:39 +00:00
|
|
|
"""Turn device off."""
|
2018-02-25 19:13:39 +00:00
|
|
|
self._insteon_device_state.close()
|