Change Skybell color mode to RGB (#78078)

This commit is contained in:
Robert Hillis 2022-09-25 19:47:38 -04:00 committed by GitHub
parent c2209111b2
commit 43c66b90df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,8 @@ from __future__ import annotations
from typing import Any from typing import Any
from aioskybell.helpers.const import BRIGHTNESS, RGB_COLOR
from homeassistant.components.light import ( from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_BRIGHTNESS,
ATTR_RGB_COLOR, ATTR_RGB_COLOR,
@ -31,16 +33,16 @@ async def async_setup_entry(
class SkybellLight(SkybellEntity, LightEntity): class SkybellLight(SkybellEntity, LightEntity):
"""A light implementation for Skybell devices.""" """A light implementation for Skybell devices."""
_attr_supported_color_modes = {ColorMode.BRIGHTNESS, ColorMode.RGB} _attr_color_mode = ColorMode.RGB
_attr_supported_color_modes = {ColorMode.RGB}
async def async_turn_on(self, **kwargs: Any) -> None: async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the light.""" """Turn on the light."""
if ATTR_RGB_COLOR in kwargs: if ATTR_RGB_COLOR in kwargs:
rgb = kwargs[ATTR_RGB_COLOR] await self._device.async_set_setting(RGB_COLOR, kwargs[ATTR_RGB_COLOR])
await self._device.async_set_setting(ATTR_RGB_COLOR, rgb)
if ATTR_BRIGHTNESS in kwargs: if ATTR_BRIGHTNESS in kwargs:
level = int((kwargs.get(ATTR_BRIGHTNESS, 0) * 100) / 255) level = int((kwargs.get(ATTR_BRIGHTNESS, 0) * 100) / 255)
await self._device.async_set_setting(ATTR_BRIGHTNESS, level) await self._device.async_set_setting(BRIGHTNESS, level)
async def async_turn_off(self, **kwargs: Any) -> None: async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off the light.""" """Turn off the light."""
@ -55,3 +57,8 @@ class SkybellLight(SkybellEntity, LightEntity):
def brightness(self) -> int: def brightness(self) -> int:
"""Return the brightness of the light.""" """Return the brightness of the light."""
return int((self._device.led_intensity * 255) / 100) return int((self._device.led_intensity * 255) / 100)
@property
def rgb_color(self) -> tuple[int, int, int] | None:
"""Return the rgb color value [int, int, int]."""
return self._device.led_rgb