mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Fix input_datetime.set_datetime not accepting 0 timestamp value (#134489)
This commit is contained in:
parent
ac26ca2da5
commit
cb389d29ea
@ -385,7 +385,7 @@ class InputDatetime(collection.CollectionEntity, RestoreEntity):
|
||||
@callback
|
||||
def async_set_datetime(self, date=None, time=None, datetime=None, timestamp=None):
|
||||
"""Set a new date / time."""
|
||||
if timestamp:
|
||||
if timestamp is not None:
|
||||
datetime = dt_util.as_local(dt_util.utc_from_timestamp(timestamp))
|
||||
|
||||
if datetime:
|
||||
|
@ -217,6 +217,34 @@ async def test_set_datetime_3(hass: HomeAssistant) -> None:
|
||||
assert state.attributes["timestamp"] == dt_obj.timestamp()
|
||||
|
||||
|
||||
async def test_set_datetime_4(hass: HomeAssistant) -> None:
|
||||
"""Test set_datetime method using timestamp 0."""
|
||||
await async_setup_component(
|
||||
hass, DOMAIN, {DOMAIN: {"test_datetime": {"has_time": True, "has_date": True}}}
|
||||
)
|
||||
|
||||
entity_id = "input_datetime.test_datetime"
|
||||
|
||||
dt_obj = datetime.datetime(
|
||||
1969, 12, 31, 16, 00, 00, tzinfo=dt_util.get_time_zone(hass.config.time_zone)
|
||||
)
|
||||
|
||||
await async_set_timestamp(hass, entity_id, 0)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == dt_obj.strftime(FORMAT_DATETIME)
|
||||
assert state.attributes["has_time"]
|
||||
assert state.attributes["has_date"]
|
||||
|
||||
assert state.attributes["year"] == 1969
|
||||
assert state.attributes["month"] == 12
|
||||
assert state.attributes["day"] == 31
|
||||
assert state.attributes["hour"] == 16
|
||||
assert state.attributes["minute"] == 00
|
||||
assert state.attributes["second"] == 0
|
||||
assert state.attributes["timestamp"] == 0
|
||||
|
||||
|
||||
async def test_set_datetime_time(hass: HomeAssistant) -> None:
|
||||
"""Test set_datetime method with only time."""
|
||||
await async_setup_component(
|
||||
|
Loading…
x
Reference in New Issue
Block a user