launch server even with no cars
This commit is contained in:
parent
942d3cc3cf
commit
1cde09ff58
29
src/main.rs
29
src/main.rs
|
@ -64,10 +64,10 @@ async fn main() {
|
|||
let config_path = args.config_dir.join("config.json");
|
||||
let (config, _config_watcher) = config::init_config(config_path);
|
||||
config::CONFIG.get_or_init(|| RwLock::new(config));
|
||||
if let Some(mut interface) = TeslaInterface::load(auth_path)
|
||||
let interface = TeslaInterface::load(auth_path)
|
||||
.await
|
||||
.some_or_print_with("loading tesla interface")
|
||||
{
|
||||
.some_or_print_with("loading tesla interface");
|
||||
|
||||
// build the channel that takes messages from the webserver thread to the api thread
|
||||
let (api_requests, mut api_receiver) = tokio::sync::mpsc::unbounded_channel();
|
||||
// and to the pli thread
|
||||
|
@ -87,8 +87,7 @@ async fn main() {
|
|||
Ok(mut pli) => {
|
||||
let pl_state = pli.state.clone();
|
||||
tokio::task::spawn(async move {
|
||||
let mut interval =
|
||||
tokio::time::interval(std::time::Duration::from_secs(
|
||||
let mut interval = tokio::time::interval(std::time::Duration::from_secs(
|
||||
access_config().pl_watch_interval_seconds,
|
||||
));
|
||||
loop {
|
||||
|
@ -154,18 +153,30 @@ async fn main() {
|
|||
})
|
||||
.collect();
|
||||
|
||||
let mut tesla_charge_rate_controller =
|
||||
let interface_and_tcrc = interface.map(|interface| {
|
||||
let tcrc =
|
||||
TeslaChargeRateController::new(interface.state.clone(), pl_state.clone());
|
||||
(interface, tcrc)
|
||||
});
|
||||
let car_state = interface_and_tcrc
|
||||
.as_ref()
|
||||
.map(|(interface, _)| interface.state.clone())
|
||||
.unwrap_or_default();
|
||||
let tcrc_state = interface_and_tcrc
|
||||
.as_ref()
|
||||
.map(|(_, tcrc)| tcrc.tcrc_state.clone())
|
||||
.unwrap_or_default();
|
||||
|
||||
let server_handle = server::launch_server(server::ServerState {
|
||||
car_state: interface.state.clone(),
|
||||
car_state,
|
||||
pl_state,
|
||||
tcrc_state: tesla_charge_rate_controller.tcrc_state.clone(),
|
||||
tcrc_state,
|
||||
api_requests,
|
||||
pli_requests,
|
||||
tcrc_requests,
|
||||
});
|
||||
|
||||
if let Some((mut interface, mut tesla_charge_rate_controller)) = interface_and_tcrc {
|
||||
// spawn the api / charge rate control loop
|
||||
tokio::task::spawn(async move {
|
||||
let mut normal_data_update_interval =
|
||||
|
@ -219,8 +230,8 @@ async fn main() {
|
|||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
tokio::join!(server_handle, local);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue