Add publishing of section states
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
239a289e4e
commit
cfde268603
@ -11,6 +11,7 @@ mod section_interface;
|
|||||||
mod section_runner;
|
mod section_runner;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod trace_listeners;
|
mod trace_listeners;
|
||||||
|
mod update_listener;
|
||||||
|
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -64,6 +65,11 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
program_runner.update_sections(sections.clone()).await?;
|
program_runner.update_sections(sections.clone()).await?;
|
||||||
mqtt_interface.publish_sections(§ions).await?;
|
mqtt_interface.publish_sections(§ions).await?;
|
||||||
|
for section_id in sections.keys() {
|
||||||
|
mqtt_interface
|
||||||
|
.publish_section_state(*section_id, false)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
program_runner.update_programs(programs.clone()).await?;
|
program_runner.update_programs(programs.clone()).await?;
|
||||||
mqtt_interface.publish_programs(&programs).await?;
|
mqtt_interface.publish_programs(&programs).await?;
|
||||||
|
|
||||||
|
@ -37,6 +37,10 @@ where
|
|||||||
format!("{}/sections/{}", self.prefix.as_ref(), section_id)
|
format!("{}/sections/{}", self.prefix.as_ref(), section_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn section_state(&self, section_id: SectionId) -> String {
|
||||||
|
format!("{}/sections/{}/state", self.prefix.as_ref(), section_id)
|
||||||
|
}
|
||||||
|
|
||||||
fn programs(&self) -> String {
|
fn programs(&self) -> String {
|
||||||
format!("{}/programs", self.prefix.as_ref())
|
format!("{}/programs", self.prefix.as_ref())
|
||||||
}
|
}
|
||||||
@ -160,6 +164,19 @@ impl MqttInterface {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn publish_section_state(&mut self, section_id: SectionId, state: bool) -> eyre::Result<()> {
|
||||||
|
let payload: Vec<u8> = state.to_string().into();
|
||||||
|
self.client
|
||||||
|
.publish(
|
||||||
|
self.topics.section_state(section_id),
|
||||||
|
QoS::AtLeastOnce,
|
||||||
|
true,
|
||||||
|
payload,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn publish_programs(&mut self, programs: &Programs) -> eyre::Result<()> {
|
pub async fn publish_programs(&mut self, programs: &Programs) -> eyre::Result<()> {
|
||||||
let program_ids: Vec<_> = programs.keys().cloned().collect();
|
let program_ids: Vec<_> = programs.keys().cloned().collect();
|
||||||
let program_ids_payload = serde_json::to_vec(&program_ids)?;
|
let program_ids_payload = serde_json::to_vec(&program_ids)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user