Closed AndreasBoehm closed 1 month ago
@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.
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.
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.
I started to refactor how we build hass discovery as an outcome of this comment: https://github.com/helgeerbe/OpenDTU-OnBattery/pull/1136#issuecomment-2253279029
My idea is to create
MqttHassPublisher
as a library with static methods that can be used to publish sensors, buttons, fields and helpers likecreateDeviceInfo
.