diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/command_policy.rs | 7 | ||||
| -rw-r--r-- | src/entity_switch.rs | 10 | ||||
| -rw-r--r-- | src/lib.rs | 2 |
3 files changed, 4 insertions, 15 deletions
diff --git a/src/command_policy.rs b/src/command_policy.rs index 049d56a..e5859bb 100644 --- a/src/command_policy.rs +++ b/src/command_policy.rs | |||
| @@ -64,16 +64,13 @@ | |||
| 64 | /// # async fn turn_on_motor() -> Result<(), ()> { Ok(()) } | 64 | /// # async fn turn_on_motor() -> Result<(), ()> { Ok(()) } |
| 65 | /// ``` | 65 | /// ``` |
| 66 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 66 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 67 | #[derive(Default)] | ||
| 67 | pub enum CommandPolicy { | 68 | pub enum CommandPolicy { |
| 68 | /// Automatically publish the entity's state when a command is received. | 69 | /// Automatically publish the entity's state when a command is received. |
| 70 | #[default] | ||
| 69 | PublishState, | 71 | PublishState, |
| 70 | 72 | ||
| 71 | /// Do not automatically publish state. The application must manually update the state. | 73 | /// Do not automatically publish state. The application must manually update the state. |
| 72 | Manual, | 74 | Manual, |
| 73 | } | 75 | } |
| 74 | 76 | ||
| 75 | impl Default for CommandPolicy { | ||
| 76 | fn default() -> Self { | ||
| 77 | Self::PublishState | ||
| 78 | } | ||
| 79 | } | ||
diff --git a/src/entity_switch.rs b/src/entity_switch.rs index c1531eb..2b799a1 100644 --- a/src/entity_switch.rs +++ b/src/entity_switch.rs | |||
| @@ -15,21 +15,13 @@ pub enum SwitchClass { | |||
| 15 | /// | 15 | /// |
| 16 | /// See [`CommandPolicy`] for details on how commands are handled. | 16 | /// See [`CommandPolicy`] for details on how commands are handled. |
| 17 | #[derive(Debug)] | 17 | #[derive(Debug)] |
| 18 | #[derive(Default)] | ||
| 18 | pub struct SwitchConfig { | 19 | pub struct SwitchConfig { |
| 19 | pub common: EntityCommonConfig, | 20 | pub common: EntityCommonConfig, |
| 20 | pub class: SwitchClass, | 21 | pub class: SwitchClass, |
| 21 | pub command_policy: CommandPolicy, | 22 | pub command_policy: CommandPolicy, |
| 22 | } | 23 | } |
| 23 | 24 | ||
| 24 | impl Default for SwitchConfig { | ||
| 25 | fn default() -> Self { | ||
| 26 | Self { | ||
| 27 | common: Default::default(), | ||
| 28 | class: Default::default(), | ||
| 29 | command_policy: CommandPolicy::default(), | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
| 33 | 25 | ||
| 34 | impl SwitchConfig { | 26 | impl SwitchConfig { |
| 35 | pub(crate) fn populate(&self, config: &mut EntityConfig) { | 27 | pub(crate) fn populate(&self, config: &mut EntityConfig) { |
| @@ -1047,7 +1047,7 @@ pub async fn run<T: Transport>(device: &mut Device<'_>, transport: &mut T) -> Re | |||
| 1047 | .resize(device.publish_buffer.capacity(), 0) | 1047 | .resize(device.publish_buffer.capacity(), 0) |
| 1048 | .expect("resize to capacity should never fail"); | 1048 | .expect("resize to capacity should never fail"); |
| 1049 | let n = | 1049 | let n = |
| 1050 | serde_json_core::to_slice(&tracker_state, &mut device.publish_buffer) | 1050 | serde_json_core::to_slice(&tracker_state, device.publish_buffer) |
| 1051 | .expect("publish buffer too small for tracker state payload"); | 1051 | .expect("publish buffer too small for tracker state payload"); |
| 1052 | device.publish_buffer.truncate(n); | 1052 | device.publish_buffer.truncate(n); |
| 1053 | } | 1053 | } |
