1 """Base SamsungTV Entity."""
3 from __future__
import annotations
5 from wakeonlan
import send_magic_packet
22 from .const
import CONF_MANUFACTURER, DOMAIN, LOGGER
23 from .coordinator
import SamsungTVDataUpdateCoordinator
24 from .triggers.turn_on
import async_get_turn_on_trigger
28 """Defines a base SamsungTV entity."""
30 _attr_has_entity_name =
True
32 def __init__(self, *, coordinator: SamsungTVDataUpdateCoordinator) ->
None:
33 """Initialize the SamsungTV entity."""
36 config_entry = coordinator.config_entry
37 self._mac: str |
None = config_entry.data.get(CONF_MAC)
38 self._host: str |
None = config_entry.data.get(CONF_HOST)
40 self.
_attr_unique_id_attr_unique_id = config_entry.unique_id
or config_entry.entry_id
42 name=config_entry.data.get(CONF_NAME),
43 manufacturer=config_entry.data.get(CONF_MANUFACTURER),
44 model=config_entry.data.get(CONF_MODEL),
45 model_id=config_entry.data.get(CONF_MODEL),
51 (dr.CONNECTION_NETWORK_MAC, self._mac)
57 """Return the availability of the device."""
58 if self.
_bridge_bridge.auth_failed:
61 self.coordinator.is_on
63 or self._mac
is not None
64 or self.
_bridge_bridge.power_off_in_progress
68 """Connect and subscribe to dispatcher signals and state updates."""
71 if (entry := self.
registry_entryregistry_entry)
and entry.device_id:
79 """Wake the device via wake on lan."""
80 send_magic_packet(self._mac, ip_address=self._host)
83 send_magic_packet(self._mac)
86 """Turn the device off."""
87 await self.
_bridge_bridge.async_power_off()
91 """Turn the remote on."""
93 LOGGER.debug(
"Attempting to turn on %s via automation", self.
entity_identity_id)
97 "Attempting to turn on %s via Wake-On-Lan; if this does not work, "
98 "please ensure that Wake-On-Lan is available for your device or use "
99 "a turn_on automation",
105 "Unable to turn on %s, as it does not have an automation configured",
109 f
"Entity {self.entity_id} does not support this service."
None _async_turn_off(self)
None async_added_to_hass(self)
None __init__(self, *SamsungTVDataUpdateCoordinator coordinator)
None _async_turn_on(self)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_register(HomeAssistant hass, system_health.SystemHealthRegistration register)
dict[str, str] async_get_turn_on_trigger(str device_id)
def async_run(config_dir)