diff --git a/appdaemon/adapi.py b/appdaemon/adapi.py index 79420d3ab..2480e16fe 100644 --- a/appdaemon/adapi.py +++ b/appdaemon/adapi.py @@ -489,7 +489,8 @@ def set_error_level(self, level: str | int) -> None: # Threading # - def set_app_pin(self, pin: bool) -> None: + @utils.sync_decorator + async def set_app_pin(self, pin: bool) -> None: """Sets an App to be pinned or unpinned. Args: @@ -506,7 +507,8 @@ def set_app_pin(self, pin: bool) -> None: """ self.AD.app_management.set_app_pin(self.name, pin) - def get_app_pin(self) -> bool: + @utils.sync_decorator + async def get_app_pin(self) -> bool: """Finds out if the current App is currently pinned or not. Returns: @@ -519,7 +521,8 @@ def get_app_pin(self) -> bool: """ return self.AD.app_management.get_app_pin(self.name) - def set_pin_thread(self, thread: int) -> None: + @utils.sync_decorator + async def set_pin_thread(self, thread: int) -> None: """Sets the thread that the App will be pinned to. Args: @@ -537,7 +540,8 @@ def set_pin_thread(self, thread: int) -> None: """ self.AD.app_management.set_pin_thread(self.name, thread) - def get_pin_thread(self) -> int: + @utils.sync_decorator + async def get_pin_thread(self) -> int: """Finds out which thread the App is pinned to. Returns: @@ -590,7 +594,8 @@ def get_namespace(self) -> str: # Keeping namespace get/set functions for legacy compatibility return self.namespace - def namespace_exists(self, namespace: str) -> bool: + @utils.sync_decorator + async def namespace_exists(self, namespace: str) -> bool: """Check the existence of a namespace in AppDaemon. See the `namespace documentation `__ for more information. @@ -668,7 +673,8 @@ async def remove_namespace(self, namespace: str) -> dict[str, Any] | None: return await self.AD.state.remove_namespace(namespace) - def list_namespaces(self) -> list[str]: + @utils.sync_decorator + async def list_namespaces(self) -> list[str]: """Get a list of all the namespaces in AppDaemon. Examples: @@ -909,7 +915,8 @@ def split_device_list(devices: str) -> list[str]: """ return devices.split(",") - def get_plugin_config(self, namespace: str | None = None) -> Any: + @utils.sync_decorator + async def get_plugin_config(self, namespace: str | None = None) -> Any: """Gets any useful metadata that the plugin may have available. For instance, for the HASS plugin, this will return Home Assistant configuration @@ -931,7 +938,8 @@ def get_plugin_config(self, namespace: str | None = None) -> Any: namespace = namespace or self.namespace return self.AD.plugins.get_plugin_meta(namespace) - def friendly_name(self, entity_id: str, namespace: str | None = None) -> str: + @utils.sync_decorator + async def friendly_name(self, entity_id: str, namespace: str | None = None) -> str: """Gets the Friendly Name of an entity. Args: @@ -1380,7 +1388,7 @@ async def deregister_route(self, handle: str) -> None: # State # - @overload + @overload # single entity @utils.sync_decorator async def listen_state( self, @@ -1399,7 +1407,7 @@ async def listen_state( **kwargs: Any ) -> str: ... - @overload + @overload # multiple entities @utils.sync_decorator async def listen_state( self, diff --git a/appdaemon/plugins/hass/hassapi.py b/appdaemon/plugins/hass/hassapi.py index 0425dbbce..ac0090234 100644 --- a/appdaemon/plugins/hass/hassapi.py +++ b/appdaemon/plugins/hass/hassapi.py @@ -260,7 +260,8 @@ def get_tracker_state(self, *args, **kwargs) -> str: """ return self.get_state(*args, **kwargs) - def anyone_home(self, person: bool = True, namespace: str | None = None) -> bool: + @utils.sync_decorator + async def anyone_home(self, person: bool = True, namespace: str | None = None) -> bool: """Determines if the house/apartment is occupied. A convenience function to determine if one or more person is home. Use @@ -285,10 +286,11 @@ def anyone_home(self, person: bool = True, namespace: str | None = None) -> bool >>> do something """ - details = self.get_tracker_details(person, namespace, copy=False) + details = await self.get_tracker_details(person, namespace, copy=False) return any(state['state'] == 'home' for state in details.values()) - def everyone_home(self, person: bool = True, namespace: str | None = None) -> bool: + @utils.sync_decorator + async def everyone_home(self, person: bool = True, namespace: str | None = None) -> bool: """Determine if all family's members at home. A convenience function to determine if everyone is home. Use this in @@ -312,10 +314,11 @@ def everyone_home(self, person: bool = True, namespace: str | None = None) -> bo >>> do something """ - details = self.get_tracker_details(person, namespace, copy=False) + details = await self.get_tracker_details(person, namespace, copy=False) return all(state['state'] == 'home' for state in details.values()) - def noone_home(self, person: bool = True, namespace: str | None = None) -> bool: + @utils.sync_decorator + async def noone_home(self, person: bool = True, namespace: str | None = None) -> bool: """Determines if the house/apartment is empty. A convenience function to determine if no people are at home. Use this @@ -340,7 +343,7 @@ def noone_home(self, person: bool = True, namespace: str | None = None) -> bool: >>> do something """ - return not self.anyone_home(person, namespace) + return not await self.anyone_home(person, namespace) # # Built-in constraints diff --git a/docs/HISTORY.md b/docs/HISTORY.md index ec387f981..956285def 100644 --- a/docs/HISTORY.md +++ b/docs/HISTORY.md @@ -8,7 +8,17 @@ None **Fixes** -None +- Reverted async methods + - `set_app_pin` + - `get_app_pin` + - `set_pin_thread` + - `get_pin_thread` + - `get_plugin_config` + - `namespace_exists` + - `get_plugin_config` + - `anyone_home` + - `everyone_home` + - `noone_home` **Breaking Changes**