aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2026-01-20 15:00:53 +0000
committerdiogo464 <[email protected]>2026-01-20 15:00:53 +0000
commit4402ce6478027d48435eb937087690ae41f152c1 (patch)
tree6e9a984a78ff67c6fb447ac928fdb1481732d74c /src
parentfde795c093c0392988cae4690b8ef85483d30162 (diff)
cargo fmt
Diffstat (limited to 'src')
-rw-r--r--src/command_policy.rs4
-rw-r--r--src/entity_sensor.rs4
-rw-r--r--src/entity_switch.rs4
-rw-r--r--src/mqtt/rx.rs18
-rw-r--r--src/mqtt/tx.rs1
5 files changed, 16 insertions, 15 deletions
diff --git a/src/command_policy.rs b/src/command_policy.rs
index e5859bb..a1bb3bf 100644
--- a/src/command_policy.rs
+++ b/src/command_policy.rs
@@ -63,8 +63,7 @@
63/// # } 63/// # }
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, Default)]
67#[derive(Default)]
68pub enum CommandPolicy { 67pub enum CommandPolicy {
69 /// Automatically publish the entity's state when a command is received. 68 /// Automatically publish the entity's state when a command is received.
70 #[default] 69 #[default]
@@ -73,4 +72,3 @@ pub enum CommandPolicy {
73 /// Do not automatically publish state. The application must manually update the state. 72 /// Do not automatically publish state. The application must manually update the state.
74 Manual, 73 Manual,
75} 74}
76
diff --git a/src/entity_sensor.rs b/src/entity_sensor.rs
index e221141..fd5e7f7 100644
--- a/src/entity_sensor.rs
+++ b/src/entity_sensor.rs
@@ -18,8 +18,7 @@ impl StateClass {
18 } 18 }
19} 19}
20 20
21#[derive(Debug, Clone, Copy, PartialEq, Eq)] 21#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
22#[derive(Default)]
23pub enum SensorClass { 22pub enum SensorClass {
24 #[default] 23 #[default]
25 Generic, 24 Generic,
@@ -77,7 +76,6 @@ pub enum SensorClass {
77 Other(&'static str), 76 Other(&'static str),
78} 77}
79 78
80
81impl SensorClass { 79impl SensorClass {
82 pub fn as_str(&self) -> Option<&'static str> { 80 pub fn as_str(&self) -> Option<&'static str> {
83 match self { 81 match self {
diff --git a/src/entity_switch.rs b/src/entity_switch.rs
index 2b799a1..b685ce5 100644
--- a/src/entity_switch.rs
+++ b/src/entity_switch.rs
@@ -14,15 +14,13 @@ pub enum SwitchClass {
14/// Configuration for a switch entity. 14/// Configuration for a switch entity.
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, Default)]
18#[derive(Default)]
19pub struct SwitchConfig { 18pub struct SwitchConfig {
20 pub common: EntityCommonConfig, 19 pub common: EntityCommonConfig,
21 pub class: SwitchClass, 20 pub class: SwitchClass,
22 pub command_policy: CommandPolicy, 21 pub command_policy: CommandPolicy,
23} 22}
24 23
25
26impl SwitchConfig { 24impl SwitchConfig {
27 pub(crate) fn populate(&self, config: &mut EntityConfig) { 25 pub(crate) fn populate(&self, config: &mut EntityConfig) {
28 self.common.populate(config); 26 self.common.populate(config);
diff --git a/src/mqtt/rx.rs b/src/mqtt/rx.rs
index 10b775a..0dfd858 100644
--- a/src/mqtt/rx.rs
+++ b/src/mqtt/rx.rs
@@ -37,7 +37,9 @@ impl From<varint::Error> for Error {
37 fn from(value: varint::Error) -> Self { 37 fn from(value: varint::Error) -> Self {
38 match value { 38 match value {
39 varint::Error::NeedMoreData => Self::NeedMoreData, 39 varint::Error::NeedMoreData => Self::NeedMoreData,
40 varint::Error::InvalidVarInt => Self::InvalidPacket("invalid variable integer encoding"), 40 varint::Error::InvalidVarInt => {
41 Self::InvalidPacket("invalid variable integer encoding")
42 }
41 } 43 }
42 } 44 }
43} 45}
@@ -92,8 +94,10 @@ pub fn decode<'a>(buf: &'a [u8]) -> Result<(Packet<'a>, usize), Error> {
92 protocol::PACKET_TYPE_PUBLISH => { 94 protocol::PACKET_TYPE_PUBLISH => {
93 // Extract flags from the fixed header 95 // Extract flags from the fixed header
94 let retain = (packet_flags & protocol::PUBLISH_FLAG_RETAIN) != 0; 96 let retain = (packet_flags & protocol::PUBLISH_FLAG_RETAIN) != 0;
95 let qos_value = (packet_flags & protocol::PUBLISH_FLAG_QOS_MASK) >> protocol::PUBLISH_FLAG_QOS_SHIFT; 97 let qos_value = (packet_flags & protocol::PUBLISH_FLAG_QOS_MASK)
96 let qos = Qos::from_u8(qos_value).ok_or(Error::InvalidPacket("PUBLISH has invalid QoS value"))?; 98 >> protocol::PUBLISH_FLAG_QOS_SHIFT;
99 let qos = Qos::from_u8(qos_value)
100 .ok_or(Error::InvalidPacket("PUBLISH has invalid QoS value"))?;
97 let dup = (packet_flags & protocol::PUBLISH_FLAG_DUP) != 0; 101 let dup = (packet_flags & protocol::PUBLISH_FLAG_DUP) != 0;
98 102
99 // Track position after fixed header to calculate data length 103 // Track position after fixed header to calculate data length
@@ -113,7 +117,9 @@ pub fn decode<'a>(buf: &'a [u8]) -> Result<(Packet<'a>, usize), Error> {
113 let variable_header_len = reader.num_read() - variable_header_start; 117 let variable_header_len = reader.num_read() - variable_header_start;
114 let data_len = (packet_len as usize) 118 let data_len = (packet_len as usize)
115 .checked_sub(variable_header_len) 119 .checked_sub(variable_header_len)
116 .ok_or(Error::InvalidPacket("PUBLISH remaining length is too short for headers"))?; 120 .ok_or(Error::InvalidPacket(
121 "PUBLISH remaining length is too short for headers",
122 ))?;
117 123
118 Packet::Publish { 124 Packet::Publish {
119 topic, 125 topic,
@@ -140,7 +146,9 @@ pub fn decode<'a>(buf: &'a [u8]) -> Result<(Packet<'a>, usize), Error> {
140 } 146 }
141 if packet_len < 3 { 147 if packet_len < 3 {
142 // Minimum: 2 bytes packet ID + 1 byte return code 148 // Minimum: 2 bytes packet ID + 1 byte return code
143 return Err(Error::InvalidPacket("SUBACK remaining length must be at least 3")); 149 return Err(Error::InvalidPacket(
150 "SUBACK remaining length must be at least 3",
151 ));
144 } 152 }
145 let packet_id = PacketId::from(reader.read_u16()?); 153 let packet_id = PacketId::from(reader.read_u16()?);
146 let return_code = reader.read_u8()?; 154 let return_code = reader.read_u8()?;
diff --git a/src/mqtt/tx.rs b/src/mqtt/tx.rs
index 7a4d443..3b2ed66 100644
--- a/src/mqtt/tx.rs
+++ b/src/mqtt/tx.rs
@@ -209,4 +209,3 @@ pub fn pingreq(buffer: &mut FieldBuffer) {
209 ))); 209 )));
210 buffer.push(Field::VarInt(0)); 210 buffer.push(Field::VarInt(0));
211} 211}
212