Skip to content

Commit

Permalink
Redo dev environment
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmay committed Nov 4, 2023
1 parent a8e0b78 commit 5994ae7
Show file tree
Hide file tree
Showing 11 changed files with 328 additions and 205 deletions.
11 changes: 0 additions & 11 deletions .devcontainer/Dockerfile

This file was deleted.

46 changes: 0 additions & 46 deletions .devcontainer/devcontainer.json

This file was deleted.

1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake . --impure
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/robotica-backend/python/__pycache__/
/local
/target
/.envrc
/.envrc-old
/state
/.direnv
/.devenv
/result
*.yaml
18 changes: 3 additions & 15 deletions brian-backend/src/amber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ use influxdb::InfluxDbWriteable;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use tokio::time::{interval, sleep_until, Instant, MissedTickBehavior};
use tracing::{debug, error, info};
use tracing::{error, info};

use robotica_backend::{
is_debug_mode, pipes::stateful, services::persistent_state::PersistentStateRow, spawn,
};
use robotica_backend::{pipes::stateful, services::persistent_state::PersistentStateRow, spawn};
use robotica_common::datetime::{
convert_date_time_to_utc_or_default, duration_from_hms, utc_now, Date, DateTime, Duration, Time,
};
Expand Down Expand Up @@ -85,7 +83,7 @@ pub fn run(
let influxdb_config = influxdb_config.clone();

spawn(async move {
// if is_debug_mode() {
// if hack enabled {
// let start_date = Date::from_ymd(2022, 1, 1);
// let stop_date = Date::from_ymd(2022, 3, 1);
// // process_prices(&config, start_date, stop_date).await;
Expand Down Expand Up @@ -421,11 +419,6 @@ async fn prices_to_influxdb(
) {
let client = influxdb_config.get_client();

if is_debug_mode() {
debug!("Skipping writing prices to influxdb in debug mode");
return;
}

for data in prices {
let reading = PriceReading {
duration: data.duration,
Expand Down Expand Up @@ -464,11 +457,6 @@ async fn process_usage(
Ok(usage) => {
let client = influxdb_config.get_client();

if is_debug_mode() {
debug!("Skipping writing usage to influxdb in debug mode");
return;
}

for data in usage {
let name = format!("amber/usage/{}", data.channel_identifier);
let reading = UsageReading {
Expand Down
55 changes: 8 additions & 47 deletions brian-backend/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,14 @@ use thiserror::Error;

#[derive(Envconfig)]
pub struct Environment {
// #[envconfig(from = "AMBER_TOKEN")]
// pub amber_token: String,

// #[envconfig(from = "AMBER_SITE_ID")]
// pub amber_site_id: String,

// #[envconfig(from = "INFLUXDB_URL")]
// pub influxdb_url: String,

// #[envconfig(from = "INFLUXDB_DATABASE")]
// pub influxdb_database: String,

// #[envconfig(from = "MQTT_USERNAME")]
// pub mqtt_username: String,

// #[envconfig(from = "MQTT_PASSWORD")]
// pub mqtt_password: String,

// #[envconfig(from = "MQTT_HOST")]
// pub mqtt_host: String,

// #[envconfig(from = "MQTT_PORT")]
// pub mqtt_port: u16,

// #[envconfig(from = "LIFE360_USERNAME")]
// pub life360_username: String,

// #[envconfig(from = "LIFE360_PASSWORD")]
// pub life360_password: String,

// #[envconfig(from = "OIDC_DISCOVERY_URL")]
// pub oidc_discovery_url: String,

// #[envconfig(from = "OIDC_CLIENT_ID")]
// pub oidc_client_id: String,

// #[envconfig(from = "OIDC_CLIENT_SECRET")]
// pub oidc_client_secret: String,

// #[envconfig(from = "OIDC_SCOPES")]
// pub oidc_scopes: String,

// #[envconfig(from = "CALENDAR_URL")]
// pub calendar_url: String,
#[envconfig(from = "CONFIG_FILE")]
pub config_file: PathBuf,

#[envconfig(from = "SECRETS_FILE")]
pub secrets_file: Option<PathBuf>,
// #[envconfig(from = "SESSION_SECRET")]
// pub session_secret: String,

#[envconfig(from = "STATIC_PATH")]
pub static_path: Option<PathBuf>,
}

fn load_file(filename: &Path) -> Result<serde_yaml::Value, Error> {
Expand All @@ -83,9 +40,13 @@ impl Environment {
config
};

let config: Config =
let mut config: Config =
serde_yaml::from_value(config).map_err(|e| Error::Yaml(self.config_file.clone(), e))?;

if let Some(static_path) = &self.static_path {
config.http.static_path = static_path.clone();
}

Ok(config)
}
/// Load the environment from the environment variables.
Expand Down
12 changes: 4 additions & 8 deletions brian-backend/src/environment_monitor.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use chrono::{DateTime, Utc};
use influxdb::InfluxDbWriteable;
use robotica_backend::pipes::{Subscriber, Subscription};
use robotica_backend::{is_debug_mode, spawn};
use robotica_backend::spawn;
use robotica_common::anavi_thermometer::{self as anavi};
use robotica_common::mqtt::{Json, MqttMessage};
use robotica_common::zwave;
use serde::de::DeserializeOwned;
use serde::Deserialize;
use tracing::{debug, error};
use tracing::error;

use crate::influxdb::Config;
use crate::InitState;
Expand Down Expand Up @@ -96,9 +96,7 @@ where
let reading: Influx = data.into();
let query = reading.into_query(&topic);

if is_debug_mode() {
// debug!("would send {:?}", query);
} else if let Err(e) = client.query(&query).await {
if let Err(e) = client.query(&query).await {
error!("Failed to write to influxdb: {}", e);
}
}
Expand All @@ -125,9 +123,7 @@ pub fn monitor_fishtank(state: &mut InitState, topic: &str, config: &Config) {
}
.into_query(&topic);

if is_debug_mode() {
debug!("would send {:?}", reading);
} else if let Err(e) = client.query(&reading).await {
if let Err(e) = client.query(&reading).await {
error!("Failed to write to influxdb: {}", e);
}
}
Expand Down
Loading

0 comments on commit 5994ae7

Please sign in to comment.