
    ^j                     h    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
 ddlmZ  G d d	ee
      Zy
)    )DictUnion)UnknownMethodException)Self)CanExecuteCommands)CanExecuteScripts   )MobileCommandc                       e Zd ZdefdZ	 	 	 ddeeef   deeef   deeedf   deeedf   deeedf   defd	Ze	de
eef   fd
       ZddZy)Locationreturnc                     	 | j                  d       | S # t        $ r# | j                  t        j                         Y | S w xY w)zToggle the location services on the device.
        This API only reliably since Android 12 (API level 31)

        Android only.

        Returns:
            Union['WebDriver', 'Location']: Self instance
        zmobile: toggleGps)execute_scriptr   executeCommandTOGGLE_LOCATION_SERVICESselfs    X/home/ubuntu/.local/lib/python3.12/site-packages/appium/webdriver/extensions/location.pytoggle_location_servicesz!Location.toggle_location_services   sE    	; 34  & 	;LL99:	;s    (A ANlatitude	longitudealtitudespeed
satellitesc                     d||di}|||d   d<   |||d   d<   |||d   d<   | j                  t        j                  |       | S )a"  Set the location of the device

        Args:
            latitude: String or numeric value between -90.0 and 90.00
            longitude: String or numeric value between -180.0 and 180.0
            altitude: String or numeric value (Android real device only)
            speed: String or numeric value larger than 0.0 (Android real devices only)
            satellites: String or numeric value of active GPS satellites in range 1..12. (Android emulators only)

        Returns:
            Union['WebDriver', 'Location']: Self instance
        location)r   r   r   r   r   )r   r   SET_LOCATION)r   r   r   r   r   r   datas          r   set_locationzLocation.set_location+   ss    * $&
 +3DZ((-DW%!-7D\*W))40    c                 F    | j                  t        j                        d   S )zRetrieves the current location

        Returns:
            A dictionary whose keys are
                - latitude (float)
                - longitude (float)
                - altitude (float)
        value)r   r   GET_LOCATIONr   s    r   r   zLocation.locationN   s     ||G001'::r!   c                    | j                   j                  t        j                  dd       | j                   j                  t        j                  dd       | j                   j                  t        j
                  dd       y)z2Add location endpoints. They are not int w3c spec.POSTz:/session/$sessionId/appium/device/toggle_location_servicesGETz/session/$sessionId/locationN)command_executoradd_commandr   r   r$   r   r   s    r   _add_commandszLocation._add_commandsZ   se    )),,H	

 	))'*>*>Gef))'*>*>Hfgr!   )NNN)r   N)__name__
__module____qualname__r   r   r   floatstrr    propertyr   r   r*    r!   r   r   r      s    $ ( -1)-.2!s
#! $! sD()	!
 UC%&! %d*+! 
!F 	;$sEz* 	; 	;hr!   r   N)typingr   r   selenium.common.exceptionsr   typing_extensionsr   /appium.protocols.webdriver.can_execute_commandsr   .appium.protocols.webdriver.can_execute_scriptsr   mobilecommandr
   r   r   r1   r!   r   <module>r8      s-     = " N L 4Hh!#4 Hhr!   