refactor: replace mqtt_publish() call sites with mqtt::publish()
This commit is contained in:
@@ -490,11 +490,7 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
||||
|
||||
match &serde_json::to_string(&light_state) {
|
||||
Ok(state) => {
|
||||
let _ = board
|
||||
.board_hal
|
||||
.get_esp()
|
||||
.mqtt_publish("/light", state)
|
||||
.await;
|
||||
let _ = mqtt::publish("/light", state).await;
|
||||
}
|
||||
Err(err) => {
|
||||
info!("Error publishing lightstate {}", err);
|
||||
@@ -504,29 +500,16 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
||||
let deep_sleep_duration_minutes: u32 =
|
||||
// if battery soc is unknown assume battery has enough change
|
||||
if state_of_charge < 10.0 && !matches!(battery_state, BatteryState::Unknown) {
|
||||
let _ = board
|
||||
.board_hal
|
||||
.get_esp()
|
||||
.mqtt_publish("/deepsleep", "low Volt 12h").await;
|
||||
let _ = mqtt::publish("/deepsleep", "low Volt 12h").await;
|
||||
12 * 60
|
||||
} else if is_day {
|
||||
let _ = board
|
||||
.board_hal
|
||||
.get_esp()
|
||||
.mqtt_publish("/deepsleep", "normal 20m").await;
|
||||
let _ = mqtt::publish("/deepsleep", "normal 20m").await;
|
||||
20
|
||||
} else {
|
||||
let _ = board
|
||||
.board_hal
|
||||
.get_esp()
|
||||
.mqtt_publish("/deepsleep", "night 1h").await;
|
||||
let _ = mqtt::publish("/deepsleep", "night 1h").await;
|
||||
60
|
||||
};
|
||||
let _ = board
|
||||
.board_hal
|
||||
.get_esp()
|
||||
.mqtt_publish("/state", "sleep")
|
||||
.await;
|
||||
let _ = mqtt::publish("/state", "sleep").await;
|
||||
|
||||
info!("Go to sleep for {} minutes", deep_sleep_duration_minutes);
|
||||
//determine next event
|
||||
@@ -691,7 +674,7 @@ async fn publish_tank_state(
|
||||
&tank_state.as_mqtt_info(&board.board_hal.get_config().tank, &water_temp),
|
||||
)
|
||||
.unwrap();
|
||||
let _ = board.board_hal.get_esp().mqtt_publish("/water", &*state);
|
||||
let _ = mqtt::publish("/water", &*state).await;
|
||||
}
|
||||
|
||||
async fn publish_plant_states(
|
||||
@@ -707,11 +690,7 @@ async fn publish_plant_states(
|
||||
let state =
|
||||
serde_json::to_string(&plant_state.to_mqtt_info(plant_conf, timezone_time)).unwrap();
|
||||
let plant_topic = format!("/plant{}", plant_id + 1);
|
||||
let _ = board
|
||||
.board_hal
|
||||
.get_esp()
|
||||
.mqtt_publish(&plant_topic, &state)
|
||||
.await;
|
||||
let _ = mqtt::publish(&plant_topic, &state).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -721,13 +700,12 @@ async fn publish_firmware_info(
|
||||
ip_address: &str,
|
||||
timezone_time: &str,
|
||||
) {
|
||||
let esp = board.board_hal.get_esp();
|
||||
esp.mqtt_publish("/firmware/address", ip_address).await;
|
||||
esp.mqtt_publish("/firmware/state", format!("{:?}", &version).as_str())
|
||||
mqtt::publish("/firmware/address", ip_address).await;
|
||||
mqtt::publish("/firmware/state", format!("{:?}", &version).as_str())
|
||||
.await;
|
||||
esp.mqtt_publish("/firmware/last_online", timezone_time)
|
||||
mqtt::publish("/firmware/last_online", timezone_time)
|
||||
.await;
|
||||
esp.mqtt_publish("/state", "online").await;
|
||||
mqtt::publish("/state", "online").await;
|
||||
}
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
@@ -827,15 +805,7 @@ async fn pump_info(
|
||||
|
||||
match serde_json::to_string(&pump_info) {
|
||||
Ok(state) => {
|
||||
BOARD_ACCESS
|
||||
.get()
|
||||
.await
|
||||
.lock()
|
||||
.await
|
||||
.board_hal
|
||||
.get_esp()
|
||||
.mqtt_publish(&pump_topic, &state)
|
||||
.await;
|
||||
let _ = mqtt::publish(&pump_topic, &state).await;
|
||||
}
|
||||
Err(err) => {
|
||||
warn!("Error publishing pump state {}", err);
|
||||
@@ -853,10 +823,7 @@ async fn publish_mppt_state(
|
||||
voltage_ma: voltage.as_millivolts() as u32,
|
||||
};
|
||||
if let Ok(serialized_solar_state_bytes) = serde_json::to_string(&solar_state) {
|
||||
let _ = board
|
||||
.board_hal
|
||||
.get_esp()
|
||||
.mqtt_publish("/mppt", &serialized_solar_state_bytes);
|
||||
let _ = mqtt::publish("/mppt", &serialized_solar_state_bytes).await;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -877,11 +844,7 @@ async fn publish_battery_state(
|
||||
Err(_) => "error".to_owned(),
|
||||
};
|
||||
{
|
||||
let _ = board
|
||||
.board_hal
|
||||
.get_esp()
|
||||
.mqtt_publish("/battery", &*value)
|
||||
.await;
|
||||
let _ = mqtt::publish("/battery", &*value).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -985,9 +948,8 @@ async fn wait_infinity(
|
||||
let cur = board.board_hal.get_time().await;
|
||||
let timezone_time = cur.with_timezone(&timezone);
|
||||
|
||||
let esp = board.board_hal.get_esp();
|
||||
esp.mqtt_publish("/state", "config").await;
|
||||
esp.mqtt_publish("/firmware/last_online", &timezone_time.to_rfc3339())
|
||||
mqtt::publish("/state", "config").await;
|
||||
mqtt::publish("/firmware/last_online", &timezone_time.to_rfc3339())
|
||||
.await;
|
||||
last_mqtt_update = Some(now);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user