o
    l>jJ1                     @  s  d Z ddlm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mZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZ ejd	d
ZdZ dZ!e"dej#dddd
dddddeedf	ddd'd(Z$e"d)ej%d*e!d
ej#ddd+d
ej#dd,d-d
dddddeedfded1d2Z&e"d3ej%d*e!d
e#d4d5dddddeedf
dfd7d8Z'e"d9ej%d*e!d
ej%d*d:d
e#d;d5ej#dd<d=d
dddddeedfdgd?d@Z(e"dAej%d*e!d
ej#dBdCdDd
ej#dEdFdGd
ej#dBdHdId
dddddeedfdhdLdMZ)e"dNej%d*e!d
e#dEdFej#ddOdPdQd
dddddeedfdidSdTZ*e"dUej%d*e!d
ej#d*dVdWd
ej#ddXdYd
ej#ddZd[d\d]dddddeedfdjdbdcZ+dS )kzFind My device commands.    )annotations)PathN)	get_stateresolve_deviceservice_call)normalize_device_detailsnormalize_device_summary)DEFAULT_LOG_LEVELDEFAULT_OUTPUT_FORMATHttpProxyOptionHttpsProxyOptionLogLevelOptionNoVerifySslOptionOutputFormatOptionSessionDirOptionUsernameOptionWithFamilyOptionstore_command_options)console_kv_tableconsole_tableprint_json_textwrite_json_filezWork with Find My devices.)helpzFind MyzDevice id or name.listFz--locatezFetch current device locations.ctxtyper.Contextlocateboolusernamer   session_dirr   
http_proxyr   https_proxyr   no_verify_sslr   output_formatr   	log_levelr   with_familyr   returnNonec
                   s   t | ||||||||	d	 t| }
|
  fddtt fdd jdD }|
jr2|
| dS |
j	t
dg d	d
d |D  dS )zList Find My devices.r   r   r    r!   r"   r#   r$   r%   c                   s   g | ]}t | d qS )r   )r   ).0devicer)    R/home/thesage/.local/lib/python3.10/site-packages/pyicloud/cli/commands/devices.py
<listcomp>C   s    
z devices_list.<locals>.<listcomp>c                     s    j S N)devicesr,   )apir,   r-   <lambda>G   s    zdevices_list.<locals>.<lambda>account_nameNDevices)IDNameDisplayModelBatteryStatusc              	   S  s4   g | ]}|d  |d |d |d |d |d fqS )idnamedisplay_namedevice_modelbattery_levelbattery_statusr,   )r*   rowr,   r,   r-   r.   R   s    	)r   r   get_apir   FIND_MYr4   json_output
write_jsonconsoleprintr   )r   r   r   r   r    r!   r"   r#   r$   r%   statepayloadr,   )r1   r   r-   devices_list%   s@   


	rK   show.zFetch current device location.z--rawzShow the raw device payload.r+   strrawc                 C  s   t | ||||||	|
|d	 t| }| }t||}|r|jnt||d}|jr/|| dS |r9t|j	| dS |j	
td|d  d|d fd|d	 fd
|d fd|d fd|d fd|d fd|d fg dS )z)Show detailed information for one device.r(   r)   NzDevice: r=   r6   r<   zDisplay Namer>   zDevice Classdevice_classzDevice Modelr?   zBattery Levelr@   zBattery StatusrA   Locationlocation)r   r   rC   r   datar   rE   rF   r   rG   rH   r   )r   r+   r   rN   r   r   r    r!   r"   r#   r$   r%   rI   r1   idevicerJ   r,   r,   r-   devices_showa   sD   








rT   soundzFind My iPhone Alertz	--subjectsubjectc                   s   t | |||||||	|
d	 t| }| }t|| tt fdd|jd  jd}|jr7|	| dS |j
d j d dS )	zPlay a sound on a device.r(   c                     s    j dS )N)rV   )
play_soundr,   rS   rV   r,   r-   r2      s    zdevices_sound.<locals>.<lambda>r3   )	device_idrV   NzRequested sound alert for .r   r   rC   r   r   rD   r4   r<   rE   rF   rG   rH   r=   )r   r+   rV   r   r   r    r!   r"   r#   r$   r%   rI   r1   rJ   r,   rX   r-   devices_sound   s0   

