diff --git a/homeassistant/components/history/websocket_api.py b/homeassistant/components/history/websocket_api.py index 25422004797..f903a9904a9 100644 --- a/homeassistant/components/history/websocket_api.py +++ b/homeassistant/components/history/websocket_api.py @@ -179,8 +179,8 @@ def _generate_stream_message( """Generate a history stream message response.""" return { "states": states, - "start_time": dt_util.utc_to_timestamp(start_day), - "end_time": dt_util.utc_to_timestamp(end_day), + "start_time": start_day.timestamp(), + "end_time": end_day.timestamp(), } diff --git a/homeassistant/components/logbook/queries/__init__.py b/homeassistant/components/logbook/queries/__init__.py index 29d89a4c22f..af41374ec9b 100644 --- a/homeassistant/components/logbook/queries/__init__.py +++ b/homeassistant/components/logbook/queries/__init__.py @@ -9,7 +9,6 @@ from sqlalchemy.sql.lambdas import StatementLambdaElement from homeassistant.components.recorder.filters import Filters from homeassistant.components.recorder.models import ulid_to_bytes_or_none from homeassistant.helpers.json import json_dumps -from homeassistant.util import dt as dt_util from .all import all_stmt from .devices import devices_stmt @@ -28,8 +27,8 @@ def statement_for_request( context_id: str | None = None, ) -> StatementLambdaElement: """Generate the logbook statement for a logbook request.""" - start_day = dt_util.utc_to_timestamp(start_day_dt) - end_day = dt_util.utc_to_timestamp(end_day_dt) + start_day = start_day_dt.timestamp() + end_day = end_day_dt.timestamp() # No entities: logbook sends everything for the timeframe # limited by the context_id and the yaml configured filter if not entity_ids and not device_ids: diff --git a/homeassistant/components/logbook/websocket_api.py b/homeassistant/components/logbook/websocket_api.py index 82124247adf..0b1b34ca375 100644 --- a/homeassistant/components/logbook/websocket_api.py +++ b/homeassistant/components/logbook/websocket_api.py @@ -184,8 +184,8 @@ def _generate_stream_message( """Generate a logbook stream message response.""" return { "events": events, - "start_time": dt_util.utc_to_timestamp(start_day), - "end_time": dt_util.utc_to_timestamp(end_day), + "start_time": start_day.timestamp(), + "end_time": end_day.timestamp(), } diff --git a/homeassistant/components/recorder/purge.py b/homeassistant/components/recorder/purge.py index 0b63bb8daa2..a9d8c0b2482 100644 --- a/homeassistant/components/recorder/purge.py +++ b/homeassistant/components/recorder/purge.py @@ -10,8 +10,6 @@ from typing import TYPE_CHECKING from sqlalchemy.orm.session import Session -import homeassistant.util.dt as dt_util - from .db_schema import Events, States, StatesMeta from .models import DatabaseEngine from .queries import ( @@ -251,7 +249,7 @@ def _select_state_attributes_ids_to_purge( state_ids = set() attributes_ids = set() for state_id, attributes_id in session.execute( - find_states_to_purge(dt_util.utc_to_timestamp(purge_before), max_bind_vars) + find_states_to_purge(purge_before.timestamp(), max_bind_vars) ).all(): state_ids.add(state_id) if attributes_id: @@ -271,7 +269,7 @@ def _select_event_data_ids_to_purge( event_ids = set() data_ids = set() for event_id, data_id in session.execute( - find_events_to_purge(dt_util.utc_to_timestamp(purge_before), max_bind_vars) + find_events_to_purge(purge_before.timestamp(), max_bind_vars) ).all(): event_ids.add(event_id) if data_id: @@ -464,7 +462,7 @@ def _select_legacy_detached_state_and_attributes_and_data_ids_to_purge( """ states = session.execute( find_legacy_detached_states_and_attributes_to_purge( - dt_util.utc_to_timestamp(purge_before), max_bind_vars + purge_before.timestamp(), max_bind_vars ) ).all() _LOGGER.debug("Selected %s state ids to remove", len(states)) @@ -489,7 +487,7 @@ def _select_legacy_event_state_and_attributes_and_data_ids_to_purge( """ events = session.execute( find_legacy_event_state_and_attributes_and_data_ids_to_purge( - dt_util.utc_to_timestamp(purge_before), max_bind_vars + purge_before.timestamp(), max_bind_vars ) ).all() _LOGGER.debug("Selected %s event ids to remove", len(events)) diff --git a/homeassistant/core.py b/homeassistant/core.py index 004c0dc1ede..047f46afdf5 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -1077,9 +1077,7 @@ class Event: self.origin = origin self.time_fired = time_fired or dt_util.utcnow() if not context: - context = Context( - id=ulid_at_time(dt_util.utc_to_timestamp(self.time_fired)) - ) + context = Context(id=ulid_at_time(self.time_fired.timestamp())) self.context = context if not context.origin_event: context.origin_event = self diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index ea80591a989..b109ce16698 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -1442,7 +1442,7 @@ def async_track_point_in_utc_time( """ # Ensure point_in_time is UTC utc_point_in_time = dt_util.as_utc(point_in_time) - expected_fire_timestamp = dt_util.utc_to_timestamp(utc_point_in_time) + expected_fire_timestamp = utc_point_in_time.timestamp() job = ( action if isinstance(action, HassJob)