diff options
| author | diogo464 <[email protected]> | 2025-12-14 14:17:56 +0000 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-12-14 14:17:56 +0000 |
| commit | ab4a7c83e00314a2f5d2f455987ba530fd08bdd7 (patch) | |
| tree | 721360b4ff8f89c08b1c156bd1033e46b9caebe7 | |
| parent | 871b67e886ed9853e3fa392ff33a05c7da09fe9b (diff) | |
added category field to entity discovery payload
| -rw-r--r-- | examples/sensor.rs | 25 | ||||
| -rw-r--r-- | src/lib.rs | 4 |
2 files changed, 29 insertions, 0 deletions
diff --git a/examples/sensor.rs b/examples/sensor.rs index 2fd2d1f..acbb3ab 100644 --- a/examples/sensor.rs +++ b/examples/sensor.rs | |||
| @@ -51,8 +51,25 @@ async fn main_task(spawner: Spawner) { | |||
| 51 | }, | 51 | }, |
| 52 | ); | 52 | ); |
| 53 | 53 | ||
| 54 | let signal_strength_sensor = embassy_ha::create_sensor( | ||
| 55 | &device, | ||
| 56 | "signal-strength-sensor-id", | ||
| 57 | embassy_ha::SensorConfig { | ||
| 58 | common: embassy_ha::EntityCommonConfig { | ||
| 59 | name: Some("Signal Strength"), | ||
| 60 | category: Some(embassy_ha::EntityCategory::Diagnostic), | ||
| 61 | ..Default::default() | ||
| 62 | }, | ||
| 63 | class: embassy_ha::SensorClass::SignalStrength, | ||
| 64 | state_class: embassy_ha::StateClass::Measurement, | ||
| 65 | unit: Some(embassy_ha::constants::HA_UNIT_SIGNAL_STRENGTH_DBM), | ||
| 66 | suggested_display_precision: Some(0), | ||
| 67 | }, | ||
| 68 | ); | ||
| 69 | |||
| 54 | spawner.must_spawn(random_temperature_task(temperature_sensor)); | 70 | spawner.must_spawn(random_temperature_task(temperature_sensor)); |
| 55 | spawner.must_spawn(random_humidity_task(humidity_sensor)); | 71 | spawner.must_spawn(random_humidity_task(humidity_sensor)); |
| 72 | spawner.must_spawn(random_signal_strength_task(signal_strength_sensor)); | ||
| 56 | 73 | ||
| 57 | embassy_ha::run(&mut device, &mut stream).await.unwrap(); | 74 | embassy_ha::run(&mut device, &mut stream).await.unwrap(); |
| 58 | } | 75 | } |
| @@ -73,4 +90,12 @@ async fn random_humidity_task(mut sensor: embassy_ha::Sensor<'static>) { | |||
| 73 | } | 90 | } |
| 74 | } | 91 | } |
| 75 | 92 | ||
| 93 | #[embassy_executor::task] | ||
| 94 | async fn random_signal_strength_task(mut sensor: embassy_ha::Sensor<'static>) { | ||
| 95 | loop { | ||
| 96 | sensor.publish(rand::random_range(-90.0..-30.0)); | ||
| 97 | Timer::after_secs(1).await; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 76 | example_main!(); | 101 | example_main!(); |
| @@ -137,6 +137,9 @@ struct EntityDiscovery<'a> { | |||
| 137 | icon: Option<&'a str>, | 137 | icon: Option<&'a str>, |
| 138 | 138 | ||
| 139 | #[serde(skip_serializing_if = "Option::is_none")] | 139 | #[serde(skip_serializing_if = "Option::is_none")] |
| 140 | entity_category: Option<&'a str>, | ||
| 141 | |||
| 142 | #[serde(skip_serializing_if = "Option::is_none")] | ||
| 140 | entity_picture: Option<&'a str>, | 143 | entity_picture: Option<&'a str>, |
| 141 | 144 | ||
| 142 | #[serde(skip_serializing_if = "Option::is_none")] | 145 | #[serde(skip_serializing_if = "Option::is_none")] |
| @@ -771,6 +774,7 @@ pub async fn run<T: Transport>(device: &mut Device<'_>, transport: &mut T) -> Re | |||
| 771 | platform: entity_config.platform, | 774 | platform: entity_config.platform, |
| 772 | state_class: entity_config.state_class, | 775 | state_class: entity_config.state_class, |
| 773 | icon: entity_config.icon, | 776 | icon: entity_config.icon, |
| 777 | entity_category: entity_config.category, | ||
| 774 | entity_picture: entity_config.picture, | 778 | entity_picture: entity_config.picture, |
| 775 | min: entity_config.min, | 779 | min: entity_config.min, |
| 776 | max: entity_config.max, | 780 | max: entity_config.max, |
