Fix additional typing in local calendar tests (#89704)

* Fix additional typing in local calendar tests

* Update tests/components/local_calendar/test_calendar.py

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

---------

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
Allen Porter 2023-03-14 19:33:46 -07:00 committed by GitHub
parent b906d67c1e
commit a91055cc2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 13 deletions

View File

@ -87,14 +87,14 @@ async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry)
await hass.async_block_till_done()
GetEventsFn = Callable[[str, str], Awaitable[dict[str, Any]]]
GetEventsFn = Callable[[str, str], Awaitable[list[dict[str, Any]]]]
@pytest.fixture(name="get_events")
def get_events_fixture(hass_client: ClientSessionGenerator) -> GetEventsFn:
"""Fetch calendar events from the HTTP API."""
async def _fetch(start: str, end: str) -> None:
async def _fetch(start: str, end: str) -> list[dict[str, Any]]:
client = await hass_client()
response = await client.get(
f"/api/calendars/{TEST_ENTITY}?start={urllib.parse.quote(start)}&end={urllib.parse.quote(end)}"
@ -108,9 +108,7 @@ def get_events_fixture(hass_client: ClientSessionGenerator) -> GetEventsFn:
def event_fields(data: dict[str, str]) -> dict[str, str]:
"""Filter event API response to minimum fields."""
return {
k: data.get(k)
for k in ["summary", "start", "end", "recurrence_id"]
if data.get(k)
k: data[k] for k in ["summary", "start", "end", "recurrence_id"] if data.get(k)
}
@ -122,7 +120,9 @@ class Client:
self.client = client
self.id = 0
async def cmd(self, cmd: str, payload: dict[str, Any] = None) -> dict[str, Any]:
async def cmd(
self, cmd: str, payload: dict[str, Any] | None = None
) -> dict[str, Any]:
"""Send a command and receive the json result."""
self.id += 1
await self.client.send_json(
@ -136,7 +136,9 @@ class Client:
assert resp.get("id") == self.id
return resp
async def cmd_result(self, cmd: str, payload: dict[str, Any] = None) -> Any:
async def cmd_result(
self, cmd: str, payload: dict[str, Any] | None = None
) -> dict[str, Any] | None:
"""Send a command and parse the result."""
resp = await self.cmd(cmd, payload)
assert resp.get("success")

View File

@ -28,6 +28,7 @@ async def test_empty_calendar(
assert len(events) == 0
state = hass.states.get(TEST_ENTITY)
assert state
assert state.name == FRIENDLY_NAME
assert state.state == STATE_OFF
assert dict(state.attributes) == {
@ -140,6 +141,7 @@ async def test_active_event(
)
state = hass.states.get(TEST_ENTITY)
assert state
assert state.name == FRIENDLY_NAME
assert state.state == STATE_ON
assert dict(state.attributes) == {
@ -176,6 +178,7 @@ async def test_upcoming_event(
)
state = hass.states.get(TEST_ENTITY)
assert state
assert state.name == FRIENDLY_NAME
assert state.state == STATE_OFF
assert dict(state.attributes) == {
@ -642,9 +645,10 @@ async def test_invalid_rrule(
},
},
)
assert resp
assert not resp.get("success")
assert "error" in resp
assert resp.get("error").get("code") == "invalid_format"
assert resp["error"].get("code") == "invalid_format"
@pytest.mark.parametrize(
@ -720,9 +724,10 @@ async def test_start_end_types(
},
},
)
assert result
assert not result.get("success")
assert "error" in result
assert "code" in result.get("error")
assert "code" in result["error"]
assert result["error"]["code"] == "invalid_format"
@ -743,9 +748,10 @@ async def test_end_before_start(
},
},
)
assert result
assert not result.get("success")
assert "error" in result
assert "code" in result.get("error")
assert "code" in result["error"]
assert result["error"]["code"] == "invalid_format"
@ -767,9 +773,10 @@ async def test_invalid_recurrence_rule(
},
},
)
assert result
assert not result.get("success")
assert "error" in result
assert "code" in result.get("error")
assert "code" in result["error"]
assert result["error"]["code"] == "invalid_format"
@ -790,9 +797,10 @@ async def test_invalid_date_formats(
},
},
)
assert result
assert not result.get("success")
assert "error" in result
assert "code" in result.get("error")
assert "code" in result["error"]
assert result["error"]["code"] == "invalid_format"
@ -815,9 +823,10 @@ async def test_update_invalid_event_id(
},
},
)
assert resp
assert not resp.get("success")
assert "error" in resp
assert resp.get("error").get("code") == "failed"
assert resp["error"].get("code") == "failed"
@pytest.mark.parametrize(