
    FNj                        d Z ddlmZ ddlZddlZddlZddlmZ  ee      j                         j                  j                  dz  Zedz  Zddd	d
dZddZddZddZdddZddZddZy)uz  Where-am-I awareness — which network Ahmed is on = where he physically is.

macOS now HIDES the Wi-Fi SSID unless the app holds Location permission, so we
fingerprint the network the permission-free way: the default gateway's MAC
address (unique per router — his home router, the office, his phone hotspot are
all distinct). Each fingerprint is labelled once ("home"/"work"/"mobile") in
control/locations.json; after that Jarvis always knows where he is.

Ahmed's seed mapping (by his SSID names, which become the labels):
  Rajeh 5G      -> home   (his apartment)
  alrugaib      -> work   (the Alrugaib office)
  Nothing Phone -> mobile (phone hotspot / on the move)

Binding an unknown network: Jarvis writes control/loc_bind.json
{"place": "work", "label": "the office", "ssid": "alrugaib"} when Ahmed says
where he is; the ControlWatcher stores it against the current fingerprint.
    )annotationsN)Pathcontrolzlocations.jsonzat home, in his apartmentzat the Alrugaib officez$out and about (on his phone hotspot)u)   somewhere new — an unrecognised network)homeworkmobileunknownc                    	 d} t        j                  g dddd      j                  }t        j                  d|      }|r|j                  d      nd} | syt        j                  dd	d
dd
| gdd       t        j                  dd| gddd      j                  }t        j                  d|t        j                        }|r|j                  d      j                         S dS # t        $ r Y yw xY w)uC   The default gateway's MAC — a stable, permission-free network id.N)route-ngetdefaultT   )capture_outputtexttimeoutzgateway:\s*([0-9.]+)   pingz-c1z-t   )r   r   arpr   z$([0-9a-f]{1,2}(?::[0-9a-f]{1,2}){5}))	
subprocessrunstdoutresearchgroupIlower	Exception)gwoutmr   s       </Users/ahmed/devFolder/Ultron/claude-voice/voice/location.py_gateway_macr%   %   s    nn>,0tQHHN 	II-s3QWWQZ$c4b9&*A	7nneT2.t"&3396 	II=sBDDI%&qwwqz!0D0 s   AC# B	C# !C# #	C/.C/c                 t    	 t        j                  t        j                               S # t        $ r i cY S w xY w)N)jsonloads_STORE	read_textr         r$   _loadr-   9   s3    zz&**,-- 	s   &) 77c                    	 t         j                  d       t        j                  t	        j
                  | d             y # t        $ r Y y w xY w)NT)exist_okr   )indent)_CONTROLmkdirr)   
write_textr'   dumpsr    )ds    r$   _saver6   @   s@    %$**Qq12 s   A A 	AAc                    t               }|syt               }| |xs t        j                  | |       |d||<   t	        |       |S )zDLabel the CURRENT network as a place. Returns the fingerprint bound.Nplacelabelssid)r%   r-   PLACESr   r6   )r9   r:   r;   fpr5   s        r$   bindr>   H   sE    	BAe&Gvzz%/GAbE	!HIr,   c                     t               } | sdddddS t               j                  |       }|r	i || ddS dt        d   d| dd	S )
zCWhere Ahmed is right now: {place, label, ssid, fingerprint, known}.r	   zoffline or wiredFN)r9   r:   knownfingerprintT)rA   r@    )r9   r:   r;   rA   r@   )r%   r-   r   r<   )r=   hits     r$   currentrD   T   s`    	B"-?t5 	5
'++b/C
8#8b488	):B/ /r,   c                 V    t               ryt               } | rt        | ddddi       yy)zFirst run: assume the current network is home (Ahmed's 'Rajeh 5G'), so
    location works out of the box; work/mobile get bound when he's there.Nr   zhis apartmentzRajeh 5Gr8   )r-   r%   r6   )r=   s    r$   seed_if_emptyrF   a   s6     w	B	rVo&( ) 	* 
r,   )return
str | None)rG   dict)r5   rI   rG   None)rB   rB   )r9   strr:   rK   r;   rK   rG   rH   )rG   rJ   )__doc__
__future__r   r'   r   r   pathlibr   __file__resolveparentr1   r)   r<   r%   r-   r6   r>   rD   rF   r+   r,   r$   <module>rR      s|   " #  	  >!!#**11I=	$	$ ($4:	
(	
/*r,   