From dc6eef2844a19a736119fe8df4ed38ed2fc20100 Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Wed, 24 Jun 2026 23:15:09 +0800 Subject: [PATCH] Fix date-only input_datetime timestamp attribute to use the correct TZ (#174357) --- homeassistant/components/input_datetime/__init__.py | 4 +++- tests/components/input_datetime/test_init.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/input_datetime/__init__.py b/homeassistant/components/input_datetime/__init__.py index 2fd52f17a5ed..9d581badd1ac 100644 --- a/homeassistant/components/input_datetime/__init__.py +++ b/homeassistant/components/input_datetime/__init__.py @@ -389,7 +389,9 @@ class InputDatetime(collection.CollectionEntity, RestoreEntity): elif not self.has_time: extended = py_datetime.datetime.combine( - self._current_datetime, py_datetime.time(0, 0) + self._current_datetime, + py_datetime.time(0, 0), + dt_util.get_default_time_zone(), ) attrs[InputDatetimeEntityStateAttribute.TIMESTAMP] = extended.timestamp() diff --git a/tests/components/input_datetime/test_init.py b/tests/components/input_datetime/test_init.py index 9e3364ebc424..9c1dad0757f2 100644 --- a/tests/components/input_datetime/test_init.py +++ b/tests/components/input_datetime/test_init.py @@ -344,7 +344,9 @@ async def test_set_datetime_date(hass: HomeAssistant) -> None: assert not state.attributes["has_time"] assert state.attributes["has_date"] - date_dt_obj = datetime.datetime(2017, 9, 7) + date_dt_obj = datetime.datetime( + 2017, 9, 7, tzinfo=dt_util.get_time_zone(hass.config.time_zone) + ) assert state.attributes["timestamp"] == date_dt_obj.timestamp()