mirror of
https://github.com/LastExceed/spacermake.git
synced 2025-05-02 07:50:50 +02:00
fix payload casing
This commit is contained in:
parent
123c596243
commit
ed4a89e3c0
31
src/state.rs
31
src/state.rs
@ -43,24 +43,27 @@ impl<Kind> State<Kind> {
|
|||||||
|
|
||||||
//probably doesn't belong here, dunno where else to put it
|
//probably doesn't belong here, dunno where else to put it
|
||||||
async fn update_power_state(&self, machine: &str, new_state: bool) {
|
async fn update_power_state(&self, machine: &str, new_state: bool) {
|
||||||
|
let is_tasmota = SLAVE_PROPERTIES[machine][2];
|
||||||
|
let topic =
|
||||||
|
if is_tasmota {
|
||||||
|
format!("cmnd/{machine}/Power")
|
||||||
|
} else {
|
||||||
|
format!("shellies/{machine}/relay/0/command")
|
||||||
|
};
|
||||||
|
|
||||||
|
#[allow(clippy::collapsible_else_if)]
|
||||||
|
let payload =
|
||||||
|
if is_tasmota {
|
||||||
|
if new_state { b"ON".as_slice() } else { b"OFF".as_slice() }
|
||||||
|
} else {
|
||||||
|
if new_state { b"on".as_slice() } else { b"off".as_slice() }
|
||||||
|
};
|
||||||
|
|
||||||
self.client
|
self.client
|
||||||
.read()
|
.read()
|
||||||
.await
|
.await
|
||||||
.publish(
|
.publish(topic, QoS::AtMostOnce, false, payload)
|
||||||
get_slave_topic(machine),
|
|
||||||
QoS::AtMostOnce,
|
|
||||||
false,
|
|
||||||
if new_state { b"ON".as_slice() } else { b"OFF".as_slice() }
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.expect("failed to publish");
|
.expect("failed to publish");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_slave_topic(machine: &str) -> String {
|
|
||||||
if SLAVE_PROPERTIES[machine][2] {
|
|
||||||
format!("cmnd/{machine}/Power")
|
|
||||||
} else {
|
|
||||||
format!("shellies/{machine}/relay/0/command")
|
|
||||||
}
|
|
||||||
}
|
|
@ -66,7 +66,7 @@ impl State<Announcer> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.update_power_state(&machine, false).await;
|
self.update_power_state(machine, false).await;
|
||||||
schedule.pop_front();
|
schedule.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user