PhilipsTV - Add Ambilight + Hue switch entity (#69141)

* Bump ha-philipsjs requirements

* Directly write correct ha state after switching on

* Update homeassistant/components/philips_js/switch.py

Co-authored-by: Joakim Plate <elupus@ecce.se>

* Update homeassistant/components/philips_js/switch.py

Co-authored-by: Joakim Plate <elupus@ecce.se>

* Format with black

Co-authored-by: Joakim Plate <elupus@ecce.se>
pull/69331/head
Bram Gerritsen 2022-04-05 10:23:07 +02:00 committed by GitHub
parent 5d07be7190
commit 9c949f7f8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 3 deletions

View File

@ -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",

View File

@ -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()

View File

@ -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

View File

@ -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