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

Classes

class  _CollectionLifeCycle
 
class  CollectionChange
 
class  CollectionEntity
 
class  CollectionError
 
class  DictStorageCollection
 
class  DictStorageCollectionWebsocket
 
class  IDLessCollection
 
class  IDManager
 
class  ItemNotFound
 
class  ObservableCollection
 
class  SerializedStorageCollection
 
class  StorageCollection
 
class  StorageCollectionWebsocket
 
class  YamlCollection
 

Functions

None __init__ (self, _StorageCollectionT storage_collection, str api_prefix, str model_name, VolDictType create_schema, VolDictType update_schema)
 
None __init__ (self, Store[_StoreT] store, IDManager|None id_manager=None)
 
_StoreT|None _async_load_data (self)
 
None _async_schedule_save (self)
 
SerializedStorageCollection _base_data_to_save (self)
 
_ItemT _create_item (self, str item_id, dict data)
 
_StoreT _data_to_save (self)
 
_ItemT _deserialize_item (self, dict data)
 
str _get_suggested_id (self, dict info)
 
str _hash_item (self, dict item)
 
dict _process_create_data (self, dict data)
 
dict _serialize_item (self, str item_id, _ItemT item)
 
_ItemT _update_data (self, _ItemT item, dict update_data)
 
None _ws_subscribe (self, HomeAssistant hass, websocket_api.ActiveConnection connection, dict msg)
 
_ItemT async_create_item (self, dict data)
 
None async_delete_item (self, str item_id)
 
None async_load (self)
 
None async_setup (self, HomeAssistant hass)
 
_ItemT async_update_item (self, str item_id, dict updates)
 
CollectionEntity create_entity (type[CollectionEntity] entity_class, ConfigType config)
 
HomeAssistant hass (self)
 
str item_id_key (self)
 
None sync_entity_lifecycle (HomeAssistant hass, str domain, str platform, EntityComponent[_EntityT] entity_component, StorageCollection|YamlCollection collection, type[CollectionEntity] entity_class)
 
None ws_create_item (self, HomeAssistant hass, websocket_api.ActiveConnection connection, dict msg)
 
None ws_delete_item (self, HomeAssistant hass, websocket_api.ActiveConnection connection, dict msg)
 
None ws_list_item (self, HomeAssistant hass, websocket_api.ActiveConnection connection, dict msg)
 
None ws_update_item (self, HomeAssistant hass, websocket_api.ActiveConnection connection, dict msg)
 

Variables

 _EntityT = TypeVar("_EntityT", bound=Entity, default=Entity)
 
 _GROUP_BY_KEY = attrgetter("change_type")
 
 _remove_subscription
 
 api_prefix
 
string CHANGE_ADDED = "added"
 
string CHANGE_REMOVED = "removed"
 
string CHANGE_UPDATED = "updated"
 
 ChangeListener
 
 ChangeSetListener
 
 create_schema
 
 model_name
 
int SAVE_DELAY = 10
 
 storage_collection
 
int STORAGE_VERSION = 1
 
 store
 
 update_schema
 

Detailed Description

Helper to deal with YAML + storage.

Function Documentation

◆ __init__() [1/2]

None homeassistant.helpers.collection.__init__ (   self,
_StorageCollectionT  storage_collection,
str  api_prefix,
str  model_name,
VolDictType  create_schema,
VolDictType  update_schema 
)
Class to expose storage collection management over websocket.
Initialize a websocket CRUD.

Definition at line 544 of file collection.py.

◆ __init__() [2/2]

None homeassistant.helpers.collection.__init__ (   self,
Store[_StoreT]  store,
IDManager | None   id_manager = None 
)
Offer a CRUD interface on top of JSON storage.
Initialize the storage collection.

Definition at line 244 of file collection.py.

◆ _async_load_data()

_StoreT | None homeassistant.helpers.collection._async_load_data (   self)
private
Load the data.

Definition at line 265 of file collection.py.

◆ _async_schedule_save()

None homeassistant.helpers.collection._async_schedule_save (   self)
private
Schedule saving the collection.

Definition at line 372 of file collection.py.

◆ _base_data_to_save()

SerializedStorageCollection homeassistant.helpers.collection._base_data_to_save (   self)
private
Return JSON-compatible data for storing to file.

Definition at line 377 of file collection.py.

◆ _create_item()

_ItemT homeassistant.helpers.collection._create_item (   self,
str  item_id,
dict  data 
)
private
Create an item from validated config.

Definition at line 300 of file collection.py.

◆ _data_to_save()

_StoreT homeassistant.helpers.collection._data_to_save (   self)
private
Return JSON-compatible date for storing to file.

Definition at line 388 of file collection.py.

◆ _deserialize_item()

_ItemT homeassistant.helpers.collection._deserialize_item (   self,
dict  data 
)
private
Create an item from its serialized representation.

Definition at line 304 of file collection.py.

◆ _get_suggested_id()

str homeassistant.helpers.collection._get_suggested_id (   self,
dict  info 
)
private
Suggest an ID based on the config.

Definition at line 292 of file collection.py.

◆ _hash_item()

str homeassistant.helpers.collection._hash_item (   self,
dict  item 
)
private
Return a hash of the item.

Definition at line 391 of file collection.py.

◆ _process_create_data()

dict homeassistant.helpers.collection._process_create_data (   self,
dict  data 
)
private
Validate the config is valid.

Definition at line 287 of file collection.py.

◆ _serialize_item()

dict homeassistant.helpers.collection._serialize_item (   self,
str  item_id,
_ItemT  item 
)
private
Return the serialized representation of an item for storing.

The serialized representation must include the item_id in the "id" key.

Definition at line 308 of file collection.py.

◆ _update_data()

_ItemT homeassistant.helpers.collection._update_data (   self,
_ItemT  item,
dict  update_data 
)
private
Return a new updated item.

Definition at line 296 of file collection.py.

◆ _ws_subscribe()

None homeassistant.helpers.collection._ws_subscribe (   self,
HomeAssistant  hass,
websocket_api.ActiveConnection  connection,
dict   msg 
)
private
Subscribe to collection updates.

Definition at line 660 of file collection.py.

◆ async_create_item()

_ItemT homeassistant.helpers.collection.async_create_item (   self,
dict  data 
)
Create a new item.

Definition at line 314 of file collection.py.

◆ async_delete_item()

None homeassistant.helpers.collection.async_delete_item (   self,
str  item_id 
)
Delete item.

Definition at line 361 of file collection.py.

◆ async_load()

None homeassistant.helpers.collection.async_load (   self)
Load the storage Manager.

Definition at line 269 of file collection.py.

◆ async_setup()

None homeassistant.helpers.collection.async_setup (   self,
HomeAssistant  hass 
)
Set up the websocket commands.

Definition at line 570 of file collection.py.

◆ async_update_item()

_ItemT homeassistant.helpers.collection.async_update_item (   self,
str  item_id,
dict  updates 
)
Update item.

Definition at line 333 of file collection.py.

◆ create_entity()

CollectionEntity homeassistant.helpers.collection.create_entity ( type[CollectionEntity entity_class,
ConfigType   config 
)
static
Create a CollectionEntity instance.

Definition at line 254 of file collection.py.

◆ hass()

HomeAssistant homeassistant.helpers.collection.hass (   self)
Home Assistant object.

Definition at line 261 of file collection.py.

◆ item_id_key()

str homeassistant.helpers.collection.item_id_key (   self)
Return item ID key.

Definition at line 565 of file collection.py.

◆ sync_entity_lifecycle()

None homeassistant.helpers.collection.sync_entity_lifecycle ( HomeAssistant  hass,
str  domain,
str  platform,
EntityComponent[_EntityT entity_component,
StorageCollection | YamlCollection  collection,
type[CollectionEntity entity_class 
)
Map a collection to an entity component.

Definition at line 526 of file collection.py.

◆ ws_create_item()

None homeassistant.helpers.collection.ws_create_item (   self,
HomeAssistant  hass,
websocket_api.ActiveConnection  connection,
dict   msg 
)
Create an item.

Definition at line 640 of file collection.py.

◆ ws_delete_item()

None homeassistant.helpers.collection.ws_delete_item (   self,
HomeAssistant  hass,
websocket_api.ActiveConnection  connection,
dict   msg 
)
Delete an item.

Definition at line 736 of file collection.py.

◆ ws_list_item()

None homeassistant.helpers.collection.ws_list_item (   self,
HomeAssistant  hass,
websocket_api.ActiveConnection  connection,
dict   msg 
)
List items.

Definition at line 634 of file collection.py.

◆ ws_update_item()

None homeassistant.helpers.collection.ws_update_item (   self,
HomeAssistant  hass,
websocket_api.ActiveConnection  connection,
dict   msg 
)
Update an item.

Definition at line 709 of file collection.py.

Variable Documentation

◆ _EntityT

homeassistant.helpers.collection._EntityT = TypeVar("_EntityT", bound=Entity, default=Entity)
private

Definition at line 40 of file collection.py.

◆ _GROUP_BY_KEY

homeassistant.helpers.collection._GROUP_BY_KEY = attrgetter("change_type")
private

Definition at line 447 of file collection.py.

◆ _remove_subscription

homeassistant.helpers.collection._remove_subscription
private

Definition at line 680 of file collection.py.

◆ api_prefix

homeassistant.helpers.collection.api_prefix

Definition at line 554 of file collection.py.

◆ CHANGE_ADDED

string homeassistant.helpers.collection.CHANGE_ADDED = "added"

Definition at line 36 of file collection.py.

◆ CHANGE_REMOVED

string homeassistant.helpers.collection.CHANGE_REMOVED = "removed"

Definition at line 38 of file collection.py.

◆ CHANGE_UPDATED

string homeassistant.helpers.collection.CHANGE_UPDATED = "updated"

Definition at line 37 of file collection.py.

◆ ChangeListener

homeassistant.helpers.collection.ChangeListener

Definition at line 58 of file collection.py.

◆ ChangeSetListener

homeassistant.helpers.collection.ChangeSetListener

Definition at line 70 of file collection.py.

◆ create_schema

homeassistant.helpers.collection.create_schema

Definition at line 556 of file collection.py.

◆ model_name

homeassistant.helpers.collection.model_name

Definition at line 555 of file collection.py.

◆ SAVE_DELAY

int homeassistant.helpers.collection.SAVE_DELAY = 10

Definition at line 34 of file collection.py.

◆ storage_collection

homeassistant.helpers.collection.storage_collection

Definition at line 553 of file collection.py.

◆ STORAGE_VERSION

int homeassistant.helpers.collection.STORAGE_VERSION = 1

Definition at line 33 of file collection.py.

◆ store

homeassistant.helpers.collection.store

Definition at line 251 of file collection.py.

◆ update_schema

homeassistant.helpers.collection.update_schema

Definition at line 557 of file collection.py.