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

Home Assistant event entities, part 2 #24717

Merged
merged 3 commits into from
Nov 11, 2024

Conversation

mundschenk-at
Copy link
Contributor

  • Adds parsing support for Hue Tap actions.
  • Refactors action parsing (for the Z2M and HA sides).

@mundschenk-at
Copy link
Contributor Author

@Koenkk There are probably some more action types we should parse, do you want that all in one big PR or several smaller ones?

@Koenkk
Copy link
Owner

Koenkk commented Nov 11, 2024

@mundschenk-at whatever you prefer, I reviewed this one and it looks good. Let me know if I can merge it.

@mundschenk-at
Copy link
Contributor Author

@Koenkk OK, then I'd say let's get this into dev and I'll do an additional PR for the remaining wildcard actions (and maybe semi-systematic review of other action payloads) when I get around to it.

@Koenkk Koenkk merged commit 22e13c5 into Koenkk:dev Nov 11, 2024
11 checks passed
@Koenkk
Copy link
Owner

Koenkk commented Nov 11, 2024

Thanks!

@mundschenk-at mundschenk-at deleted the homeassistant-events-part2 branch November 11, 2024 21:13
` {% 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}}`;
Copy link
Contributor

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?

Copy link
Contributor Author

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}}

Copy link
Contributor

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.

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.

3 participants