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

Add device_class attribute to battery and WiFi sensors for Home Assistant #1910

Merged
merged 3 commits into from
Oct 26, 2023
Merged

Add device_class attribute to battery and WiFi sensors for Home Assistant #1910

merged 3 commits into from
Oct 26, 2023

Conversation

mill1000
Copy link
Contributor

@mill1000 mill1000 commented Oct 25, 2023

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Docs
  • Refactor/Code Cleanup

Description

This PR add the device_class attribute to the battery and WiFi sensors for Home Assistant. Having a proper device_class attribute allows HA to apply some extra styles to entity.

e.g. For battery level, the icon is color-coded depending on state and the device page shows the battery level

Icon Colored
image
image

Battery On Device Page
image

I didn't notice any obvious changes for the WiFi sensor to report here.

Possible additional changes

The following additional updates might be possible.

  • Current Statistics Time -> DeviceClass.DURATION
  • Total Statistics Time -> DeviceClass.DURATION
  • Consumables -> DeviceClass.DURATION
    • Only if unit !== stateAttrs.ConsumableStateAttribute.UNITS.PERCENT
  • Status Flag -> Maybe DeviceClass.ENUM?
  • Error -> Maybe DeviceClass.ENUM?
    • Or maybe could be refactored to a binary sensor with BinarySensorDeviceClass.PROBLEM

There is also a BinarySensorDeviceClass which can be seen here but I didn't find an applicable classes to the current binary sensors.

A future improvement could expose if an update is available with the UPDATE class.

@Hypfer
Copy link
Owner

Hypfer commented Oct 26, 2023

This is not a bug fix as you initially selected. It's a feature for which there is no category in the PR template because I'm not interested in feature PRs. The reason for that is that they're just more trouble then they're worth.

For example, one thought that comes to mind is "how does this affect the minimum required Home Assistant Version?" because there's a schema validation in HAs MQTT feature meaning that this will break hard on older versions, likely making use of Valetudo impossible.
It might still be reasonable to do that but that all depends on how old that minimum required version is.

Did you consider those implications? Probably not.
Which is generally fine, because a lot of projects operate like that but this one doesn't.

A future improvement could expose if an update is available with the UPDATE class.

No, absolutely not. That will never happen. See also #1890
No further input or opinions required on that btw. Not interested.

@Hypfer Hypfer closed this Oct 26, 2023
@mill1000
Copy link
Contributor Author

Wow. I'm sorry, I didn't know. I understand you're just trying to protect your sanity (e.g. #1664), and I appreciate the work you've done but it saddens me to see such hostility towards potential contributors.

For example, one thought that comes to mind is "how does this affect the minimum required Home Assistant Version?" because there's a schema validation in HAs MQTT feature meaning that this will break hard on older versions,
...
Did you consider those implications? Probably not.

You're right. I hadn't and that's a very valid concern. Personally, I think the beauty of PRs is that we can have that discussion now.

FWIW
The device_class function was added 5 years ago: home-assistant/core#14033
There was a recent related bug fix in Jan 2023: home-assistant/core#85106

Additionally the MQTT discovery documentation (https://www.home-assistant.io/integrations/mqtt#discovery-payload) indicates that unknown keys are ignored to in effort to allow backwards compatibility.

Regards,
Tucker

@Hypfer
Copy link
Owner

Hypfer commented Oct 26, 2023

it saddens me to see such hostility towards potential contributors.

I do get that perspective but IMO that is part of that fake story about FOSS, big corpo started telling people to get them to exploit themselves for corporate profits.

The probably a bit harsh truth there is that for this project, contributers 80% of the time are a net negative. They take time to deal with, they usually add stuff to the codebase that then needs to be maintained by yours truly and at the end of the day they're "solving" something there is no shortage of: Coding.

I can do the coding just fine - after all that's why the project even exists.
It doesn't help me if someone does the things that I find enjoyable for me and then leaves me with a bunch of new things that I have to do instead which aren't that. Some mildly while others not at all.


I hope you don't take this personally because it's not a personal issue. It's cultural.

Every talking head on the internet tells you that you should contribute because contributing is oh so great, then you do invest the time to actually do that and then suddenly the maintainer tells you to F off.

What a frustrating experience for everyone involved. Everyone but the talking heads of course who continue to bring this nonsense upon random people for their own personal gain.



aaanyway, I do very much appreciate that you took the time to put in the effort of researching if there might be any trouble with that change even after having received this rather harsh reply!

@Hypfer Hypfer reopened this Oct 26, 2023
@Hypfer Hypfer merged commit aac0f51 into Hypfer:master Oct 26, 2023
7 checks passed
@mill1000 mill1000 deleted the feature/ha_device_class branch October 26, 2023 19:03
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.

2 participants