
    g
                         S 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  \r " S
 S\5      rS rS rS rS rS rS rg)zStorage handers.    )JSONEncoder)Store)json   )VERSION_STORAGE)HacsException   )LOGGERc                       \ rS rSrSrS rSrg)	HACSStore   z?A subclass of Store that allows multiple loads in the executor.c                      [         R                  " U R                  5      nU0 :X  d  US   U R                  :w  a  gUS   $ ! [         a2  n[        R                  SU R                  U5        [        U5      UeSnAff = f)z+Load the data from disk if version matches.zDCould not load '%s', restore it from a backup or delete the file: %sNversiondata)	json_util	load_jsonpathBaseException_LOGGERcriticalr   r   )selfr   	exceptions      -/config/custom_components/hacs/utils/store.pyloadHACSStore.load   s~    
	:&&tyy1D 2:iDLL8F| 	: V		
  	*	9	:s    A 
A=-A88A= N)__name__
__module____qualname____firstlineno____doc__r   __static_attributes__r       r   r   r      s
    Ir#   r   c                     SU ;   a  U $ SU  3$ )zAReturn the key to use with homeassistant.helpers.storage.Storage./zhacs.r   )keys    r   get_store_keyr'   #   s    *3/E#-/r#   c                 6    [        U [        [        U5      USS9$ )"Create a Store object for the key.T)encoderatomic_writes)r   r   r'   )hassr&   r*   s      r   _get_store_for_keyr-   (   s    T?M#,>_cddr#   c                 "    [        X[        5      $ )r)   )r-   r   r,   r&   s     r   get_store_for_keyr0   -   s    d55r#   c                 b   #    [        X5      R                  5       I Sh  vN =(       d    0 $  N7f)z@Load the retained data from store and return de-serialized data.N)r0   
async_loadr/   s     r   async_load_from_storer3   2   s$     "4-88::@b@:s   /-/c                    #    [        X5      I Sh  vN nUb  X2:w  a#  [        X5      R                  U5      I Sh  vN   g[        R	                  S[        U5      5        g NO N'7f)a0  Generate dynamic data to store and save it to the filesystem.

The data is only written if the content on the disk has changed
by reading the existing content and comparing it.

If the data has changed this will generate two executor jobs

If the data has not changed this will generate one executor job
NzS<HACSStore async_save_to_store> Did not store data for '%s'. Content did not change)r3   r0   
async_saver   debugr'   )r,   r&   r   currents       r   async_save_to_storer8   7   sX      *$44G'/*55d;;;MM]c	 5;s   A%A!)A%A#&A%#A%c                 `   #    SU;  a  g[        X5      R                  5       I Sh  vN   g N7f)z5Remove a store element that should no longer be used.r%   N)r0   async_remover/   s     r   async_remove_storer;   K   s&     
#~
D
&
3
3
555s   $.,.N)r!   homeassistant.helpers.jsonr   homeassistant.helpers.storager   homeassistant.utilr   r   constr   
exceptionsr   loggerr
   r   r   r'   r-   r0   r3   r8   r;   r   r#   r   <module>rB      sK     2 / 0 # & 
 *0
e
6
A
(6r#   