
    (\i8-                       d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	m
Z
mZ ddlmZmZ ddlmZ ddlmZ d	d
lmZ ddlmZ erV	 ddlmZmZmZ 	 ddlmZ  G d ded      Z G d ded      Z G d ded      Ze
e ejB                  e"e#f   Z$e	eee$f      Z%d!dZ&d"dZ'	 	 	 	 	 	 	 	 	 	 	 	 d#dZ(dddddddejR                  ddf
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d$dZ*ddddddddddejR                  ddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d%d Z+y# e$ r ddlmZmZmZ Y w xY w# e$ r	 ddlmZ Y w xY w)&a  
This module provides some helper functions to allow straightforward publishing
of messages in a one-shot manner. In other words, they are useful for the
situation where you have a single/multiple messages you want to publish to a
broker, then disconnect and nothing else is required.
    )annotationsN)Iterable)TYPE_CHECKINGAnyListTupleUnion)CallbackAPIVersionMQTTProtocolVersion)
Properties)
ReasonCode   )mqtt   )client)NotRequiredRequired	TypedDict)Literalc                  "    e Zd ZU ded<   ded<   y)AuthParameterRequired[str]usernameNotRequired[str]passwordN__name__
__module____qualname____annotations__     a/home/devuser/fomin/mqttuser/mqtt_project/myenv/lib/python3.12/site-packages/paho/mqtt/publish.pyr   r   /   s    ""r"   r   F)totalc                  J    e Zd ZU ded<   ded<   ded<   ded<   ded<   d	ed
<   y)TLSParameterr   ca_certsr   certfilekeyfileNotRequired[int]tls_versionciphersNotRequired[bool]insecureNr   r!   r"   r#   r&   r&   4   s&    ""!!%%!!##r"   r&   c                  6    e Zd ZU ded<   ded<   ded<   ded<   y	)
MessageDictr   topiczNotRequired[paho.PayloadType]payloadr*   qosr-   retainNr   r!   r"   r#   r0   r0   =   s    ..!!r"   r0   c                    | j                   j                         }t        |t              r | j                  di | yt        |t
        t        f      r | j                  |  yt        d      )zInternal functionz&message must be a dict, tuple, or listNr!   )	_userdatapopleft
isinstancedictpublishtuplelist	TypeError)r   messages     r#   _do_publishr?   H   s[     &&(G'4 !!	GeT]	+ @AAr"   c                    |dk(  rt        |      dkD  rt        |        yyt        j                  t	        j
                  |            )zInternal v5 callbackr   N)lenr?   r   MQTTExceptionpahoconnack_string)r   userdataflagsreason_code
propertiess        r#   _on_connectrI   U   sA    ax=1    !4!4[!ABBr"   c                X    t        |      dk(  r| j                          yt        |        y)zInternal callbackr   N)rA   
disconnectr?   )r   rE   midreason_codesrH   s        r#   _on_publishrN   ^   s$     8}Fr"   	localhosti[   <   tcpc                   t        | t              st        d      t        |       dk(  rt	        d      t        j                  t        j                  |t        j                  |       ||	      }|j                          t        |_        t        |_        |
 |j                   di |
 |rB|j#                  d      }|r$|j#                  d      }|j%                  ||       nt'        d      | |j(                  di | |Yt        |t*              r8|j-                  d	d
      } |j.                  di | |r#|j1                  |       n|j3                  |       |j5                  |||       |j7                          y)a  Publish multiple messages to a broker, then disconnect cleanly.

    This function creates an MQTT client, connects to a broker and publishes a
    list of messages. Once the messages have been delivered, it disconnects
    cleanly from the broker.

    :param msgs: a list of messages to publish. Each message is either a dict or a
           tuple.

           If a dict, only the topic must be present. Default values will be
           used for any missing arguments. The dict must be of the form:

           msg = {'topic':"<topic>", 'payload':"<payload>", 'qos':<qos>,
           'retain':<retain>}
           topic must be present and may not be empty.
           If payload is "", None or not present then a zero length payload
           will be published.
           If qos is not present, the default of 0 is used.
           If retain is not present, the default of False is used.

           If a tuple, then it must be of the form:
           ("<topic>", "<payload>", qos, retain)

    :param str hostname: the address of the broker to connect to.
               Defaults to localhost.

    :param int port: the port to connect to the broker on. Defaults to 1883.

    :param str client_id: the MQTT client id to use. If "" or None, the Paho library will
                generate a client id automatically.

    :param int keepalive: the keepalive timeout value for the client. Defaults to 60
                seconds.

    :param will: a dict containing will parameters for the client: will = {'topic':
           "<topic>", 'payload':"<payload">, 'qos':<qos>, 'retain':<retain>}.
           Topic is required, all other parameters are optional and will
           default to None, 0 and False respectively.
           Defaults to None, which indicates no will should be used.

    :param auth: a dict containing authentication parameters for the client:
           auth = {'username':"<username>", 'password':"<password>"}
           Username is required, password is optional and will default to None
           if not provided.
           Defaults to None, which indicates no authentication is to be used.

    :param tls: a dict containing TLS configuration parameters for the client:
          dict = {'ca_certs':"<ca_certs>", 'certfile':"<certfile>",
          'keyfile':"<keyfile>", 'tls_version':"<tls_version>",
          'ciphers':"<ciphers">, 'insecure':"<bool>"}
          ca_certs is required, all other parameters are optional and will
          default to None if not provided, which results in the client using
          the default behaviour - see the paho.mqtt.client documentation.
          Alternatively, tls input can be an SSLContext object, which will be
          processed using the tls_set_context method.
          Defaults to None, which indicates that TLS should not be used.

    :param str transport: set to "tcp" to use the default setting of transport which is
          raw TCP. Set to "websockets" to use WebSockets as the transport.

    :param proxy_args: a dictionary that will be given to the client.
    zmsgs must be an iterabler   zmsgs is empty)	client_idrE   protocol	transportNr   r   z;The 'username' key was not found, this is required for authr.   Fr!   )r8   r   r=   rA   
