
    :j1                        d Z ddlmZ ddlZddlmZ ddlZddlmZm	Z	m
Z
 ddlmZmZ ddlmZ dd	lmZmZ erdd
lmZ  G d de
          Z G d dej                  Z G d deej                  ZdS )zQ
Provides controllers to handle specific namespaces in Chromecast communication.
    )annotationsN)partial)TYPE_CHECKINGAnyProtocol   )UnsupportedNamespaceControllerNotRegistered)CastMessage)CallbackTypechain_on_success)SocketClientc                  $    e Zd ZdZddddddZdS )SendMessageFuncz3Protocol for SocketClient's send message functions.FNinc_session_idcallback_functionno_add_request_id	namespacestrmessager   r   boolr   CallbackType | Noner   returnNonec                   d S )N )selfr   r   r   r   r   s         W/home/user/adhan/venv/lib/python3.11/site-packages/pychromecast/controllers/__init__.py__call__zSendMessageFunc.__call__   s	     s    )r   r   r   r   r   r   r   r   r   r   r   r   )__name__
__module____qualname____doc__r    r   r!   r   r   r      sC        ==  %15"'       r!   r   c                      e Zd ZdZ	 	 	 d'd(dZed)d            Zdddd*dZd+dZd,dZ	d,dZ
d,dZddddd-dZddddd-d Zd.d%Zd,d&ZdS )/BaseControllerzABC for namespace controllers.NFr   r   supporting_app_id
str | Nonetarget_platformr   app_must_matchr   r   c                    || _         || _        || _        || _        d| _        d| _        t          j        t                    | _	        dS )a  
        Initialize the controller.

        namespace:         the namespace this controller will act on
        supporting_app_id: app to be launched if app is running with
                           unsupported namespace.
        target_platform:   set to True if you target the platform instead of
                           current app.
        app_must_match:    set to True if the app should be launched even if the
                           namespace is supported by another app.
        N)
r+   r   r(   r*   _socket_client_message_funclogging	getLoggerr"   logger)r   r   r(   r*   r+   s        r   __init__zBaseController.__init__'   sI    $ -"!2.3759'11r!   c                :    | j         duo| j        | j         j        v S )zTrue if the controller is connected to a socket client and the
        Chromecast is running an app that supports this controller.N)r-   r   app_namespacesr   s    r   	is_activezBaseController.is_activeC   s*    
 t+ E$"5"DD	
r!   )r   force_launchr   r   r7   c                  | j         5| j                            d| j        j                   |r |dd           dS | j        |r |dd           t          | j        j                            | j         ||           dS )z/If set, launches app related to the controller.Nz.%s: Can't launch app with no supporting app_idF)r7   r   )	r(   r1   debug	__class__r"   r-   r
   receiver_controller
launch_app)r   r   r7   s      r   launchzBaseController.launchL   s     !)K@'   ! /!!%...F&  /!!%...))/::"%/ 	; 	
 	
 	
 	
 	
r!   socket_clientr   c                j    || _         | j        r| j         j        | _        dS | j         j        | _        dS )z'Called when a controller is registered.N)r-   r*   send_platform_messager.   send_app_message)r   r>   s     r   
registeredzBaseController.registeredg   s>    + 	F!%!4!JD!%!4!EDr!   c                    d| _         dS )z)Called when a controller is unregistered.N)r.   r5   s    r   unregisteredzBaseController.unregisteredp   s    !r!   c                    dS )z^Called when a channel has been openend that supports the
        namespace of this controller.Nr   r5   s    r   channel_connectedz BaseController.channel_connectedt         r!   c                    dS )z&Called when a channel is disconnected.Nr   r5   s    r   channel_disconnectedz#BaseController.channel_disconnectedx   rG   r!   r   datar   r   r   c          
        | j         |r |dd           t          | j         j        }| j        s| j        | j         j        vs| j        ry|j        | j        k    ri| j        <| 	                    t          t          | j        |||          |                     dS |r |dd           t          d| j         d          |                     ||||           dS )z
        Send a message on this namespace to the Chromecast. Ensures app is loaded.

        Will raise a NotConnected exception if not connected.
        NF)r   r   )r   z
Namespace z) is not supported by running application.r   )r-   r
   r;   r*   r   r4   r+   app_idr(   r=   r   r   send_message_nocheckr	   )r   rJ   r   r   r   receiver_ctrls         r   send_messagezBaseController.send_message{   sD    &  /!!%...))+?# 	N$"5"DDD# E(5(<@V(V(V%1&6 5 +9.?	   *' '  
 
 
   /!!%...&VT^VVV   	!!)//	 	" 	
 	
 	
 	
 	
r!   c               d    t           r	| j        sJ |                     | j        ||||           dS )zSend a message.r   N)r   r.   r   )r   rJ   r   r   r   s        r   rM   z#BaseController.send_message_nocheck   sS      	&%%%%N)// 	 	
 	
 	
 	
 	
r!   _messager   _datadictc                    dS )z
        Called when a message is received that matches the namespace.
        Returns boolean indicating if message was handled.
        data is message.payload_utf8 interpreted as a JSON dict.
        Fr   )r   rQ   rR   s      r   receive_messagezBaseController.receive_message   s	     ur!   c                "    d| _         d| _        dS )z!Called when we are shutting down.N)r-   r.   r5   s    r   	tear_downzBaseController.tear_down   s    "!r!   )NFF)
r   r   r(   r)   r*   r   r+   r   r   r   )r   r   )r   r   r7   r   r   r   )r>   r   r   r   )r   r   )
rJ   r   r   r   r   r   r   r   r   r   )rQ   r   rR   rS   r   r   )r"   r#   r$   r%   r2   propertyr6   r=   rB   rD   rF   rI   rO   rM   rU   rW   r   r!   r   r'   r'   $   sS       ((
 )- %$2 2 2 2 28 
 
 
 X
 26"	
 
 
 
 
 
6F F F F" " " ") ) ) )5 5 5 5  %15"'1
 1
 1
 1
 1
 1
n  %15"'
 
 
 
 
 
(   " " " " " "r!   r'   c                  4    e Zd ZdZej        dd
            ZdS )QuickPlayControllerz-ABC for controller which supports quick play.media_idr   timeoutfloatkwargsr   r   r   c                   dS )z$Quick Play support for a controller.Nr   )r   r[   r\   r^   s       r   
quick_playzQuickPlayController.quick_play   rG   r!   N)r[   r   r\   r]   r^   r   r   r   )r"   r#   r$   r%   abcabstractmethodr`   r   r!   r   rZ   rZ      s<        773 3 3 3 3 3r!   rZ   )r%   
__future__r   ra   	functoolsr   r/   typingr   r   r   errorr	   r
   generated.cast_channel_pb2r   response_handlerr   r   r>   r   r   ABCr'   rZ   r   r!   r   <module>rj      sf    # " " " " " 



        / / / / / / / / / / A A A A A A A A      > = = = = = = = -,,,,,,    h   i" i" i" i" i"SW i" i" i"X3 3 3 3 3.#' 3 3 3 3 3r!   