Managers - Communicate with the Service Channels¶
Managers for handling different ServiceChannels.
If a manager for a specific ServiceChannel
is attached,
incoming messages get forwarded there, otherways they are discarded.
Managers can be attached by calling add_manager() on the Console
object (see example)
Methods of manager are available through console-context.
Example
How to add a manager:
discovered = await Console.discover(timeout=1)
if len(discovered):
console = discovered[0]
# Add manager, optionally passing initialization parameter
some_arg_for_manager_init = 'example'
console.add_manager(
MediaManager,
additional_arg=some_arg_for_manager_init
)
await console.connect()
if console.connection_state != ConnectionState.Connected:
print("Connection failed")
sys.exit(1)
console.wait(1)
# Call manager method
console.media_command(0x54321, MediaControlCommand.PlayPauseToggle, 0)
else:
print("No consoles discovered")
sys.exit(1)
-
class
xbox.sg.manager.
Manager
(console, channel: xbox.sg.enum.ServiceChannel)¶ Bases:
object
-
__init__
(console, channel: xbox.sg.enum.ServiceChannel)¶ Don’t use directly! INTERNALLY called by the parent
Console
!- Parameters
console – Console object, internally passed by `Console.add_manager
channel – Service channel
-
_on_message
(msg, channel)¶ Managers must implement this
-
_on_json
(data, channel)¶ Managers must implement this
-
async
_send_message
(msg: xbox.sg.utils.struct.XStruct)¶ Internal method to send messages to initialized Service Channel
- Parameters
msg (
XStructObj
) – Message
-
-
class
xbox.sg.manager.
InputManager
(console)¶ Bases:
xbox.sg.manager.Manager
-
__init__
(console)¶ Input Manager (ServiceChannel.SystemInput)
- Parameters
console – Console object, internally passed by `Console.add_manager
-
_on_message
(msg: xbox.sg.utils.struct.XStruct, channel: xbox.sg.enum.ServiceChannel) → None¶ Internal handler method to receive messages from SystemInput Channel
- Parameters
msg – Message
channel – Service channel
-
async
gamepad_input
(buttons: xbox.sg.enum.GamePadButton, l_trigger: int = 0, r_trigger: int = 0, l_thumb_x: int = 0, l_thumb_y: int = 0, r_thumb_x: int = 0, r_thumb_y: int = 0) → None¶ Send gamepad input
- Parameters
buttons – Gamepad buttons bits
l_trigger – Left trigger value
r_trigger – Right trigger value
l_thumb_x – Left thumbstick X-axis value
l_thumb_y – Left thumbstick Y-axis value
r_thumb_x – Right thumbstick X-axis value
r_thumb_y – Right thumbstick Y-axis value
Returns: None
-
-
class
xbox.sg.manager.
MediaManager
(console)¶ Bases:
xbox.sg.manager.Manager
-
__init__
(console)¶ Media Manager (ServiceChannel.SystemMedia)
Args: Console object, internally passed by `Console.add_manager
-
_on_message
(msg: xbox.sg.utils.struct.XStruct, channel: xbox.sg.enum.ServiceChannel) → None¶ Internal handler method to receive messages from SystemMedia Channel
- Parameters
msg – Message
channel – Service channel
-
property
media_state
¶ Media state payload
Returns: Media state payload
-
property
active_media
¶ Check whether console has active media
Returns: True if media is active, False if not
-
property
title_id
¶ Title Id of active media
Returns: Title Id
-
property
aum_id
¶ Application user model Id of active media
Returns: Aum Id
-
property
asset_id
¶ Asset Id of active media
Returns: Asset Id
-
property
media_type
¶ Media type of active media
Returns: Media type
-
property
sound_level
¶ Sound level of active media
Returns: Sound level
-
property
enabled_commands
¶ Enabled MediaCommands bitmask
Returns: Bitmask of enabled commands
-
property
playback_status
¶ Playback status of active media
Returns: Playback status
-
property
rate
¶ Playback rate of active media
Returns: Playback rate
-
property
position
¶ Playback position of active media
Returns: Playback position in microseconds
-
property
media_start
¶ Media start position of active media
Returns: Media start position in microseconds
-
property
media_end
¶ Media end position of active media
Returns: Media end position in microseconds
-
property
min_seek
¶ Minimum seek position of active media
Returns: Minimum position in microseconds
-
property
max_seek
¶ Maximum seek position of active media
Returns: Maximum position in microseconds
-
property
metadata
¶ Media metadata of active media
Returns: Media metadata
-
-
class
xbox.sg.manager.
TextManager
(console)¶ Bases:
xbox.sg.manager.Manager
-
__init__
(console)¶ Text Manager (ServiceChannel.SystemText)
- Parameters
console – Console object, internally passed by `Console.add_manager
-
_on_message
(msg: xbox.sg.utils.struct.XStruct, channel: xbox.sg.enum.ServiceChannel)¶ Internal handler method to receive messages from SystemText Channel
- Parameters
msg (
XStructObj
) – Messagechannel (
ServiceChannel
) – Service channel
-
property
got_active_session
¶ Check whether a text session is active
- Returns
Returns True if any text session is active, False otherwise
- Return type
-
property
text_session_id
¶ Current Text session id
- Returns
Text session id if existing, None otherwise
- Return type
-
property
text_options
¶ Current Text options
- Returns
Text options if existing, None otherwise
- Return type
TextOption
-
property
text_input_scope
¶ Current Text input scope
Returns: Text input scope if existing, None otherwise
-
property
max_text_length
¶ Maximum Text length
Returns: Max text length if existing, None otherwise
-
property
text_locale
¶ Test
Returns: Text locale if existing, None otherwise
-
property
text_prompt
¶ Test
Returns: Text prompt if existing, None otherwise
-
async
send_systemtext_input
(text: str) → Optional[xbox.sg.enum.AckStatus]¶ Sends text input
- Parameters
text – Text string to send
- Raises
TextManagerError – If message was not acknowledged via AckMsg or SystemTextAck
Returns: Ack status
-
async
send_systemtext_ack
(session_id: int, version: int) → Optional[xbox.sg.enum.AckStatus]¶ Acknowledges a SystemText message sent from the console
- Parameters
session_id – Current text session id
version – Text version to ack
Returns: Ack status
-
async
send_systemtext_done
(session_id: int, version: int, flags: int, result: xbox.sg.enum.TextResult) → Optional[xbox.sg.enum.AckStatus]¶ Informs the console that a text session is done.
Result field tells wether text input should be accepted or cancelled.
- Parameters
session_id – Current text session id
version – Last acknowledged text version
flags – Flags
result – Text result to send
Returns: Ack status
-