Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.logbook.queries.common Namespace Reference

Functions

ColumnElement[bool] _conditionally_continuous_domain_matcher ()
 
ColumnElement[bool] _missing_state_matcher ()
 
ColumnElement[bool] _not_continuous_entity_matcher ()
 
ColumnElement[bool] _not_possible_continuous_domain_matcher ()
 
BooleanClauseList _not_uom_attributes_matcher ()
 
Select apply_events_context_hints (Select sel)
 
Select apply_states_context_hints (Select sel)
 
Select apply_states_filters (Select sel, float start_day, float end_day)
 
Select select_events_context_id_subquery (float start_day, float end_day, tuple[int,...] event_type_ids)
 
Select select_events_context_only ()
 
Select select_events_without_states (float start_day, float end_day, tuple[int,...] event_type_ids)
 
Select select_states ()
 
Select select_states_context_only ()
 

Variables

 ALWAYS_CONTINUOUS_ENTITY_ID_LIKE = like_domain_matchers(ALWAYS_CONTINUOUS_DOMAINS)
 
 CONDITIONALLY_CONTINUOUS_ENTITY_ID_LIKE
 
 CONTEXT_ONLY = literal(value="1", type_=sqlalchemy.String).label("context_only")
 
tuple EMPTY_STATE_COLUMNS
 
tuple EVENT_COLUMNS
 
tuple EVENT_COLUMNS_FOR_STATE_SELECT
 
tuple EVENT_ROWS_NO_STATES
 
 Final
 
 ICON_OR_OLD_FORMAT_ICON_JSON
 
 NOT_CONTEXT_ONLY = literal(value=None, type_=sqlalchemy.String).label("context_only")
 
tuple STATE_COLUMNS
 
tuple STATE_CONTEXT_ONLY_COLUMNS
 
string UNIT_OF_MEASUREMENT_JSON = '"unit_of_measurement":'
 
string UNIT_OF_MEASUREMENT_JSON_LIKE = f"%{UNIT_OF_MEASUREMENT_JSON}%"
 

Detailed Description

Queries for logbook.

Function Documentation

◆ _conditionally_continuous_domain_matcher()

ColumnElement[bool] homeassistant.components.logbook.queries.common._conditionally_continuous_domain_matcher ( )
private
Match conditionally continuous domains.

This matches domain that are only considered
continuous if a UOM is set.

Definition at line 234 of file common.py.

◆ _missing_state_matcher()

ColumnElement[bool] homeassistant.components.logbook.queries.common._missing_state_matcher ( )
private

Definition at line 192 of file common.py.

◆ _not_continuous_entity_matcher()

ColumnElement[bool] homeassistant.components.logbook.queries.common._not_continuous_entity_matcher ( )
private
Match non continuous entities.

Definition at line 203 of file common.py.

◆ _not_possible_continuous_domain_matcher()

ColumnElement[bool] homeassistant.components.logbook.queries.common._not_possible_continuous_domain_matcher ( )
private
Match not continuous domains.

This matches domain that are always considered continuous
and domains that are conditionally (if they have a UOM)
continuous domains.

Definition at line 216 of file common.py.

◆ _not_uom_attributes_matcher()

BooleanClauseList homeassistant.components.logbook.queries.common._not_uom_attributes_matcher ( )
private
Prefilter ATTR_UNIT_OF_MEASUREMENT as its much faster in sql.

Definition at line 248 of file common.py.

◆ apply_events_context_hints()

Select homeassistant.components.logbook.queries.common.apply_events_context_hints ( Select  sel)
Force mysql to use the right index on large context_id selects.

Definition at line 264 of file common.py.

◆ apply_states_context_hints()

Select homeassistant.components.logbook.queries.common.apply_states_context_hints ( Select  sel)
Force mysql to use the right index on large context_id selects.

Definition at line 255 of file common.py.

◆ apply_states_filters()

Select homeassistant.components.logbook.queries.common.apply_states_filters ( Select  sel,
float  start_day,
float  end_day 
)
Filter states by time range.

Filters states that do not have an old state or new state (added / removed)
Filters states that are in a continuous domain with a UOM.
Filters states that do not have matching last_updated_ts and last_changed_ts.

Definition at line 167 of file common.py.

◆ select_events_context_id_subquery()

Select homeassistant.components.logbook.queries.common.select_events_context_id_subquery ( float  start_day,
float  end_day,
tuple[int, ...]  event_type_ids 
)
Generate the select for a context_id subquery.

Definition at line 110 of file common.py.

◆ select_events_context_only()

Select homeassistant.components.logbook.queries.common.select_events_context_only ( )
Generate an events query that mark them as for context_only.

By marking them as context_only we know they are only for
linking context ids and we can avoid processing them.

Definition at line 125 of file common.py.

◆ select_events_without_states()

Select homeassistant.components.logbook.queries.common.select_events_without_states ( float  start_day,
float  end_day,
tuple[int, ...]   event_type_ids 
)
Generate an events select that does not join states.

Definition at line 145 of file common.py.

◆ select_states()

Select homeassistant.components.logbook.queries.common.select_states ( )
Generate a states select that formats the states table as event rows.

Definition at line 158 of file common.py.

◆ select_states_context_only()

Select homeassistant.components.logbook.queries.common.select_states_context_only ( )
Generate an states query that mark them as for context_only.

By marking them as context_only we know they are only for
linking context ids and we can avoid processing them.

Definition at line 134 of file common.py.

