
    g!                        S r SSKJr  SSKJrJr  SSKJrJ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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  \(       a  SSKJr   " S S\5      r g)zClass for integrations in HACS.    )annotations)TYPE_CHECKINGAny)IssueSeverityasync_create_issue)async_get_custom_components   )DOMAIN)HacsCategoryHacsDispatchEventHacsGitHubRepoRepositoryFile)AddonRepositoryExceptionHacsException)decode_content)
concurrent) get_first_directory_in_directory)
json_loads   )HacsRepository)HacsBasec                     ^  \ rS rSrSrSU 4S jjr\S 5       rS rSS jr	S r
\" SS	S
9SS j5       rS rSSS jjrSS jrSrU =r$ )HacsIntegrationRepository   zIntegrations in HACS.c                <  > [         TU ]  US9  X R                  l        UR	                  5       U R                  l        [        R                  U R                  l        SU R                  R                  l        U R                  U R                  R                  l        g)zInitialize.)hacscustom_componentsN)super__init__data	full_namelowerfull_name_lowerr   INTEGRATIONcategorycontentpathremote	localpathlocal)selfr   r!   	__class__s      :/config/custom_components/hacs/repositories/integration.pyr   "HacsIntegrationRepository.__init__   sj    d#'		$-OO$5		!)55		#6 "&..    c                t    U R                   R                  R                   SU R                  R                   3$ )zReturn localpath.z/custom_components/)r   coreconfig_pathr    domainr+   s    r-   r)   #HacsIntegrationRepository.localpath#   s0     ))..,,--@AQAQ@RSSr/   c                  #    SU l         U R                  R                  (       ab  U R                  R                  [        R
                  :w  a  U R                  5       I Sh  vN   U R                  R                  (       a  SU l         U R                   (       a  U R                  R                  SU R                  5        [        U R                  R                  [        SU R                  R                   SU R                    3SU R                  R"                  =(       d    [        [$        R&                  SSU R(                  0S	9  gg N7f)
zRun post installation steps.TNFz"%s Creating restart_required issuerestart_required__restart_requiredname)hassr3   issue_id
is_fixableissue_domainseveritytranslation_keytranslation_placeholders)pending_restartr    config_flowr!   r   r$   reload_custom_componentsfirst_installloggerdebugstringr   r   r;   r
   idrefr3   r   WARNINGdisplay_namer4   s    r-   async_post_installation1HacsIntegrationRepository.async_post_installation(   s     #99  yy""n&@&@@33555yy&&',$KKBDKKPYY^^,TYY\\N!DHH:F!YY--7&.. 2D--*  	 6s   AE	 E!C'E	c                   #    U R                   R                  (       a  U R                  5       I Sh  vN   gSU l        g N7f)zRun post uninstall steps.NT)r    rC   rD   rB   r4   s    r-   async_post_uninstall.HacsIntegrationRepository.async_post_uninstall@   s1     99  //111#'D  2s   /A?Ac                  #    U R                  5       I Sh  vN   U R                  R                  (       a  SU R                  R                  l        U R                  R                  R
                  S:X  a  [        U R                  S5      nUco  SU R                  ;   d   SU R                  ;   d  SU R                  ;   a
  [        5       e[        U R                   SU R                  R                  SS5       S	35      eS
U 3U R                  R                  l        U R                  5       I Sh  vN =n(       a}   X l        UR!                  S/ 5      U R"                  l        US   U R"                  l        UR!                  S5      U R"                  l        UR!                  SS5      U R"                  l        U R>                  U R                  R                  l         U R.                  R0                  (       ak  U R.                  R0                   HQ  nU R8                  RB                  RD                  (       a  M*  U RF                  R=                  SU R                  U5        MS     U R.                  RH                  $  GNb GNM! [,         ay  nU R.                  R0                  R3                  SU S[4        R6                   35        U R8                  R:                  R=                  SU[4        R6                  5         SnAGNESnAff = f7f)z	Validate.N r   zrepository.jsonzrepository.yamlzrepository.ymlz Repository structure for ztags/z is not compliantcustom_components/
codeownersr3   r:   rC   FMissing expected key '' in !Missing expected key '%s' in '%s'z%s %s)%common_validaterepository_manifestcontent_in_rootr&   r'   r(   r   tree	treefilesr   r   rH   rJ   replaceasync_get_integration_manifestintegration_manifestgetr    authorsr3   manifest_namerC   KeyErrorvalidateerrorsappendr   MAINIFEST_JSONr   logerrorr)   r*   statusstartuprF   success)r+   r:   manifest	exceptionrj   s        r-   validate_repository-HacsIntegrationRepository.validate_repositoryG   s\    ""$$$ ##33')DLL$<<##'::3DII?RSD|%7(DNN:'4>>9244#{{m#=(("5>76GI  *<D6'BDLL$ "@@BBB8B,4)$,LLr$B		!#+H#5		 *2,,v*>		'(0]E(J		% #'.. ==--yy''///KK%%gt{{EB . }}$$$_ 	%, C  $$++,YKu&55=7 8 		##7NDaDa sV   LI8DL.I;/L;A<I> 7A<L7AL;L>
LA.K<6L<LL
      )concurrenttasksbackoff_timec                  #    U R                  X5      I Sh  vN (       d  U(       d  gU R                  R                  (       a  SU R                  R                  l        U R                  R                  R
                  S:X  a4  [        U R                  S5      nSU 3U R                  R                  l        U R                  5       I Sh  vN =n(       a}   X@l	        UR                  S/ 5      U R                  l        US   U R                  l        UR                  S5      U R                  l        UR                  SS	5      U R                  l        U R2                  U R                  R                  l        U R                  R6                  (       aX  U R,                  R9                  [:        R<                  SSU R                  R>                  U R                  R@                  S.5        gg GN GN%! [          ay  nU R"                  R$                  R'                  S
U S[(        R*                   35        U R,                  R.                  R1                  SU[(        R*                  5         SnAGNSnAff = f7f)zUpdate.NrS   r   rT   rU   r3   r:   rC   FrV   rW   rX   i9  update)rI   action
repositoryrepository_id)!common_updaterZ   r[   r&   r'   r(   r   r\   r_   r`   ra   r    rb   r3   rc   rC   rd   re   rf   rg   r   rh   r   ri   rj   r)   r*   	installedasync_dispatchr   
REPOSITORYr!   rI   )r+   ignore_issuesforcer:   rn   ro   s         r-   update_repository+HacsIntegrationRepository.update_repositoryz   s     ''===e##33')DLL$<<##'::3DII?RSD);D6'BDLL$ "@@BBB8B,4)$,LLr$B		!#+H#5		 *2,,v*>		'(0]E(J		% #'.. 99II$$!,,&"&))"5"5%)YY\\	 A > C  $$++,YKu&55=7 8 		##7NDaDa sO   I8G,B2I8
G/I8A<G2 BI8/I82
I5<A.I0*I80I55I8c                  #    U R                   R                  S5        U R                  R                  R                  S	 [        U R                  R                  5      I Sh  vN   U R                   R                  S5        g N 7f)z1Reload custom_components (and config flows)in HA.z Reloading custom_component cacher   NzCustom_component cache reloaded)rF   infor   r;   r    r   r4   s    r-   rD   2HacsIntegrationRepository.reload_custom_components   s]     ;<IINN 34)$))..999:; 	:s   AB!B"!Bc                  #    U R                   R                  (       a  SO2U R                  R                  R                   S[
        R                   3nUS U R                   5       ;  a   [        S[
        R                   SU S35      eU R                  R                  " SU R                  R                  R                  R                  R                  U R                  R                   US.SS	U=(       d    U R#                  5       00D6I S
h  vN nU(       a(  [%        ['        UR                  R                  5      5      $ g
 N47f)*Get the content of the manifest.json file.manifest.json/c              3  8   #    U  H  oR                   v   M     g 7fN	full_path.0xs     r-   	<genexpr>KHacsIntegrationRepository.async_get_integration_manifest.<locals>.<genexpr>         @ii   No  file found '')methodry   r'   paramsrJ   N )rZ   r[   r&   r'   r(   r   rh   r\   r   r   async_github_api_method	githubapireposcontentsra   r    r!   version_to_downloadr   r   )r+   rJ   manifest_pathresponses       r-   r_   8HacsIntegrationRepository.async_get_integration_manifest   s     ''77 LL%%,,-Q~/L/L.MN 	  @dii @@#n&C&C%DMR_Q``a bcc:: 
99&&,,5599yy**
 %!B(@(@(BCD	
 
 nX]]-B-BCDD 
s   DEE5Ec               (  #    U R                   R                  (       a  SO2U R                  R                  R                   S[
        R                   3nUS U R                   5       ;  a   [        S[
        R                   SU S35      eU R                  R                  SU R                  U5         U R                  R                  SU R                  R                   SU SU 3S	S
9I Sh  vN nUc  g[!        U5      $  N! ["         a     gf = f7f)r   r   r   c              3  8   #    U  H  oR                   v   M     g 7fr   r   r   s     r-   r   EHacsIntegrationRepository.get_integration_manifest.<locals>.<genexpr>   r   r   r   r   r   z'%s Getting manifest.json for version=%sz"https://raw.githubusercontent.com/T)nologN)rZ   r[   r&   r'   r(   r   rh   r\   r   rF   rG   rH   r   async_download_filer    r!   r   	Exception)r+   versionkwargsr   results        r-   get_integration_manifest2HacsIntegrationRepository.get_integration_manifest   s     ''77 LL%%,,-Q~/L/L.MN 	  @dii @@#n&C&C%DMR_Q``a bccCT[[RYZ
	99884II''5)()'!M?D 9  F
 ~f%%  		sH   B/D2:D ,D -D 4D5
D ?D D 
DDDD)r`   rB   )r   r   r!   str)returnNone)FFr   )rJ   r   r   dict[str, Any] | None)r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   propertyr)   rM   rP   rp   r   r   rD   r_   r   __static_attributes____classcell__)r,   s   @r-   r   r      sb    1 T T0(1%f 3+ 4+Z<E( r/   r   N)!r   
__future__r   typingr   r   $homeassistant.helpers.issue_registryr   r   homeassistant.loaderr   constr
   enumsr   r   r   r   
exceptionsr   r   utils.decoder   utils.decoratorr   utils.filtersr   
utils.jsonr   baser   r   r   r   r/   r-   <module>r      sC    % " % R <  S S @ ) ( < #  B Br/   