Improve type hints in demo [1/3] (#77180)
This commit is contained in:
parent
575ac5ae0a
commit
7eb8e1f25d
13 changed files with 156 additions and 247 deletions
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
|
||||
import copy
|
||||
import datetime
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.calendar import (
|
||||
CalendarEntity,
|
||||
|
@ -60,18 +61,13 @@ class DemoCalendar(CalendarEntity):
|
|||
def __init__(self, event: CalendarEvent, name: str) -> None:
|
||||
"""Initialize demo calendar."""
|
||||
self._event = event
|
||||
self._name = name
|
||||
self._attr_name = name
|
||||
|
||||
@property
|
||||
def event(self) -> CalendarEvent:
|
||||
"""Return the next upcoming event."""
|
||||
return self._event
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the entity."""
|
||||
return self._name
|
||||
|
||||
async def async_get_events(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
|
@ -87,7 +83,7 @@ class LegacyDemoCalendar(CalendarEventDevice):
|
|||
|
||||
def __init__(self, name: str) -> None:
|
||||
"""Initialize demo calendar."""
|
||||
self._name = name
|
||||
self._attr_name = name
|
||||
one_hour_from_now = dt_util.now() + datetime.timedelta(minutes=30)
|
||||
self._event = {
|
||||
"start": {"dateTime": one_hour_from_now.isoformat()},
|
||||
|
@ -102,16 +98,16 @@ class LegacyDemoCalendar(CalendarEventDevice):
|
|||
}
|
||||
|
||||
@property
|
||||
def event(self):
|
||||
def event(self) -> dict[str, Any]:
|
||||
"""Return the next upcoming event."""
|
||||
return self._event
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the entity."""
|
||||
return self._name
|
||||
|
||||
async def async_get_events(self, hass, start_date, end_date):
|
||||
async def async_get_events(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
start_date: datetime.datetime,
|
||||
end_date: datetime.datetime,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Get all events in a specific time frame."""
|
||||
event = copy.copy(self.event)
|
||||
event["title"] = event["summary"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue