Home Assistant Unofficial Reference 2024.12.1
homeassistant.helpers.storage Namespace Reference

Classes

class  _StoreManager
 
class  Store
 

Functions

None __init__ (self, HomeAssistant hass, int version, str key, bool private=False, *bool atomic_writes=False, type[JSONEncoder]|None encoder=None, int minor_version=1, bool read_only=False)
 
None _async_callback_delayed_write (self)
 
None _async_callback_final_write (self, Event _event)
 
None _async_cleanup_delay_listener (self)
 
None _async_cleanup_final_write_listener (self)
 
None _async_ensure_final_write_listener (self)
 
def _async_handle_write_data (self, *_args)
 
_T|None _async_load (self)
 
def _async_load_data (self)
 
def _async_migrate_func (self, old_major_version, old_minor_version, old_data)
 
None _async_reschedule_delayed_write (self, float when)
 
None _async_schedule_callback_delayed_write (self)
 
None _async_write_data (self, str path, dict data)
 
def _T
 
None _write_data (self, str path, dict data)
 
None async_delay_save (self, Callable[[], _T] data_func, float delay=0)
 
_T|None async_load (self)
 
None async_remove (self)
 
None async_save (self, _T data)
 
_StoreManager get_internal_store_manager (HomeAssistant hass)
 
None make_read_only (self)
 
def path (self)
 

Variables

 _atomic_writes
 
 _data
 
 _delay_handle
 
 _encoder
 
 _load_future
 
 _LOGGER = logging.getLogger(__name__)
 
 _manager
 
 _next_write_time
 
 _private
 
 _read_only
 
 _unsub_final_write_listener
 
 _write_lock
 
 hass
 
 key
 
int MANAGER_CLEANUP_DELAY = 60
 
int MAX_LOAD_CONCURRENTLY = 6
 
 minor_version
 
string STORAGE_DIR = ".storage"
 
 version
 

Detailed Description

Helper to help store data.

Function Documentation

◆ __init__()

None homeassistant.helpers.storage.__init__ (   self,
HomeAssistant  hass,
int  version,
str  key,
bool   private = False,
*bool   atomic_writes = False,
type[JSONEncoder] | None   encoder = None,
int   minor_version = 1,
bool   read_only = False 
)
Class to help storing data.
Initialize storage class.

Definition at line 234 of file storage.py.

◆ _async_callback_delayed_write()

None homeassistant.helpers.storage._async_callback_delayed_write (   self)
private
Handle a delayed write callback.

Definition at line 510 of file storage.py.

◆ _async_callback_final_write()

None homeassistant.helpers.storage._async_callback_final_write (   self,
Event  _event 
)
private
Handle a write because Home Assistant is in final write state.

Definition at line 518 of file storage.py.

◆ _async_cleanup_delay_listener()

None homeassistant.helpers.storage._async_cleanup_delay_listener (   self)
private
Clean up a delay listener.

Definition at line 504 of file storage.py.

◆ _async_cleanup_final_write_listener()

None homeassistant.helpers.storage._async_cleanup_final_write_listener (   self)
private
Clean up a stop listener.

Definition at line 497 of file storage.py.

◆ _async_ensure_final_write_listener()

None homeassistant.helpers.storage._async_ensure_final_write_listener (   self)
private
Ensure that we write if we quit before delay has passed.

Definition at line 488 of file storage.py.

◆ _async_handle_write_data()

def homeassistant.helpers.storage._async_handle_write_data (   self,
_args 
)
private
Handle writing the config.

Definition at line 523 of file storage.py.

◆ _async_load()

_T | None homeassistant.helpers.storage._async_load (   self)
private
Load the data and ensure the task is removed.

Definition at line 305 of file storage.py.

◆ _async_load_data()

def homeassistant.helpers.storage._async_load_data (   self)
private
Load the data.

Definition at line 312 of file storage.py.

◆ _async_migrate_func()

def homeassistant.helpers.storage._async_migrate_func (   self,
  old_major_version,
  old_minor_version,
  old_data 
)
private
Migrate to the new version.

Definition at line 564 of file storage.py.

◆ _async_reschedule_delayed_write()

None homeassistant.helpers.storage._async_reschedule_delayed_write (   self,
float  when 
)
private
Reschedule a delayed write.

Definition at line 468 of file storage.py.

◆ _async_schedule_callback_delayed_write()

