mirror of
https://github.com/home-assistant/core.git
synced 2025-12-27 14:31:13 +00:00
Black
This commit is contained in:
@@ -7,9 +7,15 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.const import CONF_HOSTS
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_EFFECT,
|
||||
SUPPORT_BRIGHTNESS, SUPPORT_EFFECT, SUPPORT_COLOR,
|
||||
Light, PLATFORM_SCHEMA)
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_HS_COLOR,
|
||||
ATTR_EFFECT,
|
||||
SUPPORT_BRIGHTNESS,
|
||||
SUPPORT_EFFECT,
|
||||
SUPPORT_COLOR,
|
||||
Light,
|
||||
PLATFORM_SCHEMA,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import homeassistant.util.color as color_util
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
@@ -17,36 +23,35 @@ from homeassistant.exceptions import PlatformNotReady
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SUPPORT_EVERLIGHTS = (SUPPORT_EFFECT | SUPPORT_BRIGHTNESS | SUPPORT_COLOR)
|
||||
SUPPORT_EVERLIGHTS = SUPPORT_EFFECT | SUPPORT_BRIGHTNESS | SUPPORT_COLOR
|
||||
|
||||
SCAN_INTERVAL = timedelta(minutes=1)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_HOSTS): vol.All(cv.ensure_list, [cv.string]),
|
||||
})
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{vol.Required(CONF_HOSTS): vol.All(cv.ensure_list, [cv.string])}
|
||||
)
|
||||
|
||||
NAME_FORMAT = "EverLights {} Zone {}"
|
||||
|
||||
|
||||
def color_rgb_to_int(red: int, green: int, blue: int) -> int:
|
||||
"""Return a RGB color as an integer."""
|
||||
return red*256*256+green*256+blue
|
||||
return red * 256 * 256 + green * 256 + blue
|
||||
|
||||
|
||||
def color_int_to_rgb(value: int) -> Tuple[int, int, int]:
|
||||
"""Return an RGB tuple from an integer."""
|
||||
return (value >> 16, (value >> 8) & 0xff, value & 0xff)
|
||||
return (value >> 16, (value >> 8) & 0xFF, value & 0xFF)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the EverLights lights from configuration.yaml."""
|
||||
import pyeverlights
|
||||
|
||||
lights = []
|
||||
|
||||
for ipaddr in config[CONF_HOSTS]:
|
||||
api = pyeverlights.EverLights(ipaddr,
|
||||
async_get_clientsession(hass))
|
||||
api = pyeverlights.EverLights(ipaddr, async_get_clientsession(hass))
|
||||
|
||||
try:
|
||||
status = await api.get_status()
|
||||
@@ -57,10 +62,8 @@ async def async_setup_platform(hass, config, async_add_entities,
|
||||
raise PlatformNotReady
|
||||
|
||||
else:
|
||||
lights.append(EverLightsLight(api, pyeverlights.ZONE_1,
|
||||
status, effects))
|
||||
lights.append(EverLightsLight(api, pyeverlights.ZONE_2,
|
||||
status, effects))
|
||||
lights.append(EverLightsLight(api, pyeverlights.ZONE_1, status, effects))
|
||||
lights.append(EverLightsLight(api, pyeverlights.ZONE_2, status, effects))
|
||||
|
||||
async_add_entities(lights)
|
||||
|
||||
@@ -74,7 +77,7 @@ class EverLightsLight(Light):
|
||||
self._channel = channel
|
||||
self._status = status
|
||||
self._effects = effects
|
||||
self._mac = status['mac']
|
||||
self._mac = status["mac"]
|
||||
self._error_reported = False
|
||||
self._hs_color = [255, 255]
|
||||
self._brightness = 255
|
||||
@@ -84,7 +87,7 @@ class EverLightsLight(Light):
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique ID."""
|
||||
return '{}-{}'.format(self._mac, self._channel)
|
||||
return "{}-{}".format(self._mac, self._channel)
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
@@ -99,7 +102,7 @@ class EverLightsLight(Light):
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if device is on."""
|
||||
return self._status['ch{}Active'.format(self._channel)] == 1
|
||||
return self._status["ch{}Active".format(self._channel)] == 1
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
@@ -141,7 +144,7 @@ class EverLightsLight(Light):
|
||||
brightness = hsv[2] / 100 * 255
|
||||
|
||||
else:
|
||||
rgb = color_util.color_hsv_to_RGB(*hs_color, brightness/255*100)
|
||||
rgb = color_util.color_hsv_to_RGB(*hs_color, brightness / 255 * 100)
|
||||
colors = [color_rgb_to_int(*rgb)]
|
||||
|
||||
await self._api.set_pattern(self._channel, colors)
|
||||
|
||||
Reference in New Issue
Block a user