Add available and state to SamsungTV remote (#117909)

* Add available and state to SamsungTV remote

* Align turn_off

* Fix merge

* Fix merge (again)
This commit is contained in:
epenet 2024-05-22 20:35:34 +02:00 committed by GitHub
parent 0d5c8e30cd
commit deded19bb3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 14 deletions

View File

@ -51,6 +51,18 @@ class SamsungTVEntity(CoordinatorEntity[SamsungTVDataUpdateCoordinator], Entity)
}
self._turn_on_action = PluggableAction(self.async_write_ha_state)
@property
def available(self) -> bool:
"""Return the availability of the device."""
if self._bridge.auth_failed:
return False
return (
self.coordinator.is_on
or bool(self._turn_on_action)
or self._mac is not None
or self._bridge.power_off_in_progress
)
async def async_added_to_hass(self) -> None:
"""Connect and subscribe to dispatcher signals and state updates."""
await super().async_added_to_hass()

View File

@ -297,18 +297,6 @@ class SamsungTVDevice(SamsungTVEntity, MediaPlayerEntity):
return
await self._bridge.async_send_keys(keys)
@property
def available(self) -> bool:
"""Return the availability of the device."""
if self._bridge.auth_failed:
return False
return (
self.state == MediaPlayerState.ON
or bool(self._turn_on_action)
or self._mac is not None
or self._bridge.power_off_in_progress
)
async def async_turn_off(self) -> None:
"""Turn off media player."""
await super()._async_turn_off()

View File

@ -6,7 +6,7 @@ from collections.abc import Iterable
from typing import Any
from homeassistant.components.remote import ATTR_NUM_REPEATS, RemoteEntity
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import SamsungTVConfigEntry
@ -28,7 +28,12 @@ class SamsungTVRemote(SamsungTVEntity, RemoteEntity):
"""Device that sends commands to a SamsungTV."""
_attr_name = None
_attr_should_poll = False
@callback
def _handle_coordinator_update(self) -> None:
"""Handle data update."""
self._attr_is_on = self.coordinator.is_on
self.async_write_ha_state()
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the device off."""