None homeassistant.helpers.storage._async_schedule_callback_delayed_write (   self)
private
Schedule the delayed write in a task.

Definition at line 475 of file storage.py.

◆ _async_write_data()

None homeassistant.helpers.storage._async_write_data (   self,
str  path,
dict  data 
)
private

Definition at line 545 of file storage.py.

◆ _T()

def homeassistant.helpers.storage._T
private

Definition at line 54 of file storage.py.

◆ _write_data()

None homeassistant.helpers.storage._write_data (   self,
str  path,
dict  data 
)
private
Write the data.

Definition at line 548 of file storage.py.

◆ async_delay_save()

None homeassistant.helpers.storage.async_delay_save (   self,
Callable[[], _T data_func,
float   delay = 0 
)
Save data with an optional delay.

Definition at line 440 of file storage.py.

◆ async_load()

_T | None homeassistant.helpers.storage.async_load (   self)
Load data.

If the expected version and minor version do not match the given
versions, the migrate function will be invoked with
migrate_func(version, minor_version, config).

Will ensure that when a call comes in while another one is in progress,
the second call will wait and return the result of the first call.

Definition at line 275 of file storage.py.

◆ async_remove()

None homeassistant.helpers.storage.async_remove (   self)
Remove all data.

Definition at line 568 of file storage.py.

◆ async_save()

None homeassistant.helpers.storage.async_save (   self,
_T  data 
)
Save data.

Definition at line 424 of file storage.py.

◆ get_internal_store_manager()

_StoreManager homeassistant.helpers.storage.get_internal_store_manager ( HomeAssistant  hass)
Get the store manager.

This function is not part of the API and should only be
used in the Home Assistant core internals. It is not
guaranteed to be stable.

Definition at line 93 of file storage.py.

◆ make_read_only()

None homeassistant.helpers.storage.make_read_only (   self)
Make the store read-only.

This method is irreversible.

Definition at line 268 of file storage.py.

◆ path()

def homeassistant.helpers.storage.path (   self)
Return the config path.

Definition at line 264 of file storage.py.

Variable Documentation

◆ _atomic_writes

homeassistant.helpers.storage._atomic_writes
private

Definition at line 258 of file storage.py.

◆ _data

homeassistant.helpers.storage._data
private

Definition at line 426 of file storage.py.

◆ _delay_handle

homeassistant.helpers.storage._delay_handle
private

Definition at line 470 of file storage.py.

◆ _encoder

homeassistant.helpers.storage._encoder
private

Definition at line 257 of file storage.py.

◆ _load_future

homeassistant.helpers.storage._load_future
private

Definition at line 288 of file storage.py.

◆ _LOGGER

homeassistant.helpers.storage._LOGGER = logging.getLogger(__name__)
private

Definition at line 45 of file storage.py.

◆ _manager

homeassistant.helpers.storage._manager
private

Definition at line 261 of file storage.py.

◆ _next_write_time

homeassistant.helpers.storage._next_write_time
private

Definition at line 260 of file storage.py.

◆ _private

homeassistant.helpers.storage._private
private

Definition at line 251 of file storage.py.

◆ _read_only

homeassistant.helpers.storage._read_only
private

Definition at line 259 of file storage.py.

◆ _unsub_final_write_listener

homeassistant.helpers.storage._unsub_final_write_listener
private

Definition at line 491 of file storage.py.

◆ _write_lock

homeassistant.helpers.storage._write_lock
private

Definition at line 255 of file storage.py.

◆ hass

homeassistant.helpers.storage.hass

Definition at line 250 of file storage.py.

◆ key

homeassistant.helpers.storage.key

Definition at line 249 of file storage.py.

◆ MANAGER_CLEANUP_DELAY

int homeassistant.helpers.storage.MANAGER_CLEANUP_DELAY = 60

Definition at line 50 of file storage.py.

◆ MAX_LOAD_CONCURRENTLY

int homeassistant.helpers.storage.MAX_LOAD_CONCURRENTLY = 6

Definition at line 42 of file storage.py.

◆ minor_version

homeassistant.helpers.storage.minor_version

Definition at line 248 of file storage.py.

◆ STORAGE_DIR

string homeassistant.helpers.storage.STORAGE_DIR = ".storage"

Definition at line 44 of file storage.py.

◆ version

homeassistant.helpers.storage.version

Definition at line 247 of file storage.py.