diff --git a/homeassistant/components/philips_js/manifest.json b/homeassistant/components/philips_js/manifest.json index 948ce8703a1..cd613306130 100644 --- a/homeassistant/components/philips_js/manifest.json +++ b/homeassistant/components/philips_js/manifest.json @@ -2,7 +2,7 @@ "domain": "philips_js", "name": "Philips TV", "documentation": "https://www.home-assistant.io/integrations/philips_js", - "requirements": ["ha-philipsjs==2.7.6"], + "requirements": ["ha-philipsjs==2.9.0"], "codeowners": ["@elupus"], "config_flow": true, "iot_class": "local_polling", diff --git a/homeassistant/components/philips_js/switch.py b/homeassistant/components/philips_js/switch.py index a89c22f1850..bf1e83b0ec1 100644 --- a/homeassistant/components/philips_js/switch.py +++ b/homeassistant/components/philips_js/switch.py @@ -13,6 +13,9 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity from . import PhilipsTVDataUpdateCoordinator from .const import DOMAIN +HUE_POWER_OFF = "Off" +HUE_POWER_ON = "On" + async def async_setup_entry( hass: HomeAssistant, @@ -26,6 +29,9 @@ async def async_setup_entry( async_add_entities([PhilipsTVScreenSwitch(coordinator)]) + if coordinator.api.json_feature_supported("ambilight", "Hue"): + async_add_entities([PhilipsTVAmbilightHueSwitch(coordinator)]) + class PhilipsTVScreenSwitch( CoordinatorEntity[PhilipsTVDataUpdateCoordinator], SwitchEntity @@ -70,3 +76,50 @@ class PhilipsTVScreenSwitch( async def async_turn_off(self, **kwargs: Any) -> None: """Turn the entity off.""" await self.coordinator.api.setScreenState("Off") + + +class PhilipsTVAmbilightHueSwitch( + CoordinatorEntity[PhilipsTVDataUpdateCoordinator], SwitchEntity +): + """A Philips TV Ambi+Hue switch.""" + + def __init__( + self, + coordinator: PhilipsTVDataUpdateCoordinator, + ) -> None: + """Initialize entity.""" + + super().__init__(coordinator) + + self._attr_name = f"{coordinator.system['name']} Ambilight+Hue" + self._attr_icon = "mdi:television-ambient-light" + self._attr_unique_id = f"{coordinator.unique_id}_ambi_hue" + self._attr_device_info = DeviceInfo( + identifiers={ + (DOMAIN, coordinator.unique_id), + } + ) + + @property + def available(self) -> bool: + """Return true if entity is available.""" + if not super().available: + return False + if not self.coordinator.api.on: + return False + return self.coordinator.api.powerstate == "On" + + @property + def is_on(self) -> bool: + """Return True if entity is on.""" + return self.coordinator.api.huelamp_power == HUE_POWER_ON + + async def async_turn_on(self, **kwargs: Any) -> None: + """Turn the entity on.""" + await self.coordinator.api.setHueLampPower(HUE_POWER_ON) + self.async_write_ha_state() + + async def async_turn_off(self, **kwargs: Any) -> None: + """Turn the entity off.""" + await self.coordinator.api.setHueLampPower(HUE_POWER_OFF) + self.async_write_ha_state() diff --git a/requirements_all.txt b/requirements_all.txt index 0990ad32a3e..1aa848c826b 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -770,7 +770,7 @@ guppy3==3.1.2 ha-ffmpeg==3.0.2 # homeassistant.components.philips_js -ha-philipsjs==2.7.6 +ha-philipsjs==2.9.0 # homeassistant.components.habitica habitipy==0.2.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 2ff7f48c92d..1599a6e0d9b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -540,7 +540,7 @@ guppy3==3.1.2 ha-ffmpeg==3.0.2 # homeassistant.components.philips_js -ha-philipsjs==2.7.6 +ha-philipsjs==2.9.0 # homeassistant.components.habitica habitipy==0.2.0