Skip to content

Commit

Permalink
Fix type hints for pre python 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
acockburn committed Mar 23, 2023
1 parent fa55cfa commit 8c131a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
23 changes: 12 additions & 11 deletions appdaemon/adapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# needed for fake coro cb that looks like scheduler
import uuid


import appdaemon.utils as utils
from appdaemon.appdaemon import AppDaemon
from appdaemon.entity import Entity
Expand Down Expand Up @@ -457,7 +458,7 @@ async def namespace_exists(self, namespace: str) -> bool:
return await self.AD.state.namespace_exists(namespace)

@utils.sync_wrapper
async def add_namespace(self, namespace: str, **kwargs) -> str | None:
async def add_namespace(self, namespace: str, **kwargs) -> Union[str, None]:
"""Used to add a user-defined namespaces from apps, which has a database file associated with it.
This way, when AD restarts these entities will be reloaded into AD with its
Expand Down Expand Up @@ -936,7 +937,7 @@ def reload_apps(self, **kwargs) -> None:
# Dialogflow
#

def get_dialogflow_intent(self, data: dict) -> Any | None:
def get_dialogflow_intent(self, data: dict) -> Union[Any, None]:
"""Gets the intent's action from the Google Home response.
Args:
Expand All @@ -960,7 +961,7 @@ def get_dialogflow_intent(self, data: dict) -> Any | None:
return None

@staticmethod
def get_dialogflow_slot_value(data, slot=None) -> Any | None:
def get_dialogflow_slot_value(data, slot=None) -> Union[Any, None]:
"""Gets slots' values from the interaction model.
Args:
Expand Down Expand Up @@ -1005,7 +1006,7 @@ def get_dialogflow_slot_value(data, slot=None) -> Any | None:
else:
return None

def format_dialogflow_response(self, speech=None) -> Any | None:
def format_dialogflow_response(self, speech=None) -> Union[Any, None]:
"""Formats a response to be returned to Google Home, including speech.
Args:
Expand Down Expand Up @@ -1059,7 +1060,7 @@ def format_alexa_response(speech=None, card=None, title=None) -> dict:
return speech

@staticmethod
def get_alexa_error(data: dict) -> str | None:
def get_alexa_error(data: dict) -> Union[str, None]:
"""Gets the error message from the Alexa API response.
Args:
Expand All @@ -1075,7 +1076,7 @@ def get_alexa_error(data: dict) -> str | None:
return None

@staticmethod
def get_alexa_intent(data: dict) -> str | None:
def get_alexa_intent(data: dict) -> Union[str, None]:
"""Gets the Intent's name from the Alexa response.
Args:
Expand All @@ -1095,7 +1096,7 @@ def get_alexa_intent(data: dict) -> str | None:
return None

@staticmethod
def get_alexa_slot_value(data, slot=None) -> str | None:
def get_alexa_slot_value(data, slot=None) -> Union[str, None]:
"""Gets values for slots from the interaction model.
Args:
Expand Down Expand Up @@ -2372,7 +2373,7 @@ async def reset_timer(self, handle: str) -> bool:
return await self.AD.sched.reset_timer(name, handle)

@utils.sync_wrapper
async def info_timer(self, handle: str) -> tuple | None:
async def info_timer(self, handle: str) -> Union[tuple, None]:
"""Gets information on a scheduler event from its handle.
Args:
Expand Down Expand Up @@ -2446,7 +2447,7 @@ async def run_in(self, callback: Callable, delay: int, **kwargs) -> str:
return handle

@utils.sync_wrapper
async def run_once(self, callback: Callable, start: dt.time | str, **kwargs):
async def run_once(self, callback: Callable, start: Union[dt.time, str], **kwargs):
"""Runs the callback once, at the specified time of day.
Args:
Expand Down Expand Up @@ -2517,7 +2518,7 @@ async def run_once(self, callback: Callable, start: dt.time | str, **kwargs):
return handle

@utils.sync_wrapper
async def run_at(self, callback: Callable, start: dt.datetime | str, **kwargs):
async def run_at(self, callback: Callable, start: Union[dt.datetime, str], **kwargs):
"""Runs the callback once, at the specified time of day.
Args:
Expand Down Expand Up @@ -2591,7 +2592,7 @@ async def run_at(self, callback: Callable, start: dt.datetime | str, **kwargs):
return handle

@utils.sync_wrapper
async def run_daily(self, callback: Callable, start: dt.time | str, **kwargs):
async def run_daily(self, callback: Callable, start: Union[dt.time, str], **kwargs):
"""Runs the callback at the same time every day.
Args:
Expand Down
8 changes: 4 additions & 4 deletions appdaemon/plugins/hass/hassapi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any, Optional, Union
import requests
from ast import literal_eval
from functools import wraps
Expand Down Expand Up @@ -306,7 +306,7 @@ def constrain_person(self, value: str) -> bool:

return unconstrained

def constrain_input_boolean(self, value: str | list) -> bool:
def constrain_input_boolean(self, value: Union[str, list]) -> bool:
unconstrained = True
state = self.get_state()

Expand All @@ -324,7 +324,7 @@ def constrain_input_boolean(self, value: str | list) -> bool:

return unconstrained

def constrain_input_select(self, value: str | list) -> bool:
def constrain_input_select(self, value: Union[str, list]) -> bool:
unconstrained = True
state = self.get_state()

Expand Down Expand Up @@ -459,7 +459,7 @@ async def toggle(self, entity_id: str, **kwargs) -> None:

@utils.sync_wrapper
@hass_check
async def set_value(self, entity_id: str, value: int | float, **kwargs) -> None:
async def set_value(self, entity_id: str, value: Union[int, float], **kwargs) -> None:
"""Sets the value of an `input_number`.
This is a convenience function for the ``input_number.set_value``
Expand Down

0 comments on commit 8c131a7

Please sign in to comment.