
    ^j*                     r    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	 d dl
mZ ddlmZ  G d	 d
ee	e      Zy)    )Optional)UnknownMethodException)Self)CanExecuteCommands)CanExecuteScripts)CanRememberExtensionPresence   )MobileCommandc                   |    e Zd Zddee   defdZdefdZdefdZ	defdZ
dedefd	Zdefd
ZdedefdZddZy)HardwareActionsNsecondsreturnc                     d}d|xs di}	 | j                  |      j                  ||       | S # t        $ r3 | j                  |      j	                  t
        j                  |       Y | S w xY w)a  Lock the device. No changes are made if the device is already unlocked.

        Args:
            seconds: The duration to lock the device, in seconds.
                The device is going to be locked forever until `unlock` is called
                if it equals or is less than zero, otherwise this call blocks until
                the timeout expires and unlocks the screen automatically.

        Returns:
            Union['WebDriver', 'HardwareActions']: Self instance
        zmobile: lockr   r   )assert_extension_existsexecute_scriptr   mark_extension_absenceexecuteCommandLOCK)selfr   ext_nameargss       Z/home/ubuntu/.local/lib/python3.12/site-packages/appium/webdriver/extensions/hw_actions.pylockzHardwareActions.lock   sv     "7<a(	N((2AA(DQ  & 	N''199',,M	Ns   !/ 8A+*A+c                     d}	 | j                  |      j                  d      s| S | j                  |       | S # t        $ r2 | j                  |      j	                  t
        j                         Y | S w xY w)zUnlock the device. No changes are made if the device is already locked.

        Returns:
            Union['WebDriver', 'HardwareActions']: Self instance
        zmobile: unlockmobile: isLocked)r   r   r   r   r   r   UNLOCKr   r   s     r   unlockzHardwareActions.unlock1   sx     $	J//9HHI[\)  & 	J''199'..I	Js   !9 9 7A43A4c                     d}	 | j                  |      j                  d      S # t        $ r4 | j                  |      j	                  t
        j                        d   cY S w xY w)zjChecks whether the device is locked.

        Returns:
            `True` if the device is locked
        r   value)r   r   r   r   r   r   	IS_LOCKEDr   s     r   	is_lockedzHardwareActions.is_lockedA   se     &	]//9HHI[\\% 	]..x8@@ARARST[\\	]s   $ :A! A!c                     d}	 | j                  |      j                  |       | S # t        $ r2 | j                  |      j	                  t
        j                         Y | S w xY w)zmShake the device.

        Returns:
            Union['WebDriver', 'HardwareActions']: Self instance
        zmobile: shake)r   r   r   r   r   r   SHAKEr   s     r   shakezHardwareActions.shakeN   sd     #	I((2AA(K  & 	I''199'--H	Is    & 7A! A!matchc                 0    | j                  dd|d       | S )zSimulate touchId on iOS Simulator

        Args:
            match: Simulates a successful touch (`True`) or a failed touch (`False`)

        Returns:
            Union['WebDriver', 'HardwareActions']: Self instance
        zmobile: sendBiometricMatchtouchId)typer'   r   )r   r'   s     r   touch_idzHardwareActions.touch_id\   s'     	(!	
     c                 R    | j                  d      }| j                  dd| i       | S )zToggle enroll touchId on iOS Simulator

        Returns:
            Union['WebDriver', 'HardwareActions']: Self instance
        zmobile: isBiometricEnrolledzmobile: enrollBiometric	isEnabledr+   )r   is_enrolleds     r   toggle_touch_id_enrollmentz*HardwareActions.toggle_touch_id_enrollmentn   s2     ))*GH5_7UVr-   	finger_idc                     d}d|i}	 | j                  |      j                  ||       | S # t        $ r3 | j                  |      j	                  t
        j                  |       Y | S w xY w)zAuthenticate users by using their finger print scans on supported Android emulators.

        Args:
            finger_id: Finger prints stored in Android Keystore system (from 1 to 10)
        zmobile: fingerprintfingerprintId)r   r   r   r   r   r   FINGER_PRINT)r   r2   r   r   s       r   finger_printzHardwareActions.finger_printx   su     )+	V((2AA(DQ  & 	V''199':N:NPTU	Vs   !+ 8A'&A'c                 ^   | j                   j                  t        j                  dd       | j                   j                  t        j                  dd       | j                   j                  t        j
                  dd       | j                   j                  t        j                  dd       | j                   j                  t        j                  dd       | j                   j                  t        j                  dd       | j                   j                  t        j                  dd       y )	NPOSTz&/session/$sessionId/appium/device/lockz(/session/$sessionId/appium/device/unlockz+/session/$sessionId/appium/device/is_lockedz'/session/$sessionId/appium/device/shakez-/session/$sessionId/appium/simulator/touch_idz?/session/$sessionId/appium/simulator/toggle_touch_id_enrollmentz./session/$sessionId/appium/device/finger_print)
command_executoradd_commandr   r   r   r"   r%   TOUCH_IDTOGGLE_TOUCH_ID_ENROLLMENTr5   )r   s    r   _add_commandszHardwareActions._add_commands   s    ))',,@hi))'..&Blm))'*;*;VErs))'--Ajk))'*:*:FDst))..M	

 	))  <	
r-   )N)r   N)__name__
__module____qualname__r   intr   r   r   boolr#   r&   r,   r1   r6   r=    r-   r   r   r      sv    HSM T *  ]4 ]t d t $D c d 
r-   r   N)typingr   selenium.common.exceptionsr   typing_extensionsr   /appium.protocols.webdriver.can_execute_commandsr   .appium.protocols.webdriver.can_execute_scriptsr   :appium.protocols.webdriver.can_remember_extension_presencer   mobilecommandr
   r   r   rC   r-   r   <module>rK      s1     = " N L c 4z
(*;=Y z
r-   