Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions appdaemon/adapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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 <APPGUIDE.html#namespaces>`__ for more information.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -1399,7 +1407,7 @@ async def listen_state(
**kwargs: Any
) -> str: ...

@overload
@overload # multiple entities
@utils.sync_decorator
async def listen_state(
self,
Expand Down
15 changes: 9 additions & 6 deletions appdaemon/plugins/hass/hassapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion docs/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
Loading