Skip to content
Merged
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: 19 additions & 9 deletions appdaemon/plugins/hass/hassapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,28 @@ async def _domain_service_call(
- Asserts that the entity is in the right domain.
- Displays a warning if the entity doesn't exist in the namespace.
"""
namespace = namespace or self.namespace
domain = service.split('/')[0]
namespace = namespace if namespace is not None else self.namespace
service_domain = service.split('/')[0]

def _check(entity_ids: Iterable[str]) -> None:
for eid in entity_ids:
entity_domain = eid.split('.')[0]
# This check needs to work for domains like "number" and "input_number"
assert entity_domain in service_domain, (
f"Entity domain '{entity_domain}' does not match service domain '{service_domain}'"
)
self._check_entity(namespace, eid)

match entity_id:
case str():
assert domain == entity_id.split('.')[0], f'{entity_id} does not match domain for {service}'
self._check_entity(namespace, entity_id)
case Iterable():
entity_id = entity_id if isinstance(entity_id, list) else list(entity_id)
for e in entity_id:
assert domain == e.split('.')[0], f'{e} does not match domain for {service}'
self._check_entity(namespace, e)
_check([entity_id])
case list(entity_ids):
_check(entity_ids)
case Iterable() as entity_ids:
entity_id = entity_ids if isinstance(entity_ids, list) else list(entity_ids)
_check(entity_id)
case _:
raise TypeError('entity_id must be a string or an iterable of strings')

return await self.call_service(
service=service,
Expand Down
Loading