diff --git a/homeassistant/components/samsungtv/entity.py b/homeassistant/components/samsungtv/entity.py index e2c1fb66bcc..8bf2c2b864b 100644 --- a/homeassistant/components/samsungtv/entity.py +++ b/homeassistant/components/samsungtv/entity.py @@ -12,6 +12,7 @@ from homeassistant.const import ( CONF_MODEL, CONF_NAME, ) +from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import device_registry as dr from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity import Entity @@ -67,3 +68,19 @@ class SamsungTVEntity(CoordinatorEntity[SamsungTVDataUpdateCoordinator], Entity) # If the ip address changed since we last saw the device # broadcast a packet as well send_magic_packet(self._mac) + + async def _async_turn_off(self) -> None: + """Turn the device off.""" + await self._bridge.async_power_off() + await self.coordinator.async_refresh() + + async def _async_turn_on(self) -> None: + """Turn the remote on.""" + if self._turn_on_action: + await self._turn_on_action.async_run(self.hass, self._context) + elif self._mac: + await self.hass.async_add_executor_job(self._wake_on_lan) + else: + raise HomeAssistantError( + f"Entity {self.entity_id} does not support this service." + ) diff --git a/homeassistant/components/samsungtv/media_player.py b/homeassistant/components/samsungtv/media_player.py index 6b984130f70..6b9bd432789 100644 --- a/homeassistant/components/samsungtv/media_player.py +++ b/homeassistant/components/samsungtv/media_player.py @@ -311,8 +311,7 @@ class SamsungTVDevice(SamsungTVEntity, MediaPlayerEntity): async def async_turn_off(self) -> None: """Turn off media player.""" - await self._bridge.async_power_off() - await self.coordinator.async_refresh() + await super()._async_turn_off() async def async_set_volume_level(self, volume: float) -> None: """Set volume level on the media player.""" @@ -386,10 +385,7 @@ class SamsungTVDevice(SamsungTVEntity, MediaPlayerEntity): async def async_turn_on(self) -> None: """Turn the media player on.""" - if self._turn_on_action: - await self._turn_on_action.async_run(self.hass, self._context) - elif self._mac: - await self.hass.async_add_executor_job(self._wake_on_lan) + await super()._async_turn_on() async def async_select_source(self, source: str) -> None: """Select input source.""" diff --git a/homeassistant/components/samsungtv/remote.py b/homeassistant/components/samsungtv/remote.py index 29681f96ab7..f32b107eaee 100644 --- a/homeassistant/components/samsungtv/remote.py +++ b/homeassistant/components/samsungtv/remote.py @@ -7,7 +7,6 @@ from typing import Any from homeassistant.components.remote import ATTR_NUM_REPEATS, RemoteEntity from homeassistant.core import HomeAssistant -from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import SamsungTVConfigEntry @@ -33,7 +32,7 @@ class SamsungTVRemote(SamsungTVEntity, RemoteEntity): async def async_turn_off(self, **kwargs: Any) -> None: """Turn the device off.""" - await self._bridge.async_power_off() + await super()._async_turn_off() async def async_send_command(self, command: Iterable[str], **kwargs: Any) -> None: """Send a command to a device. @@ -53,11 +52,4 @@ class SamsungTVRemote(SamsungTVEntity, RemoteEntity): async def async_turn_on(self, **kwargs: Any) -> None: """Turn the remote on.""" - if self._turn_on_action: - await self._turn_on_action.async_run(self.hass, self._context) - elif self._mac: - await self.hass.async_add_executor_job(self._wake_on_lan) - else: - raise HomeAssistantError( - f"Entity {self.entity_id} does not support this service." - ) + await super()._async_turn_on()