diff options
| author | diogo464 <[email protected]> | 2025-12-05 12:17:01 +0000 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-12-05 12:17:01 +0000 |
| commit | 0c86da392af50c7588b087c3f72602e8368af65e (patch) | |
| tree | 894cd2f353298b83a56cde06eafd7b1e366aa6b3 /examples | |
| parent | 1d2ee64d0ec917a2c2b66f8d58e1f37dd174a89d (diff) | |
reworked entity creation
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/binary_sensor.rs | 9 | ||||
| -rw-r--r-- | examples/button.rs | 2 | ||||
| -rw-r--r-- | examples/number.rs | 16 | ||||
| -rw-r--r-- | examples/switch.rs | 11 | ||||
| -rw-r--r-- | examples/temperature.rs | 18 |
5 files changed, 47 insertions, 9 deletions
diff --git a/examples/binary_sensor.rs b/examples/binary_sensor.rs index 2809255..c0afa4a 100644 --- a/examples/binary_sensor.rs +++ b/examples/binary_sensor.rs | |||
| @@ -23,8 +23,13 @@ async fn main_task(spawner: Spawner) { | |||
| 23 | 23 | ||
| 24 | let sensor = device.create_binary_sensor( | 24 | let sensor = device.create_binary_sensor( |
| 25 | "binary-sensor-id", | 25 | "binary-sensor-id", |
| 26 | "Binary Sensor", | 26 | embassy_ha::BinarySensorConfig { |
| 27 | embassy_ha::constants::HA_DEVICE_CLASS_BINARY_SENSOR_SMOKE, | 27 | common: embassy_ha::EntityCommonConfig { |
| 28 | name: Some("Binary Sensor"), | ||
| 29 | ..Default::default() | ||
| 30 | }, | ||
| 31 | class: embassy_ha::BinarySensorClass::Smoke, | ||
| 32 | }, | ||
| 28 | ); | 33 | ); |
| 29 | 34 | ||
| 30 | spawner.must_spawn(binary_sensor_class(sensor)); | 35 | spawner.must_spawn(binary_sensor_class(sensor)); |
diff --git a/examples/button.rs b/examples/button.rs index cfef3e3..3ac1de8 100644 --- a/examples/button.rs +++ b/examples/button.rs | |||
| @@ -20,7 +20,7 @@ async fn main_task(spawner: Spawner) { | |||
| 20 | }, | 20 | }, |
| 21 | ); | 21 | ); |
| 22 | 22 | ||
| 23 | let button = device.create_button("button-sensor-id", "Button Name"); | 23 | let button = device.create_button("button-sensor-id", embassy_ha::ButtonConfig::default()); |
| 24 | 24 | ||
| 25 | spawner.must_spawn(button_task(button)); | 25 | spawner.must_spawn(button_task(button)); |
| 26 | 26 | ||
diff --git a/examples/number.rs b/examples/number.rs index 78307d6..4e7fe1c 100644 --- a/examples/number.rs +++ b/examples/number.rs | |||
| @@ -21,7 +21,21 @@ async fn main_task(spawner: Spawner) { | |||
| 21 | }, | 21 | }, |
| 22 | ); | 22 | ); |
| 23 | 23 | ||
| 24 | let number = device.create_number("number-id", "Number Name"); | 24 | let number = device.create_number( |
| 25 | "number-id", | ||
| 26 | embassy_ha::NumberConfig { | ||
| 27 | common: embassy_ha::EntityCommonConfig { | ||
| 28 | name: Some("Number Name"), | ||
| 29 | ..Default::default() | ||
| 30 | }, | ||
| 31 | unit: Some(embassy_ha::NumberUnit::Meter), | ||
| 32 | min: Some(0.0), | ||
| 33 | max: Some(20.0), | ||
| 34 | step: Some(0.5), | ||
| 35 | mode: embassy_ha::NumberMode::Slider, | ||
| 36 | class: embassy_ha::NumberClass::Distance, | ||
| 37 | }, | ||
| 38 | ); | ||
| 25 | 39 | ||
| 26 | spawner.must_spawn(number_task(number)); | 40 | spawner.must_spawn(number_task(number)); |
| 27 | 41 | ||
diff --git a/examples/switch.rs b/examples/switch.rs index a12b8d0..815a0f9 100644 --- a/examples/switch.rs +++ b/examples/switch.rs | |||
| @@ -21,7 +21,16 @@ async fn main_task(spawner: Spawner) { | |||
| 21 | }, | 21 | }, |
| 22 | ); | 22 | ); |
| 23 | 23 | ||
| 24 | let switch = device.create_switch("switch-id", "Example Switch"); | 24 | let switch = device.create_switch( |
| 25 | "switch-id", | ||
| 26 | embassy_ha::SwitchConfig { | ||
| 27 | common: embassy_ha::EntityCommonConfig { | ||
| 28 | name: Some("Example Switch"), | ||
| 29 | ..Default::default() | ||
| 30 | }, | ||
| 31 | ..Default::default() | ||
| 32 | }, | ||
| 33 | ); | ||
| 25 | 34 | ||
| 26 | spawner.must_spawn(switch_task(switch)); | 35 | spawner.must_spawn(switch_task(switch)); |
| 27 | 36 | ||
diff --git a/examples/temperature.rs b/examples/temperature.rs index 32f4887..4cf0d42 100644 --- a/examples/temperature.rs +++ b/examples/temperature.rs | |||
| @@ -23,14 +23,24 @@ async fn main_task(spawner: Spawner) { | |||
| 23 | 23 | ||
| 24 | let constant_temperature_sensor = device.create_temperature_sensor( | 24 | let constant_temperature_sensor = device.create_temperature_sensor( |
| 25 | "constant-temperature-sensor-id", | 25 | "constant-temperature-sensor-id", |
| 26 | "Constant Temperature Sensor", | 26 | embassy_ha::TemperatureSensorConfig { |
| 27 | embassy_ha::TemperatureUnit::Celcius, | 27 | common: embassy_ha::EntityCommonConfig { |
| 28 | name: Some("Constant Temperature Sensor"), | ||
| 29 | ..Default::default() | ||
| 30 | }, | ||
| 31 | unit: embassy_ha::TemperatureUnit::Celcius, | ||
| 32 | }, | ||
| 28 | ); | 33 | ); |
| 29 | 34 | ||
| 30 | let random_temperature_sensor = device.create_temperature_sensor( | 35 | let random_temperature_sensor = device.create_temperature_sensor( |
| 31 | "random-temperature-sensor-id", | 36 | "random-temperature-sensor-id", |
| 32 | "Random Temperature Sensor", | 37 | embassy_ha::TemperatureSensorConfig { |
| 33 | embassy_ha::TemperatureUnit::Celcius, | 38 | common: embassy_ha::EntityCommonConfig { |
| 39 | name: Some("Random Temperature Sensor"), | ||
| 40 | ..Default::default() | ||
| 41 | }, | ||
| 42 | unit: embassy_ha::TemperatureUnit::Celcius, | ||
| 43 | }, | ||
| 34 | ); | 44 | ); |
| 35 | 45 | ||
| 36 | spawner.must_spawn(constant_temperature_task(constant_temperature_sensor)); | 46 | spawner.must_spawn(constant_temperature_task(constant_temperature_sensor)); |
