diff --git a/sprinklers_actors/src/section_runner.rs b/sprinklers_actors/src/section_runner.rs index 00fb6a4..2b5a4fa 100644 --- a/sprinklers_actors/src/section_runner.rs +++ b/sprinklers_actors/src/section_runner.rs @@ -611,7 +611,7 @@ impl SectionRunner { self.addr.send(Subscribe).map_err(From::from) } - pub fn state_receiver(&self) -> SecRunnerStateRecv { + pub fn get_state_recv(&self) -> SecRunnerStateRecv { self.state_recv.clone() } } diff --git a/sprinklers_mqtt/src/update_listener.rs b/sprinklers_mqtt/src/update_listener.rs index 68fe6ab..39fef84 100644 --- a/sprinklers_mqtt/src/update_listener.rs +++ b/sprinklers_mqtt/src/update_listener.rs @@ -160,18 +160,9 @@ pub struct UpdateListener { } impl UpdateListener { - pub fn start( - section_events: SectionEventRecv, - program_events: ProgramEventRecv, - sec_runner_state: SecRunnerStateRecv, - mqtt_interface: MqttInterface, - ) -> Self { + pub fn start(mqtt_interface: MqttInterface) -> Self { let addr = UpdateListenerActor { mqtt_interface }.start(); - let mut l = Self { addr }; - l.listen(section_events); - l.listen(program_events); - l.listen(sec_runner_state); - l + Self { addr } } fn listen(&mut self, listener: L) @@ -181,6 +172,18 @@ impl UpdateListener { self.addr.do_send(Listen(listener)); } + pub fn listen_section_events(&mut self, section_events: SectionEventRecv) { + self.listen(section_events); + } + + pub fn listen_program_events(&mut self, program_events: ProgramEventRecv) { + self.listen(program_events); + } + + pub fn listen_section_runner(&mut self, sec_runner_state_recv: SecRunnerStateRecv) { + self.listen(sec_runner_state_recv); + } + pub async fn quit(self) -> eyre::Result<()> { Ok(self.addr.send(Quit).await?) } diff --git a/sprinklers_rs/src/main.rs b/sprinklers_rs/src/main.rs index 00300cc..67d3b74 100644 --- a/sprinklers_rs/src/main.rs +++ b/sprinklers_rs/src/main.rs @@ -3,9 +3,9 @@ // mod option_future; +use sprinklers_actors as actors; use sprinklers_core::section_interface::MockSectionInterface; use sprinklers_database as database; -use sprinklers_actors as actors; use sprinklers_mqtt as mqtt; use eyre::Result; @@ -56,17 +56,10 @@ async fn main() -> Result<()> { }; let mut mqtt_interface = mqtt::MqttInterfaceTask::start(mqtt_options, request_context); - let update_listener = { - let section_events = section_runner.subscribe().await?; - let program_events = program_runner.subscribe().await?; - let sec_runner_state = section_runner.state_receiver(); - mqtt::UpdateListener::start( - section_events, - program_events, - sec_runner_state, - mqtt_interface.clone(), - ) - }; + let mut update_listener = mqtt::UpdateListener::start(mqtt_interface.clone()); + update_listener.listen_section_events(section_runner.subscribe().await?); + update_listener.listen_section_runner(section_runner.get_state_recv()); + update_listener.listen_program_events(program_runner.subscribe().await?); program_runner.update_sections(sections.clone()).await?; // TODO: update listener should probably do this