Enable MQTT force update

This commit is contained in:
Dominic Grimm 2024-11-25 19:09:08 +01:00
parent 926b15949d
commit e7e958c757
2 changed files with 7 additions and 0 deletions

View file

@ -92,6 +92,7 @@ pub async fn post_config(
MqttDeviceDiscoveryComponent { MqttDeviceDiscoveryComponent {
platform: "sensor", platform: "sensor",
device_class: "battery", device_class: "battery",
force_update: true,
unit_of_measurement: Some("%"), unit_of_measurement: Some("%"),
value_template: "{{ value_json.battery_level }}", value_template: "{{ value_json.battery_level }}",
unique_id: &unique_id_battery_level, unique_id: &unique_id_battery_level,
@ -102,6 +103,7 @@ pub async fn post_config(
MqttDeviceDiscoveryComponent { MqttDeviceDiscoveryComponent {
platform: "sensor", platform: "sensor",
device_class: "current", device_class: "current",
force_update: true,
unit_of_measurement: Some("mA"), unit_of_measurement: Some("mA"),
value_template: "{{ value_json.battery_current }}", value_template: "{{ value_json.battery_current }}",
unique_id: &unique_id_battery_current, unique_id: &unique_id_battery_current,
@ -112,6 +114,7 @@ pub async fn post_config(
MqttDeviceDiscoveryComponent { MqttDeviceDiscoveryComponent {
platform: "sensor", platform: "sensor",
device_class: "voltage", device_class: "voltage",
force_update: true,
unit_of_measurement: Some("mV"), unit_of_measurement: Some("mV"),
value_template: "{{ value_json.battery_voltage }}", value_template: "{{ value_json.battery_voltage }}",
unique_id: &unique_id_battery_voltage, unique_id: &unique_id_battery_voltage,

View file

@ -210,12 +210,16 @@ pub struct MqttDeviceDiscoveryOrigin<'a> {
pub struct MqttDeviceDiscoveryComponent<'a> { pub struct MqttDeviceDiscoveryComponent<'a> {
#[serde(rename = "p")] #[serde(rename = "p")]
pub platform: &'a str, pub platform: &'a str,
pub device_class: &'a str, pub device_class: &'a str,
pub force_update: bool,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)] #[serde(default)]
pub unit_of_measurement: Option<&'a str>, pub unit_of_measurement: Option<&'a str>,
pub value_template: &'a str, pub value_template: &'a str,
pub unique_id: &'a str, pub unique_id: &'a str,
} }