Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to match on item attribute and it's value #80

Merged
merged 2 commits into from Aug 21, 2016

Conversation

ohinckel
Copy link
Member

(copied from mknx/smarthome#175)

The sh.match_items() method is already able to mach items by a given attribute names and return a list of items having the given attribute.

Usually you're using this to identify item having some characteristics. But sometimes you have the same attribute with different values configured and want to handle them differently, for example when connecting them to some logics using watch_item setting.

You can now do

  • sh.match_items("some.items.*:attr") which returns items with the attribute attr (already working)
  • sh.match_items("some.items.*:attr[value]") which returns items with the attribute attr set to value value (new)

The value checking supports

  • simple types (e.g. str, int, ...) by checking equality (e.g. attr = somevalue)
  • lists by checking against the list's values (e.g. attr = first | second | third)
  • dictionary by checking against the dict's keys (e.g. attr = { first : val1 | second : val2 } (only works with Configure dictionaries in config files mknx/smarthome#88, of if attributes are set in some code directly)

Something like this is now possible

[somelogic]
  filename = logic.py
  watch_item = *:item_class[light]

[otherlogic]
  filename = logic.py
  watch_item = *:item_class[dimmer]

Further I was also thinking about tree traversal and make it possible to match items using the pattern some.path:attr[value].children.*. But this seems to be more complex and could need a rewrite of the matching logic. And I don't know if this is really a good idea to introduce such a complexity. On the other hand, this feature would be nice, since it makes the configuration more flexible.

# e.g. "some.items.*:attr[value]" match items having attribute "attr" with the
# value "value"
@ohinckel
Copy link
Member Author

Any opinions on this PR?

@psilo909
Copy link
Contributor

psilo909 commented Aug 20, 2016

i think was sitting here, just a second away from a merge. in general, it would be ok for me, but perhaps some other opinions would be nice.. we should also strongly document these things after merging them to the core

@psilo909 psilo909 merged commit bd2456f into smarthomeNG:develop Aug 21, 2016
@ohinckel
Copy link
Member Author

ohinckel commented Sep 2, 2016

Documentation added: https://github.com/smarthomeNG/smarthome/wiki/Logic

@ohinckel ohinckel deleted the dev-match-attr-val branch September 4, 2016 19:39
cstrassburg pushed a commit that referenced this pull request Dec 10, 2016
Make it possible to match on item attribute and it's value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants