Back out insteon hub and fan changes (#3062)
This commit is contained in:
1 parent
a7a662d224
commit
6fdd7f5350
5 files changed
+49
-246
No files matched your search
@@ -4,76 +4,74 @@ Support for Insteon Hub lights.
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/insteon_hub/
|
||||
"""
|
||||
from homeassistant.components.insteon_hub import (INSTEON, InsteonDevice)
|
||||
from homeassistant.components.insteon_hub import INSTEON
|
||||
from homeassistant.components.light import (ATTR_BRIGHTNESS,
|
||||
SUPPORT_BRIGHTNESS, Light)
|
||||
|
||||
SUPPORT_INSTEON_HUB = SUPPORT_BRIGHTNESS
|
||||
|
||||
DEPENDENCIES = ['insteon_hub']
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the Insteon Hub light platform."""
|
||||
devs = []
|
||||
for device in INSTEON.devices:
|
||||
if device.DeviceCategory == "Switched Lighting Control":
|
||||
devs.append(InsteonLightDevice(device))
|
||||
devs.append(InsteonToggleDevice(device))
|
||||
if device.DeviceCategory == "Dimmable Lighting Control":
|
||||
devs.append(InsteonDimmableDevice(device))
|
||||
devs.append(InsteonToggleDevice(device))
|
||||
add_devices(devs)
|
||||
|
||||
|
||||
class InsteonLightDevice(InsteonDevice, Light):
|
||||
"""A representation of a light device."""
|
||||
class InsteonToggleDevice(Light):
|
||||
"""An abstract Class for an Insteon node."""
|
||||
|
||||
def __init__(self, node: object) -> None:
|
||||
def __init__(self, node):
|
||||
"""Initialize the device."""
|
||||
super(InsteonLightDevice, self).__init__(node)
|
||||
self.node = node
|
||||
self._value = 0
|
||||
|
||||
def update(self) -> None:
|
||||
"""Update state of the device."""
|
||||
resp = self._node.send_command('get_status', wait=True)
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the the name of the node."""
|
||||
return self.node.DeviceName
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the ID of this insteon node."""
|
||||
return self.node.DeviceID
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
return self._value / 100 * 255
|
||||
|
||||
def update(self):
|
||||
"""Update state of the sensor."""
|
||||
resp = self.node.send_command('get_status', wait=True)
|
||||
try:
|
||||
self._value = resp['response']['level']
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
@property
|
||||
def is_on(self) -> None:
|
||||
def is_on(self):
|
||||
"""Return the boolean response if the node is on."""
|
||||
return self._value != 0
|
||||
|
||||
def turn_on(self, **kwargs) -> None:
|
||||
"""Turn device on."""
|
||||
if self._send_command('on'):
|
||||
self._value = 100
|
||||
|
||||
def turn_off(self, **kwargs) -> None:
|
||||
"""Turn device off."""
|
||||
if self._send_command('off'):
|
||||
self._value = 0
|
||||
|
||||
|
||||
class InsteonDimmableDevice(InsteonLightDevice):
|
||||
"""A representation for a dimmable device."""
|
||||
|
||||
@property
|
||||
def brightness(self) -> int:
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
return round(self._value / 100 * 255, 0) # type: int
|
||||
|
||||
@property
|
||||
def supported_features(self) -> int:
|
||||
def supported_features(self):
|
||||
"""Flag supported features."""
|
||||
return SUPPORT_INSTEON_HUB
|
||||
|
||||
def turn_on(self, **kwargs) -> None:
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn device on."""
|
||||
level = 100 # type: int
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
level = round(kwargs[ATTR_BRIGHTNESS] / 255 * 100, 0) # type: int
|
||||
self._value = kwargs[ATTR_BRIGHTNESS] / 255 * 100
|
||||
self.node.send_command('on', self._value)
|
||||
else:
|
||||
self._value = 100
|
||||
self.node.send_command('on')
|
||||
|
||||
if self._send_command('on', level=level):
|
||||
self._value = level
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn device off."""
|
||||
self.node.send_command('off')
|
||||
Reference in new issue
Block a user