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>
This commit is contained in:
parent
5d07be7190
commit
9c949f7f8f
4 changed files with 56 additions and 3 deletions
|
@ -2,7 +2,7 @@
|
||||||
"domain": "philips_js",
|
"domain": "philips_js",
|
||||||
"name": "Philips TV",
|
"name": "Philips TV",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/philips_js",
|
"documentation": "https://www.home-assistant.io/integrations/philips_js",
|
||||||
"requirements": ["ha-philipsjs==2.7.6"],
|
"requirements": ["ha-philipsjs==2.9.0"],
|
||||||
"codeowners": ["@elupus"],
|
"codeowners": ["@elupus"],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
|
|
|
@ -13,6 +13,9 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
from . import PhilipsTVDataUpdateCoordinator
|
from . import PhilipsTVDataUpdateCoordinator
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
HUE_POWER_OFF = "Off"
|
||||||
|
HUE_POWER_ON = "On"
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
@ -26,6 +29,9 @@ async def async_setup_entry(
|
||||||
|
|
||||||
async_add_entities([PhilipsTVScreenSwitch(coordinator)])
|
async_add_entities([PhilipsTVScreenSwitch(coordinator)])
|
||||||
|
|
||||||
|
if coordinator.api.json_feature_supported("ambilight", "Hue"):
|
||||||
|
async_add_entities([PhilipsTVAmbilightHueSwitch(coordinator)])
|
||||||
|
|
||||||
|
|
||||||
class PhilipsTVScreenSwitch(
|
class PhilipsTVScreenSwitch(
|
||||||
CoordinatorEntity[PhilipsTVDataUpdateCoordinator], SwitchEntity
|
CoordinatorEntity[PhilipsTVDataUpdateCoordinator], SwitchEntity
|
||||||
|
@ -70,3 +76,50 @@ class PhilipsTVScreenSwitch(
|
||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn the entity off."""
|
"""Turn the entity off."""
|
||||||
await self.coordinator.api.setScreenState("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()
|
||||||
|
|
|
@ -770,7 +770,7 @@ guppy3==3.1.2
|
||||||
ha-ffmpeg==3.0.2
|
ha-ffmpeg==3.0.2
|
||||||
|
|
||||||
# homeassistant.components.philips_js
|
# homeassistant.components.philips_js
|
||||||
ha-philipsjs==2.7.6
|
ha-philipsjs==2.9.0
|
||||||
|
|
||||||
# homeassistant.components.habitica
|
# homeassistant.components.habitica
|
||||||
habitipy==0.2.0
|
habitipy==0.2.0
|
||||||
|
|
|
@ -540,7 +540,7 @@ guppy3==3.1.2
|
||||||
ha-ffmpeg==3.0.2
|
ha-ffmpeg==3.0.2
|
||||||
|
|
||||||
# homeassistant.components.philips_js
|
# homeassistant.components.philips_js
|
||||||
ha-philipsjs==2.7.6
|
ha-philipsjs==2.9.0
|
||||||
|
|
||||||
# homeassistant.components.habitica
|
# homeassistant.components.habitica
|
||||||
habitipy==0.2.0
|
habitipy==0.2.0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue