Black
This commit is contained in:
parent
da05dfe708
commit
4de97abc3a
2676 changed files with 163166 additions and 140084 deletions
|
@ -1,7 +1,13 @@
|
|||
"""Support for the Hive lights."""
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_HS_COLOR, SUPPORT_BRIGHTNESS,
|
||||
SUPPORT_COLOR, SUPPORT_COLOR_TEMP, Light)
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_COLOR_TEMP,
|
||||
ATTR_HS_COLOR,
|
||||
SUPPORT_BRIGHTNESS,
|
||||
SUPPORT_COLOR,
|
||||
SUPPORT_COLOR_TEMP,
|
||||
Light,
|
||||
)
|
||||
import homeassistant.util.color as color_util
|
||||
|
||||
from . import DATA_HIVE, DOMAIN
|
||||
|
@ -27,9 +33,8 @@ class HiveDeviceLight(Light):
|
|||
self.light_device_type = hivedevice["Hive_Light_DeviceType"]
|
||||
self.session = hivesession
|
||||
self.attributes = {}
|
||||
self.data_updatesource = '{}.{}'.format(
|
||||
self.device_type, self.node_id)
|
||||
self._unique_id = '{}-{}'.format(self.node_id, self.device_type)
|
||||
self.data_updatesource = "{}.{}".format(self.device_type, self.node_id)
|
||||
self._unique_id = "{}-{}".format(self.node_id, self.device_type)
|
||||
self.session.entities.append(self)
|
||||
|
||||
@property
|
||||
|
@ -40,16 +45,11 @@ class HiveDeviceLight(Light):
|
|||
@property
|
||||
def device_info(self):
|
||||
"""Return device information."""
|
||||
return {
|
||||
'identifiers': {
|
||||
(DOMAIN, self.unique_id)
|
||||
},
|
||||
'name': self.name
|
||||
}
|
||||
return {"identifiers": {(DOMAIN, self.unique_id)}, "name": self.name}
|
||||
|
||||
def handle_update(self, updatesource):
|
||||
"""Handle the new update request."""
|
||||
if '{}.{}'.format(self.device_type, self.node_id) not in updatesource:
|
||||
if "{}.{}".format(self.device_type, self.node_id) not in updatesource:
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
@property
|
||||
|
@ -70,22 +70,28 @@ class HiveDeviceLight(Light):
|
|||
@property
|
||||
def min_mireds(self):
|
||||
"""Return the coldest color_temp that this light supports."""
|
||||
if self.light_device_type == "tuneablelight" \
|
||||
or self.light_device_type == "colourtuneablelight":
|
||||
if (
|
||||
self.light_device_type == "tuneablelight"
|
||||
or self.light_device_type == "colourtuneablelight"
|
||||
):
|
||||
return self.session.light.get_min_color_temp(self.node_id)
|
||||
|
||||
@property
|
||||
def max_mireds(self):
|
||||
"""Return the warmest color_temp that this light supports."""
|
||||
if self.light_device_type == "tuneablelight" \
|
||||
or self.light_device_type == "colourtuneablelight":
|
||||
if (
|
||||
self.light_device_type == "tuneablelight"
|
||||
or self.light_device_type == "colourtuneablelight"
|
||||
):
|
||||
return self.session.light.get_max_color_temp(self.node_id)
|
||||
|
||||
@property
|
||||
def color_temp(self):
|
||||
"""Return the CT color value in mireds."""
|
||||
if self.light_device_type == "tuneablelight" \
|
||||
or self.light_device_type == "colourtuneablelight":
|
||||
if (
|
||||
self.light_device_type == "tuneablelight"
|
||||
or self.light_device_type == "colourtuneablelight"
|
||||
):
|
||||
return self.session.light.get_color_temp(self.node_id)
|
||||
|
||||
@property
|
||||
|
@ -107,7 +113,7 @@ class HiveDeviceLight(Light):
|
|||
new_color = None
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
tmp_new_brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||
percentage_brightness = ((tmp_new_brightness / 255) * 100)
|
||||
percentage_brightness = (tmp_new_brightness / 255) * 100
|
||||
new_brightness = int(round(percentage_brightness / 5.0) * 5.0)
|
||||
if new_brightness == 0:
|
||||
new_brightness = 5
|
||||
|
@ -120,9 +126,13 @@ class HiveDeviceLight(Light):
|
|||
saturation = int(get_new_color[1])
|
||||
new_color = (hue, saturation, 100)
|
||||
|
||||
self.session.light.turn_on(self.node_id, self.light_device_type,
|
||||
new_brightness, new_color_temp,
|
||||
new_color)
|
||||
self.session.light.turn_on(
|
||||
self.node_id,
|
||||
self.light_device_type,
|
||||
new_brightness,
|
||||
new_color_temp,
|
||||
new_color,
|
||||
)
|
||||
|
||||
for entity in self.session.entities:
|
||||
entity.handle_update(self.data_updatesource)
|
||||
|
@ -140,15 +150,13 @@ class HiveDeviceLight(Light):
|
|||
if self.light_device_type == "warmwhitelight":
|
||||
supported_features = SUPPORT_BRIGHTNESS
|
||||
elif self.light_device_type == "tuneablelight":
|
||||
supported_features = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP)
|
||||
supported_features = SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP
|
||||
elif self.light_device_type == "colourtuneablelight":
|
||||
supported_features = (
|
||||
SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_COLOR)
|
||||
supported_features = SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_COLOR
|
||||
|
||||
return supported_features
|
||||
|
||||
def update(self):
|
||||
"""Update all Node data from Hive."""
|
||||
self.session.core.update_data(self.node_id)
|
||||
self.attributes = self.session.attributes.state_attributes(
|
||||
self.node_id)
|
||||
self.attributes = self.session.attributes.state_attributes(self.node_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue