Migrate dynalite light to color_mode (#69177)

pull/69192/head
Erik Montnemery 2022-04-03 13:58:28 +02:00 committed by GitHub
parent b38ca5ddd6
commit eeeb21a9f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -1,6 +1,6 @@
"""Support for Dynalite channels as lights."""
from homeassistant.components.light import SUPPORT_BRIGHTNESS, LightEntity
from homeassistant.components.light import COLOR_MODE_BRIGHTNESS, LightEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -22,6 +22,9 @@ async def async_setup_entry(
class DynaliteLight(DynaliteBase, LightEntity):
"""Representation of a Dynalite Channel as a Home Assistant Light."""
_attr_color_mode = COLOR_MODE_BRIGHTNESS
_attr_supported_color_modes = {COLOR_MODE_BRIGHTNESS}
@property
def brightness(self) -> int:
"""Return the brightness of this light between 0..255."""
@ -39,8 +42,3 @@ class DynaliteLight(DynaliteBase, LightEntity):
async def async_turn_off(self, **kwargs) -> None:
"""Turn the light off."""
await self._device.async_turn_off(**kwargs)
@property
def supported_features(self) -> int:
"""Flag supported features."""
return SUPPORT_BRIGHTNESS

View File

@ -3,7 +3,11 @@
from dynalite_devices_lib.light import DynaliteChannelLightDevice
import pytest
from homeassistant.components.light import SUPPORT_BRIGHTNESS
from homeassistant.components.light import (
ATTR_COLOR_MODE,
ATTR_SUPPORTED_COLOR_MODES,
COLOR_MODE_BRIGHTNESS,
)
from homeassistant.const import (
ATTR_FRIENDLY_NAME,
ATTR_SUPPORTED_FEATURES,
@ -32,7 +36,11 @@ async def test_light_setup(hass, mock_device):
entity_state = hass.states.get("light.name")
assert entity_state.attributes[ATTR_FRIENDLY_NAME] == mock_device.name
assert entity_state.attributes["brightness"] == mock_device.brightness
assert entity_state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_BRIGHTNESS
assert entity_state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_BRIGHTNESS
assert entity_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [
COLOR_MODE_BRIGHTNESS
]
assert entity_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
await run_service_tests(
hass,
mock_device,