Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.matrix.MatrixBot Class Reference

Public Member Functions

None __init__ (self, HomeAssistant hass, str config_file, str homeserver, bool verify_ssl, str username, str password, list[RoomAnyID] listening_rooms, list[ConfigCommand] commands)
 
None handle_send_message (self, ServiceCall service)
 

Public Attributes

 hass
 

Private Member Functions

JsonObjectType _get_auth_tokens (self)
 
None _handle_multi_room_send (self, Sequence[RoomAnyID] target_rooms, str message_type, dict content)
 
None _handle_room_message (self, MatrixRoom room, Event message)
 
None _handle_room_send (self, RoomAnyID target_room, str message_type, dict content)
 
None _join_room (self, RoomID room_id, RoomAnyID room_alias_or_id)
 
None _join_rooms (self)
 
None _load_commands (self, list[ConfigCommand] commands)
 
None _login (self)
 
dict[RoomAnyID, RoomID_resolve_room_alias (self, RoomAnyID room_alias_or_id)
 
None _resolve_room_aliases (self, list[RoomAnyID] listening_rooms)
 
None _send_image (self, str image_path, Sequence[RoomAnyID] target_rooms)
 
None _send_message (self, str message, list[RoomAnyID] target_rooms, dict|None data)
 
None _store_auth_token (self, str token)
 

Private Attributes

 _access_tokens
 
 _client
 
 _homeserver
 
 _mx_id
 
 _password
 
 _session_filepath
 
 _unparsed_commands
 
 _verify_tls
 

Detailed Description

The Matrix Bot.

Definition at line 162 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

None homeassistant.components.matrix.MatrixBot.__init__ (   self,
HomeAssistant  hass,
str  config_file,
str  homeserver,
bool  verify_ssl,
str  username,
str  password,
list[RoomAnyID listening_rooms,
list[ConfigCommand commands 
)
Set up the client.

Definition at line 167 of file __init__.py.

Member Function Documentation

◆ _get_auth_tokens()

JsonObjectType homeassistant.components.matrix.MatrixBot._get_auth_tokens (   self)
private
Read sorted authentication tokens from disk.

Definition at line 349 of file __init__.py.

◆ _handle_multi_room_send()

None homeassistant.components.matrix.MatrixBot._handle_multi_room_send (   self,
Sequence[RoomAnyID target_rooms,
str  message_type,
dict   content 
)
private
Wrap _handle_room_send for multiple target_rooms.

Definition at line 444 of file __init__.py.

◆ _handle_room_message()

None homeassistant.components.matrix.MatrixBot._handle_room_message (   self,
MatrixRoom  room,
Event  message 
)
private
Handle a message sent to a Matrix room.

Definition at line 249 of file __init__.py.

◆ _handle_room_send()

None homeassistant.components.matrix.MatrixBot._handle_room_send (   self,
RoomAnyID  target_room,
str  message_type,
dict   content 
)
private
Wrap _client.room_send and handle ErrorResponses.

Definition at line 426 of file __init__.py.

◆ _join_room()

None homeassistant.components.matrix.MatrixBot._join_room (   self,
RoomID  room_id,
RoomAnyID  room_alias_or_id 
)
private
Join a room or do nothing if already joined.

Definition at line 326 of file __init__.py.

◆ _join_rooms()

None homeassistant.components.matrix.MatrixBot._join_rooms (   self)
private
Join the Matrix rooms that we listen for commands in.

Definition at line 339 of file __init__.py.

◆ _load_commands()

None homeassistant.components.matrix.MatrixBot._load_commands (   self,
list[ConfigCommand commands 
)
private

Definition at line 231 of file __init__.py.

◆ _login()

None homeassistant.components.matrix.MatrixBot._login (   self)
private
Log in to the Matrix homeserver.

Attempts to use the stored access token.
If that fails, then tries using the password.
If that also fails, raises LocalProtocolError.

Definition at line 374 of file __init__.py.

◆ _resolve_room_alias()

dict[RoomAnyID, RoomID] homeassistant.components.matrix.MatrixBot._resolve_room_alias (   self,
RoomAnyID   room_alias_or_id 
)
private
Resolve a single RoomAlias if needed.

Definition at line 288 of file __init__.py.

◆ _resolve_room_aliases()

None homeassistant.components.matrix.MatrixBot._resolve_room_aliases (   self,
list[RoomAnyID listening_rooms 
)
private
Resolve any RoomAliases into RoomIDs for the purpose of client interactions.

Definition at line 315 of file __init__.py.

◆ _send_image()

None homeassistant.components.matrix.MatrixBot._send_image (   self,
str  image_path,
Sequence[RoomAnyID]   target_rooms 
)
private
Upload an image, then send it to all target_rooms.

Definition at line 460 of file __init__.py.

◆ _send_message()

None homeassistant.components.matrix.MatrixBot._send_message (   self,
str  message,
list[RoomAnyID target_rooms,
dict | None   data 
)
private
Send a message to the Matrix server.

Definition at line 513 of file __init__.py.

◆ _store_auth_token()

None homeassistant.components.matrix.MatrixBot._store_auth_token (   self,
str  token 
)
private
Store authentication token to session and persistent storage.

Definition at line 363 of file __init__.py.

◆ handle_send_message()

None homeassistant.components.matrix.MatrixBot.handle_send_message (   self,
ServiceCall  service 
)
Handle the send_message service.

Definition at line 538 of file __init__.py.

Member Data Documentation

◆ _access_tokens

homeassistant.components.matrix.MatrixBot._access_tokens
private

Definition at line 207 of file __init__.py.

◆ _client

homeassistant.components.matrix.MatrixBot._client
private

Definition at line 189 of file __init__.py.

◆ _homeserver

homeassistant.components.matrix.MatrixBot._homeserver
private

Definition at line 184 of file __init__.py.

◆ _mx_id

homeassistant.components.matrix.MatrixBot._mx_id
private

Definition at line 186 of file __init__.py.

◆ _password

homeassistant.components.matrix.MatrixBot._password
private

Definition at line 187 of file __init__.py.

◆ _session_filepath

homeassistant.components.matrix.MatrixBot._session_filepath
private

Definition at line 181 of file __init__.py.

◆ _unparsed_commands

homeassistant.components.matrix.MatrixBot._unparsed_commands
private

Definition at line 196 of file __init__.py.

◆ _verify_tls

homeassistant.components.matrix.MatrixBot._verify_tls
private

Definition at line 185 of file __init__.py.

◆ hass

homeassistant.components.matrix.MatrixBot.hass

Definition at line 179 of file __init__.py.


The documentation for this class was generated from the following file: