Home Assistant Unofficial Reference 2024.12.1
homeassistant.core.StateMachine Class Reference

Public Member Functions

None __init__ (self, EventBus bus, asyncio.events.AbstractEventLoop loop)
 
list[Stateall (self, str|Iterable[str]|None domain_filter=None)
 
list[Stateasync_all (self, str|Iterable[str]|None domain_filter=None)
 
bool async_available (self, str entity_id)
 
list[str] async_entity_ids (self, str|Iterable[str]|None domain_filter=None)
 
int async_entity_ids_count (self, str|Iterable[str]|None domain_filter=None)
 
bool async_remove (self, str entity_id, Context|None context=None)
 
None async_reserve (self, str entity_id)
 
None async_set (self, str entity_id, str new_state, Mapping[str, Any]|None attributes=None, bool force_update=False, Context|None context=None, StateInfo|None state_info=None, float|None timestamp=None)
 
None async_set_internal (self, str entity_id, str new_state, Mapping[str, Any]|None attributes, bool force_update, Context|None context, StateInfo|None state_info, float timestamp)
 
list[str] entity_ids (self, str|None domain_filter=None)
 
State|None get (self, str entity_id)
 
bool is_state (self, str entity_id, str state)
 
bool remove (self, str entity_id)
 
None set (self, str entity_id, str new_state, Mapping[str, Any]|None attributes=None, bool force_update=False, Context|None context=None)
 

Private Attributes

 _bus
 
 _loop
 
 _states
 
 _states_data
 

Static Private Attributes

 __slots__
 

Detailed Description

Helper class that tracks the state of different entities.

Definition at line 2076 of file core.py.

Constructor & Destructor Documentation

◆ __init__()

None homeassistant.core.StateMachine.__init__ (   self,
EventBus  bus,
asyncio.events.AbstractEventLoop  loop 
)
Initialize state machine.

Definition at line 2081 of file core.py.

Member Function Documentation

◆ all()

list[State] homeassistant.core.StateMachine.all (   self,
str | Iterable[str] | None   domain_filter = None 
)
Create a list of all states.

Definition at line 2135 of file core.py.

◆ async_all()

list[State] homeassistant.core.StateMachine.async_all (   self,
str | Iterable[str] | None   domain_filter = None 
)
Create a list of all states matching the filter.

This method must be run in the event loop.

Definition at line 2142 of file core.py.

◆ async_available()

bool homeassistant.core.StateMachine.async_available (   self,
str  entity_id 
)
Check to see if an entity_id is available to be used.

Definition at line 2258 of file core.py.

◆ async_entity_ids()

list[str] homeassistant.core.StateMachine.async_entity_ids (   self,
str | Iterable[str] | None   domain_filter = None 
)
List of entity ids that are being tracked.

This method must be run in the event loop.

Definition at line 2099 of file core.py.

◆ async_entity_ids_count()

int homeassistant.core.StateMachine.async_entity_ids_count (   self,
str | Iterable[str] | None   domain_filter = None 
)
Count the entity ids that are being tracked.

This method must be run in the event loop.

Definition at line 2118 of file core.py.

◆ async_remove()

bool homeassistant.core.StateMachine.async_remove (   self,
str  entity_id,
Context | None   context = None 
)
Remove the state of an entity.

Returns boolean to indicate if an entity was removed.

This method must be run in the event loop.

Definition at line 2187 of file core.py.

◆ async_reserve()

None homeassistant.core.StateMachine.async_reserve (   self,
str  entity_id 
)
Reserve a state in the state machine for an entity being added.

This must not fire an event when the state is reserved.

This avoids a race condition where multiple entities with the same
entity_id are added.

Definition at line 2240 of file core.py.

◆ async_set()

None homeassistant.core.StateMachine.async_set (   self,
str  entity_id,
str  new_state,
Mapping[str, Any] | None   attributes = None,
bool   force_update = False,
Context | None   context = None,
StateInfo | None   state_info = None,
float | None   timestamp = None 
)
Set the state of an entity, add entity if it does not exist.

Attributes is an optional dict to specify attributes of this state.

If you just update the attributes and not the state, last changed will
not be affected.

This method must be run in the event loop.

Definition at line 2266 of file core.py.

◆ async_set_internal()

None homeassistant.core.StateMachine.async_set_internal (   self,
str  entity_id,
str  new_state,
Mapping[str, Any] | None  attributes,
bool  force_update,
Context | None  context,
StateInfo | None  state_info,
float  timestamp 
)
Set the state of an entity, add entity if it does not exist.

This method is intended to only be used by core internally
and should not be considered a stable API. We will make
breaking changes to this function in the future and it
should not be used in integrations.

This method must be run in the event loop.

Definition at line 2296 of file core.py.

◆ entity_ids()

list[str] homeassistant.core.StateMachine.entity_ids (   self,
str | None   domain_filter = None 
)
List of entity ids that are being tracked.

Definition at line 2091 of file core.py.

◆ get()

State | None homeassistant.core.StateMachine.get (   self,
str  entity_id 
)
Retrieve state of entity_id or None if not found.

Async friendly.

Definition at line 2160 of file core.py.

◆ is_state()

bool homeassistant.core.StateMachine.is_state (   self,
str  entity_id,
str  state 
)
Test if entity exists and is in specified state.

Async friendly.

Definition at line 2169 of file core.py.

◆ remove()

bool homeassistant.core.StateMachine.remove (   self,
str  entity_id 
)
Remove the state of an entity.

Returns boolean to indicate if an entity was removed.

Definition at line 2177 of file core.py.

◆ set()

None homeassistant.core.StateMachine.set (   self,
str  entity_id,
str  new_state,
Mapping[str, Any] | None   attributes = None,
bool   force_update = False,
Context | None   context = None 
)
Set the state of an entity, add entity if it does not exist.

Attributes is an optional dict to specify attributes of this state.

If you just update the attributes and not the state, last changed will
not be affected.

Definition at line 2214 of file core.py.

Member Data Documentation

◆ __slots__

homeassistant.core.StateMachine.__slots__
staticprivate

Definition at line 2079 of file core.py.

◆ _bus

homeassistant.core.StateMachine._bus
private

Definition at line 2088 of file core.py.

◆ _loop

homeassistant.core.StateMachine._loop
private

Definition at line 2089 of file core.py.

◆ _states

homeassistant.core.StateMachine._states
private

Definition at line 2083 of file core.py.

◆ _states_data

homeassistant.core.StateMachine._states_data
private

Definition at line 2086 of file core.py.


The documentation for this class was generated from the following file: