diff options
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 38 |
1 files changed, 25 insertions, 13 deletions
| @@ -485,8 +485,10 @@ pub fn create_sensor<'a>( | |||
| 485 | id: &'static str, | 485 | id: &'static str, |
| 486 | config: SensorConfig, | 486 | config: SensorConfig, |
| 487 | ) -> Sensor<'a> { | 487 | ) -> Sensor<'a> { |
| 488 | let mut entity_config = EntityConfig::default(); | 488 | let mut entity_config = EntityConfig { |
| 489 | entity_config.id = id; | 489 | id, |
| 490 | ..Default::default() | ||
| 491 | }; | ||
| 490 | config.populate(&mut entity_config); | 492 | config.populate(&mut entity_config); |
| 491 | 493 | ||
| 492 | let entity = create_entity( | 494 | let entity = create_entity( |
| @@ -502,8 +504,10 @@ pub fn create_button<'a>( | |||
| 502 | id: &'static str, | 504 | id: &'static str, |
| 503 | config: ButtonConfig, | 505 | config: ButtonConfig, |
| 504 | ) -> Button<'a> { | 506 | ) -> Button<'a> { |
| 505 | let mut entity_config = EntityConfig::default(); | 507 | let mut entity_config = EntityConfig { |
| 506 | entity_config.id = id; | 508 | id, |
| 509 | ..Default::default() | ||
| 510 | }; | ||
| 507 | config.populate(&mut entity_config); | 511 | config.populate(&mut entity_config); |
| 508 | 512 | ||
| 509 | let entity = create_entity( | 513 | let entity = create_entity( |
| @@ -519,8 +523,10 @@ pub fn create_number<'a>( | |||
| 519 | id: &'static str, | 523 | id: &'static str, |
| 520 | config: NumberConfig, | 524 | config: NumberConfig, |
| 521 | ) -> Number<'a> { | 525 | ) -> Number<'a> { |
| 522 | let mut entity_config = EntityConfig::default(); | 526 | let mut entity_config = EntityConfig { |
| 523 | entity_config.id = id; | 527 | id, |
| 528 | ..Default::default() | ||
| 529 | }; | ||
| 524 | config.populate(&mut entity_config); | 530 | config.populate(&mut entity_config); |
| 525 | 531 | ||
| 526 | let entity = create_entity( | 532 | let entity = create_entity( |
| @@ -539,8 +545,10 @@ pub fn create_switch<'a>( | |||
| 539 | id: &'static str, | 545 | id: &'static str, |
| 540 | config: SwitchConfig, | 546 | config: SwitchConfig, |
| 541 | ) -> Switch<'a> { | 547 | ) -> Switch<'a> { |
| 542 | let mut entity_config = EntityConfig::default(); | 548 | let mut entity_config = EntityConfig { |
| 543 | entity_config.id = id; | 549 | id, |
| 550 | ..Default::default() | ||
| 551 | }; | ||
| 544 | config.populate(&mut entity_config); | 552 | config.populate(&mut entity_config); |
| 545 | 553 | ||
| 546 | let entity = create_entity( | 554 | let entity = create_entity( |
| @@ -559,8 +567,10 @@ pub fn create_binary_sensor<'a>( | |||
| 559 | id: &'static str, | 567 | id: &'static str, |
| 560 | config: BinarySensorConfig, | 568 | config: BinarySensorConfig, |
| 561 | ) -> BinarySensor<'a> { | 569 | ) -> BinarySensor<'a> { |
| 562 | let mut entity_config = EntityConfig::default(); | 570 | let mut entity_config = EntityConfig { |
| 563 | entity_config.id = id; | 571 | id, |
| 572 | ..Default::default() | ||
| 573 | }; | ||
| 564 | config.populate(&mut entity_config); | 574 | config.populate(&mut entity_config); |
| 565 | 575 | ||
| 566 | let entity = create_entity( | 576 | let entity = create_entity( |
| @@ -693,7 +703,7 @@ pub async fn run<T: Transport>(device: &mut Device<'_>, transport: &mut T) -> Re | |||
| 693 | .discovery_buffer | 703 | .discovery_buffer |
| 694 | .resize(device.discovery_buffer.capacity(), 0) | 704 | .resize(device.discovery_buffer.capacity(), 0) |
| 695 | .unwrap(); | 705 | .unwrap(); |
| 696 | let n = serde_json_core::to_slice(&discovery, &mut device.discovery_buffer) | 706 | let n = serde_json_core::to_slice(&discovery, device.discovery_buffer) |
| 697 | .expect("discovery buffer too small"); | 707 | .expect("discovery buffer too small"); |
| 698 | device.discovery_buffer.truncate(n); | 708 | device.discovery_buffer.truncate(n); |
| 699 | } | 709 | } |
| @@ -702,7 +712,7 @@ pub async fn run<T: Transport>(device: &mut Device<'_>, transport: &mut T) -> Re | |||
| 702 | crate::log::debug!("sending discovery to topic '{}'", discovery_topic); | 712 | crate::log::debug!("sending discovery to topic '{}'", discovery_topic); |
| 703 | match embassy_time::with_timeout( | 713 | match embassy_time::with_timeout( |
| 704 | MQTT_TIMEOUT, | 714 | MQTT_TIMEOUT, |
| 705 | client.publish(discovery_topic, &device.discovery_buffer), | 715 | client.publish(discovery_topic, device.discovery_buffer), |
| 706 | ) | 716 | ) |
| 707 | .await | 717 | .await |
| 708 | { | 718 | { |
| @@ -1077,10 +1087,12 @@ pub async fn connect_and_run( | |||
| 1077 | } | 1087 | } |
| 1078 | }; | 1088 | }; |
| 1079 | 1089 | ||
| 1090 | #[allow(unreachable_patterns)] | ||
| 1080 | let ipv4_addr = match addrs | 1091 | let ipv4_addr = match addrs |
| 1081 | .iter() | 1092 | .iter() |
| 1082 | .filter_map(|addr| match addr { | 1093 | .filter_map(|addr| match addr { |
| 1083 | embassy_net::IpAddress::Ipv4(ipv4) => Some((*ipv4).into()), | 1094 | embassy_net::IpAddress::Ipv4(ipv4) => Some(*ipv4), |
| 1095 | _ => None, | ||
| 1084 | }) | 1096 | }) |
| 1085 | .next() | 1097 | .next() |
| 1086 | { | 1098 | { |
