Fix setting timestamp on input_datetime (#44274)

This commit is contained in:
Paulus Schoutsen
2020-12-16 11:18:50 +01:00
committed by GitHub
parent dfde403937
commit 4f9d5792ed
2 changed files with 31 additions and 5 deletions

View File

@ -697,6 +697,15 @@ async def test_timestamp(hass):
).strftime(FMT_DATETIME)
== "2020-12-13 10:00:00"
)
# Use datetime.datetime.fromtimestamp
assert (
dt_util.as_local(
datetime.datetime.fromtimestamp(
state_without_tz.attributes[ATTR_TIMESTAMP]
)
).strftime(FMT_DATETIME)
== "2020-12-13 10:00:00"
)
# Test initial time sets timestamp correctly.
state_time = hass.states.get("input_datetime.test_time_initial")
@ -704,5 +713,24 @@ async def test_timestamp(hass):
assert state_time.state == "10:00:00"
assert state_time.attributes[ATTR_TIMESTAMP] == 10 * 60 * 60
# Test that setting the timestamp of an entity works.
await hass.services.async_call(
DOMAIN,
"set_datetime",
{
ATTR_ENTITY_ID: "input_datetime.test_datetime_initial_with_tz",
ATTR_TIMESTAMP: state_without_tz.attributes[ATTR_TIMESTAMP],
},
blocking=True,
)
state_with_tz_updated = hass.states.get(
"input_datetime.test_datetime_initial_with_tz"
)
assert state_with_tz_updated.state == "2020-12-13 10:00:00"
assert (
state_with_tz_updated.attributes[ATTR_TIMESTAMP]
== state_without_tz.attributes[ATTR_TIMESTAMP]
)
finally:
dt_util.set_default_time_zone(ORIG_TIMEZONE)