Skip to content

Always send sensor registration device class + entity category to prevent errors due to old registration #3977

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

Merged
merged 2 commits into from
Oct 28, 2023

Conversation

jpelgrom
Copy link
Member

Summary

Fixes #3202, fixes home-assistant/core#102853

Always send the values for device_class and entity_category when registering sensors to make sure they match the app value. Some sensors were changed in the past based on feedback, but users with existing registrations wouldn't have seen this updated in core as the app didn't send null values instead of sending that it should be null. To make this possible, registrations and updates need to be split as the app currently depends on using null as "don't send".

Example before/after payloads:

{"type":"register_sensor","data":{"unique_id":"battery_state","state":"discharging","type":"sensor","icon":"mdi:battery-minus","attributes":{},"name":"Battery state","entity_category":"diagnostic","disabled":false}}
{"type":"register_sensor","data":{"unique_id":"battery_state","state":"discharging","type":"sensor","icon":"mdi:battery-minus","attributes":{},"name":"Battery state","device_class":null,"entity_category":"diagnostic","disabled":false}}

{"type":"register_sensor","data":{"unique_id":"audio_sensor","state":"normal","type":"sensor","icon":"mdi:volume-high","attributes":{},"name":"Ringer mode","disabled":false}}
{"type":"register_sensor","data":{"unique_id":"audio_sensor","state":"normal","type":"sensor","icon":"mdi:volume-high","attributes":{},"name":"Ringer mode","device_class":null,"entity_category":null,"disabled":false}}

Screenshots

n/a

Link to pull request in Documentation repository

n/a

Any other notes

Requires home-assistant/core#86965, which was first included in 2023.2.0.

 - Always send the device class for a sensor during registration to overwrite any existing invalid values
@jpelgrom jpelgrom changed the title Always send sensor device class and entity category on update to prevent errors Always send sensor device class and entity category on registration to prevent errors Oct 27, 2023
@jpelgrom jpelgrom changed the title Always send sensor device class and entity category on registration to prevent errors Always send sensor registration device class + entity category to prevent errors due to old registration Oct 27, 2023
Copy link
Member

@dshokouhi dshokouhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix 🙏 !

I think we may want to opt to cut a release alongside HA core 2023.11 otherwise we may get more noise on this issue. I think this was one of the original sensors enabled by default for all users before we broke up attributes so could have a fair amount of users impacted by it depending on when they first setup the app.

@JBassett JBassett merged commit e8815f1 into home-assistant:master Oct 28, 2023
@jpelgrom jpelgrom deleted the fix-3202 branch October 28, 2023 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants