
    g                        S 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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JrJr  S	SKJr          SS jr " S S\\5      rg)zUpdate entities for HACS.    )annotations)Any)UpdateEntityUpdateEntityFeature)ConfigEntry)HomeAssistantHomeAssistantErrorcallback)async_dispatcher_connect)AddEntitiesCallback   )HacsBase)DOMAIN)HacsRepositoryEntity)HacsCategoryHacsDispatchEvent)HacsExceptionc                   ^#    U R                   [           mU" U4S jTR                  R                   5       5        g7f)zSetup update platform.c              3  8   >#    U  H  n[        TUS 9v   M     g7f))hacs
repositoryN)HacsRepositoryUpdateEntity).0r   r   s     (/config/custom_components/hacs/update.py	<genexpr>$async_setup_entry.<locals>.<genexpr>   s      ;J 	#D;s   N)datar   repositorieslist_downloaded)hassentryasync_add_entitiesr   s      @r   async_setup_entryr#      s7      YYv&D ++;; s   ;>c                  J  ^  \ rS rSrSr\R                  \R                  -  \R                  -  \R                  -  r
\SS j5       r\SS j5       r\SS j5       r\SS j5       r\SS j5       r\SS j5       rSS	 jrSS
 jrSU 4S jjr\SS j5       r\SS j5       rSrU =r$ )r      z6Update entities for repositories downloaded with HACS.c                4    U R                   R                   S3$ )zReturn the name.z update)r   display_nameselfs    r   nameHacsRepositoryUpdateEntity.name)   s     //../w77    c                .    U R                   R                  $ )z$Return latest version of the entity.)r   display_available_versionr(   s    r   latest_version)HacsRepositoryUpdateEntity.latest_version.        888r,   c                    U R                   R                  S:X  a#  SU R                   R                  R                   3$ SU R                   R                  R                   SU R                   3$ )z#Return the URL of the release page.commitzhttps://github.com/z
/releases/)r   display_version_or_commitr   	full_namer/   r(   s    r   release_url&HacsRepositoryUpdateEntity.release_url3   s_     ??44@()=)=)G)G(HII$T__%9%9%C%C$DJtObObNcddr,   c                .    U R                   R                  $ )z(Return downloaded version of the entity.)r   display_installed_versionr(   s    r   installed_version,HacsRepositoryUpdateEntity.installed_version:   r1   r,   c                <    U R                   R                  (       a  gg)zReturn the release summary.zJ<ha-alert alert-type='error'>Restart of Home Assistant required</ha-alert>N)r   pending_restartr(   s    r   release_summary*HacsRepositoryUpdateEntity.release_summary?   s     ??**_r,   c                    U R                   R                  R                  [        R                  :w  d!  U R                   R                  R
                  c  gSU R                   R                  R
                   S3$ )z1Return the entity picture to use in the frontend.Nz#https://brands.home-assistant.io/_/z	/icon.png)r   r   categoryr   INTEGRATIONdomainr(   s    r   entity_picture)HacsRepositoryUpdateEntity.entity_pictureF   s\     OO  ))\-E-EE##**24T__5I5I5P5P4QQZ[[r,   c                r  #    U=(       d    U R                   nX@R                  :X  a:  [        SU R                   SU R                  R                  R
                   S35      e U R                  R                  U=(       d    U R                   S9I Sh  vN   g N! [         a  n[        U5      UeSnAff = f7f)zInstall an update.zVersion z of z is already downloaded)refN)r/   r:   r	   r   r   r5   async_download_repositoryr   )r)   versionbackupkwargsto_download	exceptions         r   async_install(HacsRepositoryUpdateEntity.async_installQ   s     4!4!4000$x0F0F/Gt%)__%9%9%C%CLEDZ&\ ] ]	?//;;@^4K^K^;___ 	?$Y/Y>	?s<   AB7"/B BB B7B 
B4#B//B44B7c                f  #    U R                   R                  (       a  gU R                  U R                   R                  R                  ;  Ga  U R                   R                  U R                   R                  R                  U R                  R                  R                  S9I Sh  vN nU(       a  SU R                   R                  l
        XR                   R                  l        U Vs/ s H  o"R                  PM     snU R                   R                  l        [        [        U R                   R                  R                  5      5      U R                   R                  l        SnU R                   U R                   R                  R                  ;   a  U R                   R                  R                   Ht  nUR                  U R                   :X  a    OUSUR                   3-  nUR                  UR"                  :w  a  USUR"                   3-  nUSUR$                   3-  nUS-  nMv     O]['        U R                   R                  R                  5      (       a/  X0R                   R                  R                  S	   R$                  -  nU R                   R(                  (       an  U R                   R                  R*                  [,        R.                  :X  a  US
-  nU R                   R                  R*                  [,        R0                  :X  a  US-  nUR3                  SS5      $  GNs  snf 7f)zReturn the release notes.N)
prereleasereturnlimitT z# z  - z

z

---

r   zi

<ha-alert alert-type='warning'>You need to restart Home Assistant manually after updating.</ha-alert>

zk

<ha-alert alert-type='warning'>You need to manually clear the frontend cache after updating.</ha-alert>

z
#z

#)r   r=   r/   r   published_tagsget_releases	show_betar   configurationrelease_limitreleasesobjectstag_namenextiterlast_versionr:   r*   bodyanypending_updaterA   r   rB   PLUGINreplace)r)   rY   xrelease_notesreleases        r   async_release_notes.HacsRepositoryUpdateEntity.async_release_notes\   sk    ??**doo&:&:&I&II!__99??//99 II33AA :  H 04$$-3;((0KS6T8azz86T$$348doo>R>R>a>a9b4c$$1!!T__%9%9%H%HH??33;;##t'='==2g&6&6%7!88##w||3!tGLL>%::M4~!66. < ))1122__55==a@EEEM??))##,,0H0HHN ##,,0C0CCO
 $$UG44I 7Us&   B%L1'L)(AL1,L,H)L1,L1c                   >#    [         TU ]  5       I Sh  vN   U R                  [        U R                  [
        R                  U R                  5      5        g NC7f)zRegister for status events.N)superasync_added_to_hassasync_on_remover   r    r   REPOSITORY_DOWNLOAD_PROGRESS_update_download_progress)r)   	__class__s    r   rk   .HacsRepositoryUpdateEntity.async_added_to_hass   sK     g)+++$		!>>..	
 	,s   AAAAc                x    US   U R                   R                  R                  :w  a  gU R                  US   S9  g)Update the download progress.r   Nprogress)rs   )r   r   r5   _update_in_progress)r)   r   s     r   rn   4HacsRepositoryUpdateEntity._update_download_progress   s:     !5!5!?!??  $z*: ;r,   c                0    Xl         U R                  5         g)rr   N)_attr_in_progressasync_write_ha_state)r)   rs   s     r   rt   .HacsRepositoryUpdateEntity._update_in_progress   s     "*!!#r,   )rw   )return
str | None)rz   str)rI   r{   rJ   boolrK   r   rz   None)rz   r~   )r   dictrz   r~   )rs   z
int | boolrz   r~   )__name__
__module____qualname____firstlineno____doc__r   INSTALLSPECIFIC_VERSIONPROGRESSRELEASE_NOTES_attr_supported_featurespropertyr*   r/   r6   r:   r>   rD   rN   rg   rk   r
   rn   rt   __static_attributes____classcell__)ro   s   @r   r   r      s    @ 	##

.
.	/

&
&	' 
+
+	,  8 8 9 9 e e 9 9   \ \	?*5X	
 < < $ $r,   r   N)r    r   r!   r   r"   r   rz   r~   )r   
__future__r   typingr   homeassistant.components.updater   r   homeassistant.config_entriesr   homeassistant.corer   r	   r
    homeassistant.helpers.dispatcherr   %homeassistant.helpers.entity_platformr   baser   constr   entityr   enumsr   r   
exceptionsr   r#   r    r,   r   <module>r      se     "  M 4 J J E E   ( 2 %
 +AT	$!5| $r,   