Skip to main content

foxess/models/fox_settings/
id.rs

1//! This module hosts the [FoxSettings] enumeration mainly used when requesting several settings from FoxESS cloud at once.
2//!
3//! FoxESS Cloud currently supports many settings, and the foxess crate implements the currently available ones.
4//! More might be added over time, hence the [FoxSettings] enumeration is derived non-exhaustive.
5//!
6
7use core::str::FromStr;
8
9/// Defines the `FoxSettings` enum + `as_str()` + `FromStr` from a single registry.
10///
11/// Usage:
12/// ```rust,ignore
13/// define_fox_settings! {
14///     [ActivePowerLimit, "ActivePowerLimit", "The limit on the inverter’s active power output"],
15///     [ECOMode, "ECOMode", "Enables or configures energy-saving mode, typically optimizing battery charge/discharge based on time-of-use or self-consumption strategy"],
16///     [EpsOutPut, "EpsOutPut", "Controls whether the EPS (Emergency Power Supply) backup output is enabled during grid outages"],
17///     [ExportLimit, "ExportLimit", "Enables or disables the inverter’s grid export power limiting function"],
18/// }
19/// ```
20macro_rules! define_fox_settings {
21    (
22        $(
23            [$variant:ident, $key:literal, $doc:literal]
24        ),+ $(,)?
25    ) => {
26        /// An enumeration representing implemented settings from FoxESS cloud, i.e., a subset from available settings.
27        ///
28        /// These settings can be retrieved or set on FoxESS devices.
29        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
30        #[non_exhaustive]
31        pub enum FoxSettings {
32            $(
33                #[doc = $doc]
34                $variant,
35            )+
36        }
37
38        impl FoxSettings {
39            /// Returns the string representation of the `FoxSettings` enum variant.
40            ///
41            /// This string matches the key used by the FoxESS cloud API.
42            ///
43            /// # Returns
44            /// * `&'static str` - The string representation of the setting.
45            #[inline]
46            pub const fn as_str(&self) -> &'static str {
47                match self {
48                    $(
49                        Self::$variant => $key,
50                    )+
51                }
52            }
53        }
54
55        impl FromStr for FoxSettings {
56            type Err = ();
57
58            #[inline]
59            fn from_str(s: &str) -> Result<Self, Self::Err> {
60                match s {
61                    $(
62                        $key => Ok(Self::$variant),
63                    )+
64                    _ => Err(()),
65                }
66            }
67        }
68    };
69}
70
71// ---- registry ---------------------------------------------------------------
72
73define_fox_settings! {
74    [ActivePowerLimit, "ActivePowerLimit", "The limit on the inverter’s active power output"],
75    [ECOMode, "ECOMode", "Enables or configures energy-saving mode, typically optimizing battery charge/discharge based on time-of-use or self-consumption strategy"],
76    [EpsOutPut, "EpsOutPut", "Controls whether the EPS (Emergency Power Supply) backup output is enabled during grid outages"],
77    [ExportLimit, "ExportLimit", "Enables or disables the inverter’s grid export power limiting function"],
78    [ExportLimitPower, "ExportLimitPower", "Defines the maximum allowed power (in watts or percent) that can be exported to the grid"],
79    [GridCode, "GridCode", "Selects the country- or utility-specific grid compliance standard the inverter must follow"],
80    [GroundProtection, "GroundProtection", "Enables ground fault detection and protection functionality"],
81    [MaxSetChargeCurrent, "MaxSetChargeCurrent", "The maximum allowed battery charging current set for the inverter"],
82    [MaxSetDischargeCurrent, "MaxSetDischargeCurrent", "The maximum allowed battery discharging current set for the inverter"],
83    [MaxSoc, "MaxSoc", "The maximum battery state of charge (SOC) the system will charge up to"],
84    [Meter1Enable, "Meter1Enable", "Enables communication with and use of the primary external energy meter"],
85    [Meter2Enable, "Meter2Enable", "Enables communication with and use of a secondary external energy meter"],
86    [MinSoc, "MinSoc", "The minimum battery state of charge (SOC) allowed during normal operation"],
87    [MinSocOnGrid, "MinSocOnGrid", "The minimum battery state of charge (SOC) maintained while the grid is available"],
88    [SysSwitch, "SysSwitch", "Master system enable/disable switch for inverter operation"],
89    [WorkMode, "WorkMode", "Defines the inverter’s operating mode (e.g., self-consumption, feed-in priority, backup, or time-of-use mode)"],
90}