Skip to content

Commit

Permalink
Merge pull request smarthomeNG#714 from Morg42/develop
Browse files Browse the repository at this point in the history
sdp: allow multiple lookup items per table and mode
  • Loading branch information
Morg42 authored Feb 5, 2025
2 parents c484b89 + 4dc90a4 commit 31f1a85
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/model/smartdeviceplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,7 @@ def find_custom_attr(item: Item, index: int = 1) -> str | None:
self.logger.debug(f'Item {item} assigned lookup {table} with contents {lu}')

# store reverse-accessible items
if table not in self._items_by_lookup:
self._items_by_lookup[table] = {}
self._items_by_lookup[table][mode] = item
self._items_by_lookup.setdefault(table, {}).setdefault(mode, []).append(item)

if mode == 'fwd':
# only store item for update_items if mode is 'fwd'
Expand Down Expand Up @@ -756,11 +754,10 @@ def update_item(self, item: Item, caller: str | None = None, source: str | None
self._commands.update_lookup_table(table, item())
# update the other mode tables, if there are associated items
for mode in ('rev', 'rci', 'list'):
lu_item = None
try:
self.logger.debug(f'trying to set item for lookup {table} and mode {mode}')
lu_item = self._items_by_lookup[table][mode]
lu_item(self.get_lookup(table, mode), self.get_fullname())
self.logger.debug(f'trying to set item(s) for lookup {table} and mode {mode}')
for lu_item in self._items_by_lookup[table][mode]:
lu_item(self.get_lookup(table, mode), self.get_fullname())
except (KeyError, AttributeError):
pass

Expand Down Expand Up @@ -1053,7 +1050,7 @@ def is_valid_command(self, command: str, read: bool | None = None) -> bool | Non
else:
return False

def get_lookup(self, lookup: str, mode: str = 'fwd') -> list | None:
def get_lookup(self, lookup: str, mode: str = 'fwd') -> dict | list | None:
""" returns the lookup table for name <lookup>, None on error """
if self._commands:
return self._commands.get_lookup(lookup, mode)
Expand Down

0 comments on commit 31f1a85

Please sign in to comment.