diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/entity.rs | 2 | ||||
| -rw-r--r-- | src/lib.rs | 38 | ||||
| -rw-r--r-- | src/log.rs | 2 |
3 files changed, 26 insertions, 16 deletions
diff --git a/src/entity.rs b/src/entity.rs index ef2b9ad..e7aa895 100644 --- a/src/entity.rs +++ b/src/entity.rs | |||
| @@ -18,7 +18,7 @@ impl EntityCommonConfig { | |||
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | #[derive(Default)] | 20 | #[derive(Default)] |
| 21 | pub struct EntityConfig { | 21 | pub(crate) struct EntityConfig { |
| 22 | pub id: &'static str, | 22 | pub id: &'static str, |
| 23 | pub name: Option<&'static str>, | 23 | pub name: Option<&'static str>, |
| 24 | pub domain: &'static str, | 24 | pub domain: &'static str, |
| @@ -1,6 +1,7 @@ | |||
| 1 | //! Home Assistant MQTT device library for embassy. | 1 | //! Home Assistant MQTT device library for embassy. |
| 2 | //! | 2 | //! |
| 3 | //! To create a device use the [`new`] function. | 3 | //! To create a device use the [`new`] function. |
| 4 | //! | ||
| 4 | //! After the device is created you should create one or more entities using functions such as | 5 | //! After the device is created you should create one or more entities using functions such as |
| 5 | //! [`create_button`]/[`create_sensor`]/... | 6 | //! [`create_button`]/[`create_sensor`]/... |
| 6 | //! | 7 | //! |
| @@ -30,8 +31,9 @@ use serde::Serialize; | |||
| 30 | 31 | ||
| 31 | mod mqtt; | 32 | mod mqtt; |
| 32 | 33 | ||
| 33 | pub mod log; | 34 | mod log; |
| 34 | pub use log::Format; | 35 | #[allow(unused)] |
| 36 | use log::Format; | ||
| 35 | 37 | ||
| 36 | pub mod constants; | 38 | pub mod constants; |
| 37 | 39 | ||
| @@ -250,73 +252,79 @@ impl Default for DeviceResources { | |||
| 250 | } | 252 | } |
| 251 | 253 | ||
| 252 | #[derive(Debug, Default)] | 254 | #[derive(Debug, Default)] |
| 253 | pub struct ButtonStorage { | 255 | pub(crate) struct ButtonStorage { |
| 254 | pub timestamp: Option<embassy_time::Instant>, | 256 | pub timestamp: Option<embassy_time::Instant>, |
| 255 | pub consumed: bool, | 257 | pub consumed: bool, |
| 256 | } | 258 | } |
| 257 | 259 | ||
| 258 | #[derive(Debug)] | 260 | #[derive(Debug)] |
| 259 | pub struct SwitchCommand { | 261 | pub(crate) struct SwitchCommand { |
| 260 | pub value: BinaryState, | 262 | pub value: BinaryState, |
| 263 | #[allow(unused)] | ||
| 261 | pub timestamp: embassy_time::Instant, | 264 | pub timestamp: embassy_time::Instant, |
| 262 | } | 265 | } |
| 263 | 266 | ||
| 264 | #[derive(Debug)] | 267 | #[derive(Debug)] |
| 265 | pub struct SwitchState { | 268 | pub(crate) struct SwitchState { |
| 266 | pub value: BinaryState, | 269 | pub value: BinaryState, |
| 270 | #[allow(unused)] | ||
| 267 | pub timestamp: embassy_time::Instant, | 271 | pub timestamp: embassy_time::Instant, |
| 268 | } | 272 | } |
| 269 | 273 | ||
| 270 | #[derive(Debug, Default)] | 274 | #[derive(Debug, Default)] |
| 271 | pub struct SwitchStorage { | 275 | pub(crate) struct SwitchStorage { |
| 272 | pub state: Option<SwitchState>, | 276 | pub state: Option<SwitchState>, |
| 273 | pub command: Option<SwitchCommand>, | 277 | pub command: Option<SwitchCommand>, |
| 274 | pub publish_on_command: bool, | 278 | pub publish_on_command: bool, |
| 275 | } | 279 | } |
| 276 | 280 | ||
| 277 | #[derive(Debug)] | 281 | #[derive(Debug)] |
| 278 | pub struct BinarySensorState { | 282 | pub(crate) struct BinarySensorState { |
| 279 | pub value: BinaryState, | 283 | pub value: BinaryState, |
| 284 | #[allow(unused)] | ||
| 280 | pub timestamp: embassy_time::Instant, | 285 | pub timestamp: embassy_time::Instant, |
| 281 | } | 286 | } |
| 282 | 287 | ||
| 283 | #[derive(Debug, Default)] | 288 | #[derive(Debug, Default)] |
| 284 | pub struct BinarySensorStorage { | 289 | pub(crate) struct BinarySensorStorage { |
| 285 | pub state: Option<BinarySensorState>, | 290 | pub state: Option<BinarySensorState>, |
| 286 | } | 291 | } |
| 287 | 292 | ||
| 288 | #[derive(Debug)] | 293 | #[derive(Debug)] |
| 289 | pub struct NumericSensorState { | 294 | pub(crate) struct NumericSensorState { |
| 290 | pub value: f32, | 295 | pub value: f32, |
| 296 | #[allow(unused)] | ||
| 291 | pub timestamp: embassy_time::Instant, | 297 | pub timestamp: embassy_time::Instant, |
| 292 | } | 298 | } |
| 293 | 299 | ||
| 294 | #[derive(Debug, Default)] | 300 | #[derive(Debug, Default)] |
| 295 | pub struct NumericSensorStorage { | 301 | pub(crate) struct NumericSensorStorage { |
| 296 | pub state: Option<NumericSensorState>, | 302 | pub state: Option<NumericSensorState>, |
| 297 | } | 303 | } |
| 298 | 304 | ||
| 299 | #[derive(Debug)] | 305 | #[derive(Debug)] |
| 300 | pub struct NumberState { | 306 | pub(crate) struct NumberState { |
| 301 | pub value: f32, | 307 | pub value: f32, |
| 308 | #[allow(unused)] | ||
| 302 | pub timestamp: embassy_time::Instant, | 309 | pub timestamp: embassy_time::Instant, |
| 303 | } | 310 | } |
| 304 | 311 | ||
| 305 | #[derive(Debug)] | 312 | #[derive(Debug)] |
| 306 | pub struct NumberCommand { | 313 | pub(crate) struct NumberCommand { |
| 307 | pub value: f32, | 314 | pub value: f32, |
| 315 | #[allow(unused)] | ||
| 308 | pub timestamp: embassy_time::Instant, | 316 | pub timestamp: embassy_time::Instant, |
| 309 | } | 317 | } |
| 310 | 318 | ||
| 311 | #[derive(Debug, Default)] | 319 | #[derive(Debug, Default)] |
| 312 | pub struct NumberStorage { | 320 | pub(crate) struct NumberStorage { |
| 313 | pub state: Option<NumberState>, | 321 | pub state: Option<NumberState>, |
| 314 | pub command: Option<NumberCommand>, | 322 | pub command: Option<NumberCommand>, |
| 315 | pub publish_on_command: bool, | 323 | pub publish_on_command: bool, |
| 316 | } | 324 | } |
| 317 | 325 | ||
| 318 | #[derive(Debug)] | 326 | #[derive(Debug)] |
| 319 | pub enum EntityStorage { | 327 | pub(crate) enum EntityStorage { |
| 320 | Button(ButtonStorage), | 328 | Button(ButtonStorage), |
| 321 | Switch(SwitchStorage), | 329 | Switch(SwitchStorage), |
| 322 | BinarySensor(BinarySensorStorage), | 330 | BinarySensor(BinarySensorStorage), |
| @@ -369,7 +377,7 @@ struct EntityData { | |||
| 369 | command_waker: Option<Waker>, | 377 | command_waker: Option<Waker>, |
| 370 | } | 378 | } |
| 371 | 379 | ||
| 372 | pub struct Entity<'a> { | 380 | pub(crate) struct Entity<'a> { |
| 373 | pub(crate) data: &'a RefCell<Option<EntityData>>, | 381 | pub(crate) data: &'a RefCell<Option<EntityData>>, |
| 374 | pub(crate) waker: &'a AtomicWaker, | 382 | pub(crate) waker: &'a AtomicWaker, |
| 375 | } | 383 | } |
| @@ -24,6 +24,7 @@ | |||
| 24 | pub use defmt::Format; | 24 | pub use defmt::Format; |
| 25 | 25 | ||
| 26 | // For tracing or no logging, we provide a stub Format trait | 26 | // For tracing or no logging, we provide a stub Format trait |
| 27 | #[allow(unused)] | ||
| 27 | #[cfg(not(feature = "defmt"))] | 28 | #[cfg(not(feature = "defmt"))] |
| 28 | pub trait Format {} | 29 | pub trait Format {} |
| 29 | 30 | ||
| @@ -113,4 +114,5 @@ macro_rules! error { | |||
| 113 | } | 114 | } |
| 114 | 115 | ||
| 115 | // Re-export the macros at the module level for easier use | 116 | // Re-export the macros at the module level for easier use |
| 117 | #[allow(unused)] | ||
| 116 | pub use crate::{debug, error, info, trace, warn}; | 118 | pub use crate::{debug, error, info, trace, warn}; |
