Skip to content

Commit

Permalink
Merge pull request #80 from ohinckel/dev-match-attr-val
Browse files Browse the repository at this point in the history
Make it possible to match on item attribute and it's value
  • Loading branch information
psilo909 committed Aug 21, 2016
2 parents fde0e53 + ac550cd commit bd2456f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/smarthome.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,11 @@ def match_items(self, regex):
regex, __, attr = regex.partition(':')
regex = regex.replace('.', '\.').replace('*', '.*') + '$'
regex = re.compile(regex)
if attr != '':
attr, __, val = attr.partition('[')
val = val.rstrip(']')
if attr != '' and val != '':
return [self.__item_dict[item] for item in self.__items if regex.match(item) and attr in self.__item_dict[item].conf and ((type(self.__item_dict[item].conf[attr]) in [list,dict] and val in self.__item_dict[item].conf[attr]) or (val == self.__item_dict[item].conf[attr]))]
elif attr != '':
return [self.__item_dict[item] for item in self.__items if regex.match(item) and attr in self.__item_dict[item].conf]
else:
return [self.__item_dict[item] for item in self.__items if regex.match(item)]
Expand Down

0 comments on commit bd2456f

Please sign in to comment.