-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Home Assistant event
entities, part 2
#24717
Conversation
mundschenk-at
commented
Nov 10, 2024
- Adds parsing support for Hue Tap actions.
- Refactors action parsing (for the Z2M and HA sides).
@Koenkk There are probably some more action types we should parse, do you want that all in one big PR or several smaller ones? |
@mundschenk-at whatever you prefer, I reviewed this one and it looks good. Let me know if I can merge it. |
@Koenkk OK, then I'd say let's get this into |
Thanks! |
` {% set ns.r = ns.r|rejectattr(0, 'eq', 'action')|list + [('action', ns.r|selectattr(0, 'eq', 'actionPrefix')|map(attribute=1)|first + ns.r|selectattr(0, 'eq', 'action')|map(attribute=1)|first)] %}\n` + | ||
`{% endif %}\n` + | ||
`{% set ns.r = ns.r + [('event_type', ns.r|selectattr(0, 'eq', 'action')|map(attribute=1)|first)] %}\n` + | ||
`{{dict.from_keys(ns.r|rejectattr(0, 'in', 'action, actionPrefix'))|to_json}}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mundschenk-at: I'm working on making openHAB compatible with event entities from z2m. I've worked through several constructs Jinjava/openHAB didn't previously support, but now I'm working on dict.from_keys
. AFAICT, this is not the Python built in dict.fromkeys method (that method would set the value of all entries to None
, and testing this template in Home Assistant does not have that issue), but I can't find it explicitly defined in Home Assistant core's template extensions nor in Jinja itself. Do you know where it comes from, and can point me to source code or documentation on it? Or at least a high level description? My guess is that it takes a list of lists (of two items), and returns a new dict with each of those as key and value entries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ccutrer HA uses Jinja2, so I assume it would be a builtin (builtin-globals.dict
)? I've had a look at the source on GitHub and could not really make heads or tails of it. I just got the usage from the HA forum. However, I've no experimented and it appears the from_keys
is unnecessary, you can simple use the dict()
constructor to create the dictionary from the list of tuples. I'll simplify the template, once we have decided how to continue with event
.
{{dict(ns.r|rejectattr(0, 'in', 'action, actionPrefix'))|to_json}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh that would be good. dict.from_keys
doesn't exist in the base python3/jinja2 install on my Ubuntu box, but it does work within Home Assistant running on a pi.