Skip to main content

read_tariff_windows_async

Function read_tariff_windows_async 

Source
pub async fn read_tariff_windows_async(
    read: TariffRead<'_>,
    read_fields: impl AsyncFnMut(&[(String, Fc)]) -> Result<Vec<Value>>,
    accept_start: impl FnOnce(UtcTime) -> bool,
    classify: impl FnMut(f64) -> Option<TariffLevel>,
) -> Result<Vec<TariffWindow>>
Expand description

Drive a configured TariffRead using an existing asynchronous MMS association.

For each batch, read_fields issues one MMS Read and returns decoded values in request order or the original MMS error. The association driver owns invoke-ID matching, deadlines and in-flight request cleanup on cancellation. Dropping this future discards the unfinished schedule.

use smgw_cls::fnn::fsch::{TariffProfile, TariffRead, read_tariff_windows_async};
use smgw_cls::fnn::tariff::TariffLevel;
let profile = TariffProfile { first_price: "ValING1", ..TariffProfile::new("ct/kWh") };
let read = TariffRead::new("CLSLD0/FSCH1", profile, 86_400..172_800)?;
let windows = read_tariff_windows_async(
    read, read_fields,
    |t| !t.quality.clock_failure && !t.quality.clock_not_synchronized,
    |price| match price {
        6.0 => Some(TariffLevel::Low),
        12.0 => Some(TariffLevel::Standard),
        18.0 => Some(TariffLevel::High),
        _ => None,
    },
).await?;