ValueErrorrC   Clientr
   VERSION2collectionsdequeenable_loggerrN   
on_publishrI   
on_connect	proxy_setgetusername_pw_setKeyErrorwill_setr9   poptls_settls_insecure_settls_set_contextconnectloop_forever)msgshostnameportrT   	keepalivewillauthtlsrU   rV   
proxy_argsr   r   r   r.   s                  r#   multiplerr   j   sb   X dH%233
4yA~))[[##""4(F #F#F&:&88J'xx
+H""8X6 / 0 0 $
c4 wwz51HFNN!S! ''1 ""3'
NN8T9-
r"   c                >    | |||d}t        |g||||||	|
|||       y)a
  Publish a single message to a broker, then disconnect cleanly.

    This function creates an MQTT client, connects to a broker and publishes a
    single message. Once the message has been delivered, it disconnects cleanly
    from the broker.

    :param str topic: the only required argument must be the topic string to which the
            payload will be published.

    :param payload: the payload to be published. If "" or None, a zero length payload
              will be published.

    :param int qos: the qos to use when publishing,  default to 0.

    :param bool retain: set the message to be retained (True) or not (False).

    :param str hostname: the address of the broker to connect to.
               Defaults to localhost.

    :param int port: the port to connect to the broker on. Defaults to 1883.

    :param str client_id: the MQTT client id to use. If "" or None, the Paho library will
                generate a client id automatically.

    :param int keepalive: the keepalive timeout value for the client. Defaults to 60
                seconds.

    :param will: a dict containing will parameters for the client: will = {'topic':
           "<topic>", 'payload':"<payload">, 'qos':<qos>, 'retain':<retain>}.
           Topic is required, all other parameters are optional and will
           default to None, 0 and False respectively.
           Defaults to None, which indicates no will should be used.

    :param auth: a dict containing authentication parameters for the client:
           Username is required, password is optional and will default to None
           auth = {'username':"<username>", 'password':"<password>"}
           if not provided.
           Defaults to None, which indicates no authentication is to be used.

    :param tls: a dict containing TLS configuration parameters for the client:
          dict = {'ca_certs':"<ca_certs>", 'certfile':"<certfile>",
          'keyfile':"<keyfile>", 'tls_version':"<tls_version>",
          'ciphers':"<ciphers">, 'insecure':"<bool>"}
          ca_certs is required, all other parameters are optional and will
          default to None if not provided, which results in the client using
          the default behaviour - see the paho.mqtt.client documentation.
          Defaults to None, which indicates that TLS should not be used.
          Alternatively, tls input can be an SSLContext object, which will be
          processed using the tls_set_context method.

    :param transport: set to "tcp" to use the default setting of transport which is
          raw TCP. Set to "websockets" to use WebSockets as the transport.

    :param proxy_args: a dictionary that will be given to the client.
    )r1   r2   r3   r4   N)rr   )r1   r2   r3   r4   rk   rl   rT   rm   rn   ro   rp   rU   rV   rq   msgs                  r#   singleru      s4    P !&fUCcUHdIy$cy*.r"   )r   paho.Client)r   rv   rE   MessagesList)r   rv   rE   zcollections.deque[MessagesList]rL   intrM   r   rH   r   returnNone)rj   rw   rk   strrl   rx   rT   r{   rm   rx   rn   MessageDict | Nonero   AuthParameter | Nonerp   TLSParameter | NonerU   r   rV   Literal['tcp', 'websockets']rq   
Any | Nonery   rz   )r1   r{   r2   zpaho.PayloadTyper3   rx   r4   boolrk   r{   rl   rx   rT   r{   rm   rx   rn   r|   ro   r}   rp   r~   rU   r   rV   r   rq   r   ry   rz   ),__doc__
__future__r   rZ   collections.abcr   typingr   r   r   r   r	   paho.mqtt.enumsr
   r   paho.mqtt.propertiesr   paho.mqtt.reasoncodesr   rP   r   r   rC   r   r   r   ImportErrortyping_extensionsr   r   r&   r0   r{   PayloadTyperx   r   MessageTuplerw   r?   rI   rN   MQTTv311rr   ru   r!   r"   r#   <module>r      s   #  $ 9 9 C + ,  G;;."#	 #
$y $"iu " d..T9:Lk<789L
BC		#B	IL	\f	t~			  #!%#$(MM.3!z
zz z 	z
 z z z 
z "z ,z z 
z~ !%#!%#$(MM.3!K.K.K. 
K. 	K.
 K. K. K. K. K. K. 
K. "K. ,K. K. 
K.E  GFFG
  .-.s$   
D D0 D-,D-0D>=D>