use anyhow::{anyhow, bail, Context, Result}; use chrono::{DateTime, Utc}; use reqwest::Client; use serde_json::Value; use std::collections::HashMap; use crate::models::{ EnergyReading, HaReading, InfluxDbSettings, NetworkReading, Reading, ZoneReading, }; const DEVICE_MEASUREMENT: &str = "gree_device"; const ZONE_MEASUREMENT: &str = "gree_zone"; const HA_MEASUREMENT: &str = "gree_ha"; const ENERGY_MEASUREMENT: &str = "gree_energy"; const NETWORK_MEASUREMENT: &str = "gree_network"; // Functional source split intentionally keeps items in the existing module namespace. include!("influxdb/write.rs"); include!("influxdb/query.rs"); include!("influxdb/codec.rs"); pub async fn test_connection(client: &Client, settings: &InfluxDbSettings) -> Result<()> { validate(settings)?; if settings.version == "1" { query_v1(client, settings, "SHOW MEASUREMENTS LIMIT 1").await?; } else { let query = format!( "from(bucket: {}) |> range(start: -1m) |> limit(n: 1)", flux_string(&settings.bucket) ); query_v2(client, settings, &query).await?; } Ok(()) }