Variable Documentation

◆ ALWAYS_CONTINUOUS_ENTITY_ID_LIKE

homeassistant.components.logbook.queries.common.ALWAYS_CONTINUOUS_ENTITY_ID_LIKE = like_domain_matchers(ALWAYS_CONTINUOUS_DOMAINS)

Definition at line 36 of file common.py.

◆ CONDITIONALLY_CONTINUOUS_ENTITY_ID_LIKE

homeassistant.components.logbook.queries.common.CONDITIONALLY_CONTINUOUS_ENTITY_ID_LIKE
Initial value:
2  CONDITIONALLY_CONTINUOUS_DOMAINS
3 )
list[str] like_domain_matchers(Iterable[str] domains)
Definition: filters.py:295

Definition at line 32 of file common.py.

◆ CONTEXT_ONLY

homeassistant.components.logbook.queries.common.CONTEXT_ONLY = literal(value="1", type_=sqlalchemy.String).label("context_only")

Definition at line 106 of file common.py.

◆ EMPTY_STATE_COLUMNS

tuple homeassistant.components.logbook.queries.common.EMPTY_STATE_COLUMNS
Initial value:
1 = (
2  literal(value=None, type_=sqlalchemy.String).label("state"),
3  literal(value=None, type_=sqlalchemy.String).label("entity_id"),
4  literal(value=None, type_=sqlalchemy.String).label("icon"),
5 )

Definition at line 92 of file common.py.

◆ EVENT_COLUMNS

tuple homeassistant.components.logbook.queries.common.EVENT_COLUMNS
Initial value:
1 = (
2  Events.event_id.label("row_id"),
3  EventTypes.event_type.label("event_type"),
4  SHARED_DATA_OR_LEGACY_EVENT_DATA,
5  Events.time_fired_ts.label("time_fired_ts"),
6  Events.context_id_bin.label("context_id_bin"),
7  Events.context_user_id_bin.label("context_user_id_bin"),
8  Events.context_parent_id_bin.label("context_parent_id_bin"),
9 )

Definition at line 54 of file common.py.

◆ EVENT_COLUMNS_FOR_STATE_SELECT

tuple homeassistant.components.logbook.queries.common.EVENT_COLUMNS_FOR_STATE_SELECT
Initial value:
1 = (
2  States.state_id.label("row_id"),
3  # We use PSEUDO_EVENT_STATE_CHANGED aka None for
4  # state_changed events since it takes up less
5  # space in the response and every row has to be
6  # marked with the event_type
7  literal(value=PSEUDO_EVENT_STATE_CHANGED, type_=sqlalchemy.String).label(
8  "event_type"
9  ),
10  literal(value=None, type_=sqlalchemy.Text).label("event_data"),
11  States.last_updated_ts.label("time_fired_ts"),
12  States.context_id_bin.label("context_id_bin"),
13  States.context_user_id_bin.label("context_user_id_bin"),
14  States.context_parent_id_bin.label("context_parent_id_bin"),
15 )

Definition at line 76 of file common.py.

◆ EVENT_ROWS_NO_STATES

tuple homeassistant.components.logbook.queries.common.EVENT_ROWS_NO_STATES
Initial value:
1 = (
2  *EVENT_COLUMNS,
3  *EMPTY_STATE_COLUMNS,
4 )

Definition at line 99 of file common.py.

◆ Final

homeassistant.components.logbook.queries.common.Final

Definition at line 46 of file common.py.

◆ ICON_OR_OLD_FORMAT_ICON_JSON

homeassistant.components.logbook.queries.common.ICON_OR_OLD_FORMAT_ICON_JSON
Initial value:
1 = sqlalchemy.case(
2  (SHARED_ATTRS_JSON["icon"].is_(None), OLD_FORMAT_ATTRS_JSON["icon"].as_string()),
3  else_=SHARED_ATTRS_JSON["icon"].as_string(),
4 ).label("icon")

Definition at line 41 of file common.py.

◆ NOT_CONTEXT_ONLY

homeassistant.components.logbook.queries.common.NOT_CONTEXT_ONLY = literal(value=None, type_=sqlalchemy.String).label("context_only")

Definition at line 107 of file common.py.

◆ STATE_COLUMNS

tuple homeassistant.components.logbook.queries.common.STATE_COLUMNS
Initial value:
1 = (
2  States.state.label("state"),
3  StatesMeta.entity_id.label("entity_id"),
4  ICON_OR_OLD_FORMAT_ICON_JSON,
5 )

Definition at line 64 of file common.py.

◆ STATE_CONTEXT_ONLY_COLUMNS

tuple homeassistant.components.logbook.queries.common.STATE_CONTEXT_ONLY_COLUMNS
Initial value:
1 = (
2  States.state.label("state"),
3  StatesMeta.entity_id.label("entity_id"),
4  literal(value=None, type_=sqlalchemy.String).label("icon"),
5 )

Definition at line 70 of file common.py.

◆ UNIT_OF_MEASUREMENT_JSON

string homeassistant.components.logbook.queries.common.UNIT_OF_MEASUREMENT_JSON = '"unit_of_measurement":'

Definition at line 38 of file common.py.

◆ UNIT_OF_MEASUREMENT_JSON_LIKE

string homeassistant.components.logbook.queries.common.UNIT_OF_MEASUREMENT_JSON_LIKE = f"%{UNIT_OF_MEASUREMENT_JSON}%"

Definition at line 39 of file common.py.