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

improvement: add base class for hass discovery #1137

Closed

Conversation

AndreasBoehm
Copy link
Member

I started to refactor how we build hass discovery as an outcome of this comment: #1136 (comment)

My idea is to create MqttHassPublisher as a library with static methods that can be used to publish sensors, buttons, fields and helpers like createDeviceInfo.

@AndreasBoehm
Copy link
Member Author

AndreasBoehm commented Jul 26, 2024

@schlimmchen I already added createDeviceInfo and publish as an example in this MR to check with you if i am going into the right direction.

@AndreasBoehm
Copy link
Member Author

AndreasBoehm commented Jul 26, 2024

I also added publishBinarySensor2 in MqttHandleBatteryHassClass as a start to get the publish*Sensor methods into the library. Its a rough draft but it would be great if you can give your input on that method as well.

To make it work with even less code we would need to change MqttHassPublisher (with a better name of course) to be the base class for all MqttHandle*HassClass-es and make them implement a couple of methods like configTopicPrefix(), uniqueIdentifier() and deviceInfo() that we can then use inside publish*Sensor without repeating the same code over and over.

I would also suggest a strategy switch to type sensorIds manually instead of generating them from the caption, this will also allow us to rename captions without breaking the hass entities.

@AndreasBoehm AndreasBoehm force-pushed the chore/refactor-hass branch 4 times, most recently from 882c7bb to 817f72c Compare July 26, 2024 23:30
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new discussion or issue for related concerns.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant