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

Allow stateClass argument for Entity and default state_class to 'meas… #120

Merged
merged 1 commit into from
Oct 8, 2023

Conversation

KidA001
Copy link
Contributor

@KidA001 KidA001 commented Oct 7, 2023

Fixes #119

@neilenns
Copy link
Owner

neilenns commented Oct 7, 2023

This is failing the automated build process:

src/entityManager.ts(93,100): error TS2554: Expected 2-5 arguments, but got 6.

@KidA001
Copy link
Contributor Author

KidA001 commented Oct 7, 2023

This is failing the automated build process:

src/entityManager.ts(93,100): error TS2554: Expected 2-5 arguments, but got 6.

Yup just saw that - didn't realize Sensor class was an extension of Entity updated and re-pushed the commit

@neilenns
Copy link
Owner

neilenns commented Oct 7, 2023

Thanks! Can you provide an example of the updated MQTT details after you've run this with your weather station?

@KidA001
Copy link
Contributor Author

KidA001 commented Oct 8, 2023

Ok so I'm not sure why I thought I could push this PR without fully testing it but thanks for that! Apparently I'm a mere mortal and not a God.

Even though HomeAssistant says the state_class should be None when the device_class is a timestamp, it will throw an error if you provide None. Very odd. It prefers that no state_class is set for a timestamp device.

I set it to null in this case and removed the extra argument to pass state_class.

Currently all of your entities are considered measurements - however if this changes/grows it seems like device_class and state_class should be coupled together. In that case I'd have a function that you pass a device_class and it returns the proper state_class for that device. For now this seems to work and my HA instance didn't throw any errors regarding eventDate anymore!

image image

Commit has been udpated

@neilenns
Copy link
Owner

neilenns commented Oct 8, 2023

HomeAssistant's documentation on this stuff is so bad it drives me crazy.

I'm not wild about explicitly sending the null value for the property in the discovery message. It just shouldn't get sent at all, right? I'd expect the discovery message to have no mention of it at all.

What happens if you set it to undefined instead, or don't set it at all?

@KidA001
Copy link
Contributor Author

KidA001 commented Oct 8, 2023

Yup undefined is the way to go, it doesn't end up even showing in MQTT in that case. Sorry I write more Ruby than I do typescript - I see that's also how you handle icon in entity.ts so better to follow that pattern.

image

Thanks for managing this service, it's nice to have all my weather data in HomeAssistant. Glad I could offer even a little support here.

@neilenns neilenns merged commit 643995b into neilenns:main Oct 8, 2023
4 checks passed
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.

eventDate still returning state_class of 'measurement' - causing errors in HomeAssistant
2 participants