From 781e4571b27b6aaaabd885e7af53cbf2465b41f3 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 30 Jun 2022 19:00:34 +0200 Subject: [PATCH] Add CalendarEntity checks to pylint plugin (#74228) * Add CalendarEntity checks to pylint plugin * adjust air_quality ignore * Mark state property as final --- homeassistant/components/calendar/__init__.py | 6 +++-- pylint/plugins/hass_enforce_type_hints.py | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/calendar/__init__.py b/homeassistant/components/calendar/__init__.py index 432b6943473..4623f490302 100644 --- a/homeassistant/components/calendar/__init__.py +++ b/homeassistant/components/calendar/__init__.py @@ -222,8 +222,9 @@ class CalendarEventDevice(Entity): "description": event["description"], } + @final @property - def state(self) -> str | None: + def state(self) -> str: """Return the state of the calendar event.""" if (event := self.event) is None: return STATE_OFF @@ -276,8 +277,9 @@ class CalendarEntity(Entity): "description": event.description if event.description else "", } + @final @property - def state(self) -> str | None: + def state(self) -> str: """Return the state of the calendar event.""" if (event := self.event) is None: return STATE_OFF diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 5f4f641cbae..3ac072373b8 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -591,6 +591,7 @@ _TOGGLE_ENTITY_MATCH: list[TypeHintMatch] = [ ), ] _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = { + # "air_quality": [], # ignored as deprecated "alarm_control_panel": [ ClassTypeHintMatch( base_class="Entity", @@ -717,6 +718,30 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = { ], ), ], + "calendar": [ + ClassTypeHintMatch( + base_class="Entity", + matches=_ENTITY_MATCH, + ), + ClassTypeHintMatch( + base_class="CalendarEntity", + matches=[ + TypeHintMatch( + function_name="event", + return_type=["CalendarEvent", None], + ), + TypeHintMatch( + function_name="async_get_events", + arg_types={ + 1: "HomeAssistant", + 2: "datetime", + 3: "datetime", + }, + return_type="list[CalendarEvent]", + ), + ], + ), + ], "cover": [ ClassTypeHintMatch( base_class="Entity",