Skip to main content

rointe_core/models/
enums.rs

1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4
5/// Physical device type as reported by the API.
6///
7/// This enum is `#[non_exhaustive]` — Rointe may introduce new hardware
8/// categories in future firmware updates.
9#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10#[serde(rename_all = "snake_case")]
11#[non_exhaustive]
12pub enum RointeProduct {
13    /// Standard panel radiator.
14    Radiator,
15    /// Panel radiator (variant B).
16    Radiatorb,
17    /// Towel-rail radiator.
18    Towel,
19    /// ACS (hot-water storage / immersion) heater.
20    Acs,
21    /// Thermostat controller.
22    Therm,
23    /// Oval towel-rail radiator.
24    OvalTowel,
25}
26
27/// Operating mode of the device.
28///
29/// - `Manual` — target temperature is set explicitly by the user.
30/// - `Auto` — the device follows its programmed weekly schedule.
31#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
32#[serde(rename_all = "snake_case")]
33pub enum DeviceMode {
34    /// Temperature is controlled manually.
35    Manual,
36    /// Temperature follows the weekly schedule.
37    Auto,
38}
39
40impl fmt::Display for DeviceMode {
41    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42        match self {
43            DeviceMode::Manual => write!(f, "manual"),
44            DeviceMode::Auto => write!(f, "auto"),
45        }
46    }
47}
48
49/// Current status / active preset of the device.
50#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
51#[serde(rename_all = "snake_case")]
52pub enum DeviceStatus {
53    /// Heating to the comfort preset temperature.
54    Comfort,
55    /// Heating to the eco (energy-saving) preset temperature.
56    Eco,
57    /// Frost-protection (ice) mode active.
58    Ice,
59    /// Device is off.
60    Off,
61    /// No preset active; device is in manual temperature control.
62    #[serde(rename = "none")]
63    NoStatus,
64}
65
66impl fmt::Display for DeviceStatus {
67    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68        match self {
69            DeviceStatus::Comfort => write!(f, "comfort"),
70            DeviceStatus::Eco => write!(f, "eco"),
71            DeviceStatus::Ice => write!(f, "ice"),
72            DeviceStatus::Off => write!(f, "off"),
73            DeviceStatus::NoStatus => write!(f, "none"),
74        }
75    }
76}
77
78/// High-level HVAC command used with [`crate::RointeClient::set_mode`].
79#[derive(Debug, Clone, PartialEq)]
80pub enum HvacMode {
81    /// Turn the device off (two-step sequence).
82    Off,
83    /// Turn on and heat to the comfort temperature (two-step sequence).
84    Heat,
85    /// Follow the programmed weekly schedule (two-step sequence).
86    Auto,
87}
88
89impl fmt::Display for HvacMode {
90    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91        match self {
92            HvacMode::Off => write!(f, "off"),
93            HvacMode::Heat => write!(f, "heat"),
94            HvacMode::Auto => write!(f, "auto"),
95        }
96    }
97}
98
99/// Comfort preset used with [`crate::RointeClient::set_preset`].
100#[derive(Debug, Clone, PartialEq)]
101pub enum Preset {
102    /// Heat to the device's configured comfort temperature.
103    Comfort,
104    /// Heat to the device's configured eco (energy-saving) temperature.
105    Eco,
106    /// Activate frost-protection (ice) mode.
107    Ice,
108}
109
110impl fmt::Display for Preset {
111    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
112        match self {
113            Preset::Comfort => write!(f, "comfort"),
114            Preset::Eco => write!(f, "eco"),
115            Preset::Ice => write!(f, "ice"),
116        }
117    }
118}
119
120/// Interpretation of a single character slot in a device's weekly schedule string.
121///
122/// Each day's schedule is a 24-character string; each character represents one
123/// hour and maps to one of these modes.
124#[derive(Debug, Clone, PartialEq)]
125pub enum ScheduleMode {
126    /// `'C'` — heat to the comfort preset temperature.
127    Comfort,
128    /// `'E'` — heat to the eco preset temperature.
129    Eco,
130    /// Any other character — device is off during this hour.
131    Off,
132}
133
134impl ScheduleMode {
135    /// Parse a schedule character into the corresponding [`ScheduleMode`].
136    ///
137    /// - `'C'` → [`ScheduleMode::Comfort`]
138    /// - `'E'` → [`ScheduleMode::Eco`]
139    /// - anything else → [`ScheduleMode::Off`]
140    pub fn from_char(c: char) -> Self {
141        match c {
142            'C' => ScheduleMode::Comfort,
143            'E' => ScheduleMode::Eco,
144            _ => ScheduleMode::Off,
145        }
146    }
147}