bo4e_core/com/
metering_point_status.rs

1//! Metering point status (Messstellenstatus) component.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6use crate::traits::{Bo4eMeta, Bo4eObject};
7
8/// Status information for a metering point.
9///
10/// German: Messstellenstatus
11///
12/// # Example
13///
14/// ```rust
15/// use bo4e_core::com::MeteringPointStatus;
16/// use chrono::Utc;
17///
18/// let status = MeteringPointStatus {
19///     status_timestamp: Some(Utc::now()),
20///     is_active: Some(true),
21///     ..Default::default()
22/// };
23/// ```
24#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
25#[serde(rename_all = "camelCase")]
26pub struct MeteringPointStatus {
27    /// BO4E metadata
28    #[serde(flatten)]
29    pub meta: Bo4eMeta,
30
31    /// Timestamp of the status (Statuszeitpunkt)
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub status_timestamp: Option<DateTime<Utc>>,
34
35    /// Whether the metering point is active (Aktiv)
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub is_active: Option<bool>,
38
39    /// Status code (Statuscode)
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub status_code: Option<String>,
42
43    /// Status description (Statusbeschreibung)
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub status_description: Option<String>,
46
47    /// Whether data is being transmitted (Datenübertragung)
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub data_transmission_active: Option<bool>,
50
51    /// Installation status (Installationsstatus)
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub installation_status: Option<String>,
54}
55
56impl Bo4eObject for MeteringPointStatus {
57    fn type_name_german() -> &'static str {
58        "Messstellenstatus"
59    }
60
61    fn type_name_english() -> &'static str {
62        "MeteringPointStatus"
63    }
64
65    fn meta(&self) -> &Bo4eMeta {
66        &self.meta
67    }
68
69    fn meta_mut(&mut self) -> &mut Bo4eMeta {
70        &mut self.meta
71    }
72}
73
74#[cfg(test)]
75mod tests {
76    use super::*;
77    use chrono::TimeZone;
78
79    #[test]
80    fn test_metering_point_status() {
81        let status = MeteringPointStatus {
82            status_timestamp: Some(Utc.with_ymd_and_hms(2024, 1, 15, 12, 0, 0).unwrap()),
83            is_active: Some(true),
84            status_code: Some("ACTIVE".to_string()),
85            data_transmission_active: Some(true),
86            ..Default::default()
87        };
88
89        let json = serde_json::to_string(&status).unwrap();
90        assert!(json.contains("true"));
91        assert!(json.contains("ACTIVE"));
92    }
93
94    #[test]
95    fn test_roundtrip() {
96        let status = MeteringPointStatus {
97            status_timestamp: Some(Utc::now()),
98            is_active: Some(false),
99            status_description: Some("Meter removed".to_string()),
100            ..Default::default()
101        };
102
103        let json = serde_json::to_string(&status).unwrap();
104        let parsed: MeteringPointStatus = serde_json::from_str(&json).unwrap();
105        assert_eq!(status.is_active, parsed.is_active);
106        assert_eq!(status.status_description, parsed.status_description);
107    }
108
109    #[test]
110    fn test_bo4e_object_impl() {
111        assert_eq!(MeteringPointStatus::type_name_german(), "Messstellenstatus");
112        assert_eq!(
113            MeteringPointStatus::type_name_english(),
114            "MeteringPointStatus"
115        );
116    }
117}