hass-core/homeassistant/components/light/insteon_plm.py
Tom Harris 64ba2c63c7 Add All-Linking capabilities (#14065)
* Setup all-linking service

* Remove extra line

* Remove linefeed and tab escape chars

* Add services delete_all_link, load_all_link_database and print_all_link_database

* Check if reload is set

* Confirm entity is InsteonPLMEntity before attempting to load or print ALDB

* Debug load and print ALDB

* Debug print aldb

* Debug print_aldb

* Get entity via platform

* Track Insteon entities in component

* Store entity list in hass.data

* Add entity to hass.data

* Add ref to hass in InsteonPLMEntity

* Pass hass correctly to InsteonPLMBinarySensor

* Fix reference to ALDBStatus.PARTIAL

* Print ALDB record as string

* Get ALDB record from memory address

* Reformat ALDB log output

* Add print_im_aldb service

* Remove reference to self in print_aldb_to_log

* Remove reference to self in print_aldb_to_log

* Fix spelling issue with load_all_link_database service

* Bump insteonplm to 0.9.1

* Changes from code review

* Code review changes

* Fix syntax error

* Correct reference to cv.boolean and update requirements

* Update requirements

* Fix flake8 errors

* Reload as boolean test

* Remove hass from entity init
2018-05-05 11:15:20 -04:00

69 lines
1.9 KiB
Python

"""
Support for Insteon lights via PowerLinc Modem.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/light.insteon_plm/
"""
import asyncio
import logging
from homeassistant.components.insteon_plm import InsteonPLMEntity
from homeassistant.components.light import (
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
_LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['insteon_plm']
MAX_BRIGHTNESS = 255
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
"""Set up the Insteon PLM device."""
plm = hass.data['insteon_plm'].get('plm')
address = discovery_info['address']
device = plm.devices[address]
state_key = discovery_info['state_key']
_LOGGER.debug('Adding device %s entity %s to Light platform',
device.address.hex, device.states[state_key].name)
new_entity = InsteonPLMDimmerDevice(device, state_key)
async_add_devices([new_entity])
class InsteonPLMDimmerDevice(InsteonPLMEntity, Light):
"""A Class for an Insteon device."""
@property
def brightness(self):
"""Return the brightness of this light between 0..255."""
onlevel = self._insteon_device_state.value
return int(onlevel)
@property
def is_on(self):
"""Return the boolean response if the node is on."""
return bool(self.brightness)
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_BRIGHTNESS
@asyncio.coroutine
def async_turn_on(self, **kwargs):
"""Turn device on."""
if ATTR_BRIGHTNESS in kwargs:
brightness = int(kwargs[ATTR_BRIGHTNESS])
self._insteon_device_state.set_level(brightness)
else:
self._insteon_device_state.on()
@asyncio.coroutine
def async_turn_off(self, **kwargs):
"""Turn device off."""
self._insteon_device_state.off()