1 """Support for interface with a Ziggo Mediabox XL."""
3 from __future__
import annotations
8 import voluptuous
as vol
9 from ziggo_mediabox_xl
import ZiggoMediaboxXL
12 PLATFORM_SCHEMA
as MEDIA_PLAYER_PLATFORM_SCHEMA,
14 MediaPlayerEntityFeature,
23 _LOGGER = logging.getLogger(__name__)
25 DATA_KNOWN_DEVICES =
"ziggo_mediabox_xl_known_devices"
27 PLATFORM_SCHEMA = MEDIA_PLAYER_PLATFORM_SCHEMA.extend(
28 {vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_NAME): cv.string}
35 add_entities: AddEntitiesCallback,
36 discovery_info: DiscoveryInfoType |
None =
None,
38 """Set up the Ziggo Mediabox XL platform."""
40 hass.data[DATA_KNOWN_DEVICES] = known_devices = set()
43 if (host := config.get(CONF_HOST))
is not None:
44 name = config.get(CONF_NAME)
46 elif discovery_info
is not None:
47 host = discovery_info[
"host"]
48 name = discovery_info.get(
"name")
51 _LOGGER.error(
"Cannot determine device")
57 connection_successful =
False
58 ip_addr = socket.gethostbyname(host)
59 if ip_addr
not in known_devices:
62 mediabox = ZiggoMediaboxXL(ip_addr, 3)
64 if mediabox.test_connection():
65 connection_successful =
True
67 _LOGGER.error(
"Can't connect to %s", host)
69 _LOGGER.error(
"Can't connect to %s", host)
72 if manual_config
or connection_successful:
76 known_devices.add(ip_addr)
77 except OSError
as error:
78 _LOGGER.error(
"Can't connect to %s: %s", host, error)
80 _LOGGER.warning(
"Ignoring duplicate Ziggo Mediabox XL %s", host)
85 """Representation of a Ziggo Mediabox XL Device."""
87 _attr_supported_features = (
88 MediaPlayerEntityFeature.TURN_ON
89 | MediaPlayerEntityFeature.TURN_OFF
90 | MediaPlayerEntityFeature.NEXT_TRACK
91 | MediaPlayerEntityFeature.PAUSE
92 | MediaPlayerEntityFeature.PREVIOUS_TRACK
93 | MediaPlayerEntityFeature.SELECT_SOURCE
94 | MediaPlayerEntityFeature.PLAY
97 def __init__(self, mediabox, host, name, available):
98 """Initialize the device."""
105 """Retrieve the state of the device."""
117 _LOGGER.error(
"Couldn't fetch state from %s", self.
_host_host)
121 """Send keys to the device and handle exceptions."""
125 _LOGGER.error(
"Couldn't send keys to %s", self.
_host_host)
129 """List of available sources (channels)."""
132 for c
in sorted(self.
_mediabox_mediabox.channels().keys())
136 """Turn the media player on."""
140 """Turn off media player."""
144 """Send play command."""
146 self.
_attr_state_attr_state = MediaPlayerState.PLAYING
149 """Send pause command."""
151 self.
_attr_state_attr_state = MediaPlayerState.PAUSED
154 """Simulate play pause media player."""
157 self.
_attr_state_attr_state = MediaPlayerState.PLAYING
159 self.
_attr_state_attr_state = MediaPlayerState.PAUSED
164 self.
_attr_state_attr_state = MediaPlayerState.PLAYING
169 self.
_attr_state_attr_state = MediaPlayerState.PLAYING
172 """Select the channel."""
173 if str(source).isdigit():
179 for key, value
in self.
_mediabox_mediabox.channels().items()
187 self.
send_keyssend_keys([f
"NUM_{digit}" for digit
in str(digits)])
188 self.
_attr_state_attr_state = MediaPlayerState.PLAYING
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
str test_connection(HomeAssistant hass, data)