
    g                     D   S r SSKJr  SSKrSSKJr  SSKJr  SSKJ	r	J
r
JrJr  SSKJr  SSKJr  SS	KJrJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKr SSK!J"r"  SSK#J$r$J%r%J&r&J'r'  SSK(J)r)J*r*J+r+J,r,  SSK-J.r.  \(       a  SSKJ/r/   " S S\\%S9r0 " S S\5      r1g)zAdds config flow for HACS.    )annotationsN)suppress)TYPE_CHECKING)GitHubDeviceAPIGitHubExceptionGitHubLoginDeviceModelGitHubLoginOauthModel)OAUTH_USER_LOGIN)AwesomeVersion)
ConfigFlowOptionsFlow)__version__)callback)UnknownFlow)aiohttp_client)async_get_integration   )HacsBase)	CLIENT_IDDOMAINLOCALEMINIMUM_HA_VERSION)	APPDAEMONCOUNTRYSIDEPANEL_ICONSIDEPANEL_TITLE)LOGGER)HomeAssistantc                      \ rS rSr% SrSrS\S'   SrS\S'   SrS	\S
'   Sr	S\S'   Sr
S\S'   SrS\S'   SS jrS rS rS rSSS jjrSS jrSS jrSS jr\\S 5       5       rSrg)HacsFlowHandler'   zConfig flow for HACS.r   r   hassNzasyncio.Task | Noneactivation_taskzGitHubDeviceAPI | NonedevicezGitHubLoginDeviceModel | None_registrationzGitHubLoginOauthModel | None_activationFbool_reauthc                     0 U l         0 U l        g)zInitialize.N)_errors_user_inputselfs    -/config/custom_components/hacs/config_flow.py__init__HacsFlowHandler.__init__4   s        c                2  #    0 U l         U R                  5       (       a  U R                  SS9$ U R                  R                  R                  [        5      (       a  U R                  SS9$ U(       a  U Vs/ s H'  o"R                  S5      (       d  M  X   (       a  M%  UPM)     sn(       a(  SU R                   S'   U R                  U5      I Sh  vN $ Xl	        U R                  U5      I Sh  vN $ U R                  U5      I Sh  vN $ s  snf  NA N$ N7f)&Handle a flow initialized by the user.single_instance_allowedreasonacc_accbaseN)r*   _async_current_entriesasync_abortr"   datagetr   
startswith_show_config_formr+   async_step_device)r-   
user_inputxs      r.   async_step_userHacsFlowHandler.async_step_user9   s     &&((##+D#EE99>>f%%##+D#EE%T:af)=jm:T',V$!33J???)//
;;; ++J777 U? < 8sN   A4D6DDD$+DDD.D/DD
DDDc                  ^ #    SU 4S jjnT R                   (       d  [        T R                  [        5      I Sh  vN n[	        S[
        [        R                  " T R                  5      S.SSUR                   30D6T l          T R                   R                  5       I Sh  vN nUR                  T l        T R                   c%  T R                  R#                  U" 5       5      T l        T R                   R%                  5       (       aQ  T R                   R                  5       =nb%  [        R                  " U5        T R'                  SS9$ T R'                  S	S9$ S
S[(        T R                  R*                  S.T R                   S.nT R,                  " S0 UD6$  GN] N! [         a/  n[        R                  " U5        T R                  SS9s SnA$ SnAff = f7f)zHandle device steps.c                    >#     TR                   R                  TR                  R                  S9I S h  vN n U R                  Tl        U4S jng  N! U4S jnf = f7f)N)device_codec                    >#    [        [        5         T R                  R                  R                  R                  T R                  S9I S h  vN   S S S 5        g  N! , (       d  f       g = f7f)N)flow_id)r   r   r"   config_entriesflowasync_configurerI   r,   s   r.   	_progressRHacsFlowHandler.async_step_device.<locals>._wait_for_activation.<locals>._progressV   sO     !+."ii66;;KKTXT`T`Kaaa /.a /.s.   A/;AAA	A/A
A,(A/)r$   
activationr%   rG   r<   r&   )responserM   r-   s     r.   _wait_for_activation?HacsFlowHandler.async_step_device.<locals>._wait_for_activationP   sQ     b!%!7!7DDVDVDbDb!7!cc#+== b	 dbs,   A0A AA AA AAN)	client_idsessionclient_namezHACS/could_not_registerr5   )next_step_iddevice_doner$   wait_for_device)urlcode)step_idprogress_actiondescription_placeholdersprogress_taskreturnNone )r$   r   r"   r   r   r   r   async_get_clientsessionversionregisterr<   r%   r   r   	exceptionr;   r#   async_create_taskdoneasync_show_progress_doner
   	user_codeasync_show_progress)r-   r+   rQ   integrationrP   rg   show_progress_kwargss   `      r.   r@   !HacsFlowHandler.async_step_deviceM   s    	b {{ 5dii HHK) #&>>tyyI !E+*=*=)>"?@DK
E!%!5!5!77%-]]"
 '#'99#>#>?S?U#VD $$&&!11;;==	J  +44BV4WW00m0LL  0'**44) "11 
 ''?*>??? I 8" E  +''/C'DDEsS   7GFAGF !F"F 7C!GF 
G&$G
GGGGc                  #    U(       d  0 n[        [        5      [        :  a  U R                  SS[        0S9$ U R	                  S[
        R                  " [
        R                  " SUR                  SS5      S9[        [
        R                  " SUR                  SS5      S9[        [
        R                  " S	UR                  S	S5      S9[        [
        R                  " S
UR                  S
S5      S9[        05      U R                  S9$ 7f)z2Show the configuration form to edit location data.min_ha_versionre   )r6   r^   useracc_logsFdefault
acc_addonsacc_untestedacc_disable)r\   data_schemaerrors)r   	HAVERSIONr   r;   async_show_formvolSchemaRequiredr=   r'   r*   r-   rA   s     r.   r?   !HacsFlowHandler._show_config_form|   s      J)$'99##'*35G)H $   ##

LLZ^^JPU5VWY]LLz~~lTY7Z[]aLL&
~u0ULL
}V[8\]_c	 << $ 
 	
s   D
Dc                  #    U R                   (       a  U R                  R                  R                  U R                  S   5      nU R                  R                  R                  U0 UR                  ESU R                  R                  0ES9  U R                  R                  R                  UR                  5      I Sh  vN   U R                  SS9$ U R                  SSU R                  R                  0SS	0S
9$  N<7f)zHandle device stepsentry_idtoken)r<   Nreauth_successfulr5    experimentalT)titler<   options)r(   r"   rJ   async_get_entrycontextasync_update_entryr<   r&   access_tokenasync_reloadr   r;   async_create_entry)r-   rA   existing_entrys      r.   async_step_device_done&HacsFlowHandler.async_step_device_done   s     <<!YY55EEdllS]F^_NII$$77%d(;(;%dWdFVFVFcFc%d 8  ))**778O8OPPP##+>#??&&))66  ' 
 	
 Qs   B>C? C==C?c                (   #    U R                  SS9$ 7f)z<Handle issues that need transition await from progress step.rV   r5   )r;   r-   r+   s     r.   async_step_could_not_register-HacsFlowHandler.async_step_could_not_register   s     ';<<s   c                >   #    U R                  5       I Sh  vN $  N7f)z0Perform reauth upon an API authentication error.N)async_step_reauth_confirmr   s     r.   async_step_reauth!HacsFlowHandler.async_step_reauth   s     335555   c                   #    Uc$  U R                  S[        R                  " 0 5      S9$ SU l        U R	                  S5      I Sh  vN $  N7f)z5Dialog that informs the user that reauth is required.Nreauth_confirmr\   ry   T)r|   r}   r~   r(   r@   r   s     r.   r   )HacsFlowHandler.async_step_reauth_confirm   sQ     ''(JJrN (   ++D1111s   AAA
Ac                    [        U 5      $ N)HacsOptionsFlowHandlerconfig_entrys    r.   async_get_options_flow&HacsFlowHandler.async_get_options_flow   s     &l33r1   )r&   r*   r(   r%   r+   r#   r$   r`   r   )rA   zdict[str, bool] | None)__name__
__module____qualname____firstlineno____doc__VERSION__annotations__r#   r$   r%   r&   r(   r/   rC   r@   r?   r   r   r   r   staticmethodr   r   __static_attributes__rc   r1   r.   r    r    '   s    G
+/O(/%)F")37M0704K-4GT
8(-@^
4
(=62 4  4r1   r    )domainc                  2    \ rS rSrSrS rSS jrSS jrSrg)	r      z!HACS config flow options handler.c                8    [        [        5      S:  a  Xl        gg)zInitialize HACS options flow.z
2024.11.99N)r   r{   r   )r-   r   s     r.   r/   HacsOptionsFlowHandler.__init__   s    )$|3 , 4r1   Nc                >   #    U R                  5       I Sh  vN $  N7f)zManage the options.N)rC   r   s     r.   async_step_init&HacsOptionsFlowHandler.async_step_init   s     ))++++r   c                  #    U R                   R                  R                  [        5      nUb  U R	                  S0 UESS0ES9$ Ub  UR
                  c  U R                  SS9$ UR                  R                  (       a  U R                  SS9$ [        R                  " [        UR
                  R                  S9[        [        R                  " [        UR
                  R                  S9[        [        R                  " [         UR
                  R"                  S9[        R$                  " [&        5      [        R                  " [(        UR
                  R*                  S9[,        0nU R/                  S	[        R0                  " U5      S
9$ 7f)r3   r   r   T)r   r<   	not_setupr5   pending_tasksrt   rr   r   )r"   r<   r=   r   r   configurationr;   queuehas_pending_tasksr}   Optionalr   sidepanel_titlestrr   sidepanel_iconr   countryInr   r   	appdaemonr'   r|   r~   )r-   rA   hacsschemas       r.   rC   &HacsOptionsFlowHandler.async_step_user   s0    ++F3!**:^Z:^Y]:^*__<4--5##;#77::''##?#;; LL$2D2D2T2TUWZLL1C1C1R1RSUXLL$*<*<*D*DEsvvf~LLD,>,>,H,HI4	
 ##F

6@R#SSs   F
Fr   r   )	r   r   r   r   r   r/   r   rC   r   rc   r1   r.   r   r      s    +-
,Tr1   r   )2r   
__future__r   asyncio
contextlibr   typingr   aiogithubapir   r   r   r	   aiogithubapi.common.constr
   awesomeversionr   homeassistant.config_entriesr   r   homeassistant.constr   r{   homeassistant.corer   homeassistant.data_entry_flowr   homeassistant.helpersr   homeassistant.loaderr   
voluptuousr}   r9   r   constr   r   r   r   utils.configuration_schemar   r   r   r   utils.loggerr   r   r    r   rc   r1   r.   <module>r      sx      "      7 ) @ 8 ' 5 0 6   @ @  !0X4j X4vT[ Tr1   