diff --git a/homeassistant/components/fritzbox/light.py b/homeassistant/components/fritzbox/light.py index 24431f78aca..f83dd454592 100644 --- a/homeassistant/components/fritzbox/light.py +++ b/homeassistant/components/fritzbox/light.py @@ -72,8 +72,10 @@ class FritzboxLight(FritzBoxDeviceEntity, LightEntity): """Initialize the FritzboxLight entity.""" super().__init__(coordinator, ain, None) - self._attr_max_color_temp_kelvin = int(max(supported_color_temps)) - self._attr_min_color_temp_kelvin = int(min(supported_color_temps)) + if supported_color_temps: + # only available for color bulbs + self._attr_max_color_temp_kelvin = int(max(supported_color_temps)) + self._attr_min_color_temp_kelvin = int(min(supported_color_temps)) # Fritz!DECT 500 only supports 12 values for hue, with 3 saturations each. # Map supported colors to dict {hue: [sat1, sat2, sat3]} for easier lookup @@ -125,7 +127,11 @@ class FritzboxLight(FritzBoxDeviceEntity, LightEntity): @property def supported_color_modes(self) -> set[ColorMode]: """Flag supported color modes.""" - return SUPPORTED_COLOR_MODES + if self.data.has_color: + return SUPPORTED_COLOR_MODES + if self.data.has_level: + return {ColorMode.BRIGHTNESS} + return {ColorMode.ONOFF} async def async_turn_on(self, **kwargs: Any) -> None: """Turn the light on.""" diff --git a/homeassistant/components/fritzbox/manifest.json b/homeassistant/components/fritzbox/manifest.json index e604f1d37b5..29df2f51a34 100644 --- a/homeassistant/components/fritzbox/manifest.json +++ b/homeassistant/components/fritzbox/manifest.json @@ -7,7 +7,7 @@ "integration_type": "hub", "iot_class": "local_polling", "loggers": ["pyfritzhome"], - "requirements": ["pyfritzhome==0.6.7"], + "requirements": ["pyfritzhome==0.6.8"], "ssdp": [ { "st": "urn:schemas-upnp-org:device:fritzbox:1" diff --git a/requirements_all.txt b/requirements_all.txt index 78badcd39fa..1821af22273 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1645,7 +1645,7 @@ pyforked-daapd==0.1.14 pyfreedompro==1.1.0 # homeassistant.components.fritzbox -pyfritzhome==0.6.7 +pyfritzhome==0.6.8 # homeassistant.components.fronius pyfronius==0.7.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 7176b104189..f74895e3c6d 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1182,7 +1182,7 @@ pyforked-daapd==0.1.14 pyfreedompro==1.1.0 # homeassistant.components.fritzbox -pyfritzhome==0.6.7 +pyfritzhome==0.6.8 # homeassistant.components.fronius pyfronius==0.7.1 diff --git a/tests/components/fritzbox/__init__.py b/tests/components/fritzbox/__init__.py index 34311c0aa55..6cf60a90656 100644 --- a/tests/components/fritzbox/__init__.py +++ b/tests/components/fritzbox/__init__.py @@ -151,6 +151,8 @@ class FritzDeviceLightMock(FritzEntityBaseMock): has_alarm = False has_powermeter = False has_lightbulb = True + has_color = True + has_level = True has_switch = False has_temperature_sensor = False has_thermostat = False diff --git a/tests/components/fritzbox/test_light.py b/tests/components/fritzbox/test_light.py index 10c9835556b..074dd902fa1 100644 --- a/tests/components/fritzbox/test_light.py +++ b/tests/components/fritzbox/test_light.py @@ -15,6 +15,7 @@ from homeassistant.components.light import ( ATTR_HS_COLOR, ATTR_MAX_COLOR_TEMP_KELVIN, ATTR_MIN_COLOR_TEMP_KELVIN, + ATTR_SUPPORTED_COLOR_MODES, DOMAIN, ) from homeassistant.const import ( @@ -57,6 +58,46 @@ async def test_setup(hass: HomeAssistant, fritz: Mock) -> None: assert state.attributes[ATTR_COLOR_TEMP_KELVIN] == 2700 assert state.attributes[ATTR_MIN_COLOR_TEMP_KELVIN] == 2700 assert state.attributes[ATTR_MAX_COLOR_TEMP_KELVIN] == 6500 + assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["color_temp", "hs"] + + +async def test_setup_non_color(hass: HomeAssistant, fritz: Mock) -> None: + """Test setup of platform of non color bulb.""" + device = FritzDeviceLightMock() + device.has_color = False + device.get_color_temps.return_value = [] + device.get_colors.return_value = {} + + assert await setup_config_entry( + hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz + ) + + state = hass.states.get(ENTITY_ID) + assert state + assert state.state == STATE_ON + assert state.attributes[ATTR_FRIENDLY_NAME] == "fake_name" + assert state.attributes[ATTR_BRIGHTNESS] == 100 + assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["brightness"] + + +async def test_setup_non_color_non_level(hass: HomeAssistant, fritz: Mock) -> None: + """Test setup of platform of non color and non level bulb.""" + device = FritzDeviceLightMock() + device.has_color = False + device.has_level = False + device.get_color_temps.return_value = [] + device.get_colors.return_value = {} + + assert await setup_config_entry( + hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz + ) + + state = hass.states.get(ENTITY_ID) + assert state + assert state.state == STATE_ON + assert state.attributes[ATTR_FRIENDLY_NAME] == "fake_name" + assert state.attributes[ATTR_BRIGHTNESS] == 100 + assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["onoff"] async def test_setup_color(hass: HomeAssistant, fritz: Mock) -> None: @@ -80,6 +121,7 @@ async def test_setup_color(hass: HomeAssistant, fritz: Mock) -> None: assert state.attributes[ATTR_FRIENDLY_NAME] == "fake_name" assert state.attributes[ATTR_BRIGHTNESS] == 100 assert state.attributes[ATTR_HS_COLOR] == (100, 70) + assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["color_temp", "hs"] async def test_turn_on(hass: HomeAssistant, fritz: Mock) -> None: