diff --git a/homeassistant/components/history/__init__.py b/homeassistant/components/history/__init__.py index 4471651d8cd..7c781fd7bcb 100644 --- a/homeassistant/components/history/__init__.py +++ b/homeassistant/components/history/__init__.py @@ -423,7 +423,7 @@ class HistoryPeriodView(HomeAssistantView): self, request: web.Request, datetime: Optional[str] = None ) -> web.Response: """Return history over a period of time.""" - + datetime_ = None if datetime: datetime_ = dt_util.parse_datetime(datetime) diff --git a/tests/components/history/test_init.py b/tests/components/history/test_init.py index e7a03678835..1a5baa86e22 100644 --- a/tests/components/history/test_init.py +++ b/tests/components/history/test_init.py @@ -768,6 +768,16 @@ async def test_fetch_period_api_with_minimal_response(hass, hass_client): assert response.status == 200 +async def test_fetch_period_api_with_no_timestamp(hass, hass_client): + """Test the fetch period view for history with no timestamp.""" + await hass.async_add_executor_job(init_recorder_component, hass) + await async_setup_component(hass, "history", {}) + await hass.async_add_job(hass.data[recorder.DATA_INSTANCE].block_till_done) + client = await hass_client() + response = await client.get("/api/history/period") + assert response.status == 200 + + async def test_fetch_period_api_with_include_order(hass, hass_client): """Test the fetch period view for history.""" await hass.async_add_executor_job(init_recorder_component, hass)