Skip to content

Commit

Permalink
Merge 7324e94 into d144ad9
Browse files Browse the repository at this point in the history
  • Loading branch information
bramstroker committed Jun 29, 2024
2 parents d144ad9 + 7324e94 commit 08646d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions custom_components/powercalc/strategy/lut.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async def calculate(self, entity_state: State) -> Decimal | None:
brightness = 255

if color_mode == ColorMode.UNKNOWN:
_LOGGER.debug(
_LOGGER.warning(
"%s: Could not calculate power. color mode unknown",
entity_state.entity_id,
)
Expand Down Expand Up @@ -193,7 +193,7 @@ async def calculate(self, entity_state: State) -> Decimal | None:

async def get_selected_color_mode(self, attrs: Mapping[str, Any]) -> ColorMode:
"""Get the selected color mode for the entity."""
color_mode = ColorMode(str(attrs.get(ATTR_COLOR_MODE)))
color_mode = ColorMode(str(attrs.get(ATTR_COLOR_MODE, ColorMode.UNKNOWN)))
if color_mode in COLOR_MODES_COLOR:
color_mode = ColorMode.HS
profile_color_modes = await self._lut_registry.get_supported_color_modes(self._profile)
Expand Down
10 changes: 10 additions & 0 deletions tests/strategy/test_lut.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ async def test_fallback_color_temp_to_hs(hass: HomeAssistant) -> None:
assert hass.states.get("sensor.test_power").state == "1.42"


async def test_warning_is_logged_when_color_mode_is_missing(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -> None:
"""Test that a warning is logged when the color_mode attribute is missing."""
caplog.set_level(logging.WARNING)
strategy = await _create_lut_strategy(hass, "signify", "LCT010")

state = State("light.test", STATE_ON, {ATTR_BRIGHTNESS: 100})
assert not await strategy.calculate(state)
assert "color mode unknown" in caplog.text


async def _create_lut_strategy(
hass: HomeAssistant,
manufacturer: str,
Expand Down

0 comments on commit 08646d5

Please sign in to comment.