r\   messagezMessage to display.z	A Messagez--silentzDo not play a sound.silentc                   s   t | |||||	|
||d	 t| }| }t|| tt fdd|jd  jd}|jr;|	| dS |j
d j d dS )	zDisplay a message on a device.r(   c                     s    j  dS )N)rV   r]   sounds)display_messager,   rS   r]   r^   rV   r,   r-   r2      s    z!devices_message.<locals>.<lambda>r3   )rY   rV   r]   r^   NzRequested message for rZ   r[   )r   r+   r]   rV   r^   r   r   r    r!   r"   r#   r$   r%   rI   r1   rJ   r,   ra   r-   devices_message   s8   

rb   z	lost-mode z--phonez Phone number shown in lost mode.z*This iPhone has been lost. Please call me.z	--messagezLost mode message.z
--passcodezNew device passcode.phonepasscodec                   s   t | |||||	|
||d	 t| }| }t||dd tt fdd|jd  jd}|jr=|	| dS |j
d	 j d
 dS )zEnable lost mode for a device.r(   Trequire_uniquec                     s    j dS )N)numbertextnewpasscode)lost_devicer,   rS   r]   re   rd   r,   r-   r2     s    z#devices_lost_mode.<locals>.<lambda>r3   )rY   rd   r]   re   NzRequested lost mode for rZ   r[   )r   r+   rd   r]   re   r   r   r    r!   r"   r#   r$   r%   rI   r1   rJ   r,   rl   r-   devices_lost_mode   s8   
rm   erasez--forcez-fzSkip confirmation prompt.forcec                   s   t | ||||||	|
|d	 t| }| }t||dd |s,td j ds,t tt	 fdd|j
d  jd	}|jrI|| d
S |jd j d d
S )z$Request a remote erase for a device.r(   Trf   z(This will PERMANENTLY ERASE all data on z. Continue?c                     s
     S r/   )erase_devicer,   rS   r]   r,   r-   r2   U  s   
 zdevices_erase.<locals>.<lambda>r3   )rY   r]   NzRequested remote erase for rZ   )r   r   rC   r   typerconfirmr=   Abortr   rD   r4   r<   rE   rF   rG   rH   )r   r+   r]   ro   r   r   r    r!   r"   r#   r$   r%   rI   r1   rJ   r,   rq   r-   devices_erase+  s8   
ru   exportz--outputzDestination JSON file.z--raw/--no-rawzWrite the raw device payload.z--normalizedTz:Write normalized device fields instead of the raw payload.)hiddenr   outputr   bool | None
normalizedc                 C  s   t | |||||	|
||d	 t| }| }t||}|r#|r#td|du o)| }|r/|jnt|dd}t|| |j	rK|
|jt||d dS |jt| dS )z!Export a device snapshot to JSON.r(   z.Choose either --raw or --normalized, not both.TFr)   )rY   pathrN   N)r   r   rC   r   rr   BadParameterrR   r   r   rE   rF   r<   rM   rG   rH   )r   r+   rx   rN   rz   r   r   r    r!   r"   r#   r$   r%   rI   r1   rS   use_rawrJ   r,   r,   r-   devices_export_  s0   


r~   )r   r   r   r   r   r   r   r   r    r   r!   r   r"   r   r#   r   r$   r   r%   r   r&   r'   )r   r   r+   rM   r   r   rN   r   r   r   r   r   r    r   r!   r   r"   r   r#   r   r$   r   r%   r   r&   r'   )r   r   r+   rM   rV   rM   r   r   r   r   r    r   r!   r   r"   r   r#   r   r$   r   r%   r   r&   r'   )r   r   r+   rM   r]   rM   rV   rM   r^   r   r   r   r   r   r    r   r!   r   r"   r   r#   r   r$   r   r%   r   r&   r'   )r   r   r+   rM   rd   rM   r]   rM   re   rM   r   r   r   r   r    r   r!   r   r"   r   r#   r   r$   r   r%   r   r&   r'   )r   r   r+   rM   r]   rM   ro   r   r   r   r   r   r    r   r!   r   r"   r   r#   r   r$   r   r%   r   r&   r'   )r   r   r+   rM   rx   r   rN   ry   rz   r   r   r   r   r   r    r   r!   r   r"   r   r#   r   r$   r   r%   r   r&   r'   ),__doc__
__future__r   pathlibr   rr   pyicloud.cli.contextr   r   r   pyicloud.cli.normalizer   r   pyicloud.cli.optionsr	   r
   r   r   r   r   r   r   r   r   r   pyicloud.cli.outputr   r   r   r   TyperapprD   DEVICE_ID_HELPcommandOptionrK   ArgumentrT   r\   rb   rm   ru   r~   r,   r,   r,   r-   <module>   s    4;7
)
243