1 """Xbox Remote support."""
3 from __future__
import annotations
6 from collections.abc
import Iterable
10 from xbox.webapi.api.client
import XboxLiveClient
11 from xbox.webapi.api.provider.smartglass.models
import (
15 SmartglassConsoleList,
30 from .const
import DOMAIN
31 from .coordinator
import ConsoleData, XboxUpdateCoordinator
35 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
37 """Set up Xbox media_player from a config entry."""
38 client: XboxLiveClient = hass.data[DOMAIN][entry.entry_id][
"client"]
39 consoles: SmartglassConsoleList = hass.data[DOMAIN][entry.entry_id][
"consoles"]
40 coordinator: XboxUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
45 [
XboxRemote(client, console, coordinator)
for console
in consoles.result]
50 """Representation of an Xbox remote."""
54 client: XboxLiveClient,
55 console: SmartglassConsole,
56 coordinator: XboxUpdateCoordinator,
58 """Initialize the Xbox Media Player."""
60 self.client: XboxLiveClient = client
61 self._console: SmartglassConsole = console
65 """Return the device name."""
66 return f
"{self._console.name} Remote"
70 """Console device ID."""
71 return self._console.id
74 def data(self) -> ConsoleData:
75 """Return coordinator data for this console."""
76 return self.coordinator.data.consoles[self._console.id]
80 """Return True if device is on."""
81 return self.
datadatadatadata.status.power_state == PowerState.On
84 """Turn the Xbox on."""
85 await self.client.smartglass.wake_up(self._console.id)
88 """Turn the Xbox off."""
89 await self.client.smartglass.turn_off(self._console.id)
92 """Send controller or text input to the Xbox."""
93 num_repeats = kwargs[ATTR_NUM_REPEATS]
94 delay = kwargs.get(ATTR_DELAY_SECS, DEFAULT_DELAY_SECS)
96 for _
in range(num_repeats):
97 for single_command
in command:
99 button = InputKeyType(single_command)
100 await self.client.smartglass.press_button(self._console.id, button)
102 await self.client.smartglass.insert_text(
103 self._console.id, single_command
105 await asyncio.sleep(delay)
109 """Return a device description for device registry."""
111 matches = re.finditer(
112 ".+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)",
113 self._console.console_type,
117 identifiers={(DOMAIN, self._console.id)},
118 manufacturer=
"Microsoft",
119 model=
" ".join([m.group(0)
for m
in matches]),
120 name=self._console.name,
None __init__(self, XboxLiveClient client, SmartglassConsole console, XboxUpdateCoordinator coordinator)
None async_turn_on(self, **Any kwargs)
None async_send_command(self, Iterable[str] command, **Any kwargs)
DeviceInfo device_info(self)
None async_turn_off(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)