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
Breaking change: send sensor list attributes as list to server #2478
Breaking change: send sensor list attributes as list to server #2478
Conversation
- Send a sensor attribute that is managed by the app as a list, to the server as a list as well instead of a stringified version of a list.
- To prevent issues where we can't distinguish the list items separator from a value that includes the separator, don't try to convert a value to a list if that is the case but instead use string
Not related to the changes here but on this subject we do have this long standing bug: #1206 I don't believe there are any other places other than what you have listed where this occurs |
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.
Tested the debug APK and it checks out fine to me.
- Instead of only falling back when a list includes a String with the separator, just use toString() to also support other objects which might include ", " when stringified, such as nested lists
I've looked at the issue and believe that I've fixed it, see pull request #2482. Now the notification sensors will almost certainly get lists in their attributes 🙂. It's been tested in combination with this PR and I've made a small change to prevent problems when merged. |
A concern raised here: the fallback to a string in case there is a ", " in the stringified list values may produce inconsistent attribute value types.
Edit: did a quick test using |
- To remove any confusion when sending individual list items, store data as JSON to escape characters if necessary - Map Any data in a list that is not any of the specific types to string, for consistency with the same types when not in a list and to prevent JSON serialization issues
Updated to store lists as JSON in the database, which escapes any problematic characters, so now users can be sure that lists are always sent as lists. List values will always be booleans, ints, longs, floats or, if not one of the previous types, strings using I also looked into storing all other types as JSON, which might be interesting when #2482 is merged because that code will allow (nested) key/value maps as attributes. Unfortunately Jackson's serialization of some classes throws exceptions (for example, |
Can someone confirm this one works as expected for bluetooth connection or other sensors? I just checked in beta-2300-f33743dc published last week and now
Maybe we need to reopen #2474 |
I can confirm it is working correctly for me, tested just now with the Bluetooth Connection sensor on a build based on beta-2310. If they were still strings, I would expect to see Did you copy these values from the 'more info' panel or frontend dev tools states table? I think the frontend will only show lists as lists if you open the 'Set State' panel in the dev tools, otherwise it shows lists as a string with comma separated items. |
Oh, indeed that's what I did. I can confirm it shows as a list using 'Set State'. Sorry about that and thanks again! I am going to have some fun with the for each loop now. 😛 |
Summary
When the app collects sensor attributes, it is stored in the app's database as a string and converted back to it's original type when sent to the server, if possible. This PR updates the "if possible" part to also include lists. This will allow users to use array features in HA templating for these values.
Because this changes the format for attribute values, this is a breaking change. Based on a quick search, this will have changes for the following sensors:
I've tested this with core 2022.4.7. Fixes #2474.
Screenshots
n/a
Link to pull request in Documentation repository
n/a
Any other notes