From 7c4893cbb19d7386c0c4d1a6375c2d4fc7b62b68 Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Tue, 11 May 2021 16:23:59 +0200 Subject: [PATCH] Fix event action return value typing (#50353) Co-authored-by: Ruslan Sayfutdinov --- homeassistant/helpers/event.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index b8a8db8f03df..cdcacb8871b3 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -139,7 +139,7 @@ def threaded_listener_factory( def async_track_state_change( hass: HomeAssistant, entity_ids: str | Iterable[str], - action: Callable[[str, State, State], None], + action: Callable[[str, State, State], Awaitable[None] | None], from_state: None | str | Iterable[str] = None, to_state: None | str | Iterable[str] = None, ) -> CALLBACK_TYPE: @@ -683,7 +683,7 @@ def async_track_state_change_filtered( def async_track_template( hass: HomeAssistant, template: Template, - action: Callable[[str, State | None, State | None], None], + action: Callable[[str, State | None, State | None], Awaitable[None] | None], variables: TemplateVarsType | None = None, ) -> Callable[[], None]: """Add a listener that fires when a a template evaluates to 'true'. @@ -1072,7 +1072,7 @@ def async_track_template_result( def async_track_same_state( hass: HomeAssistant, period: timedelta, - action: Callable[..., None], + action: Callable[..., Awaitable[None] | None], async_check_same_func: Callable[[str, State | None, State | None], bool], entity_ids: str | Iterable[str] = MATCH_ALL, ) -> CALLBACK_TYPE: @@ -1141,7 +1141,7 @@ track_same_state = threaded_listener_factory(async_track_same_state) @bind_hass def async_track_point_in_time( hass: HomeAssistant, - action: HassJob | Callable[..., None], + action: HassJob | Callable[..., Awaitable[None] | None], point_in_time: datetime, ) -> CALLBACK_TYPE: """Add a listener that fires once after a specific point in time.""" @@ -1162,7 +1162,7 @@ track_point_in_time = threaded_listener_factory(async_track_point_in_time) @bind_hass def async_track_point_in_utc_time( hass: HomeAssistant, - action: HassJob | Callable[..., None], + action: HassJob | Callable[..., Awaitable[None] | None], point_in_time: datetime, ) -> CALLBACK_TYPE: """Add a listener that fires once after a specific point in UTC time.""" @@ -1213,7 +1213,9 @@ track_point_in_utc_time = threaded_listener_factory(async_track_point_in_utc_tim @callback @bind_hass def async_call_later( - hass: HomeAssistant, delay: float, action: HassJob | Callable[..., None] + hass: HomeAssistant, + delay: float, + action: HassJob | Callable[..., Awaitable[None] | None], ) -> CALLBACK_TYPE: """Add a listener that is called in .""" return async_track_point_in_utc_time( @@ -1228,7 +1230,7 @@ call_later = threaded_listener_factory(async_call_later) @bind_hass def async_track_time_interval( hass: HomeAssistant, - action: Callable[..., None | Awaitable], + action: Callable[..., Awaitable[None] | None], interval: timedelta, ) -> CALLBACK_TYPE: """Add a listener that fires repetitively at every timedelta interval.""" @@ -1360,7 +1362,7 @@ time_tracker_utcnow = dt_util.utcnow @bind_hass def async_track_utc_time_change( hass: HomeAssistant, - action: Callable[..., None], + action: Callable[..., Awaitable[None] | None], hour: Any | None = None, minute: Any | None = None, second: Any | None = None,