use std::fmt;
use super::HardwareStatus;
pub const SHT_CLOSED: u32 = 6198;
pub const SHT_OPEN: u32 = 6199;
pub const SHT_NOT_SUPPORTED: u32 = 6201;
pub const SHT_UNKNOWN: u32 = 6202;
#[repr(u32)]
#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
pub enum ShutterStatus {
Closed = SHT_CLOSED,
NotSupported = SHT_NOT_SUPPORTED,
Open = SHT_OPEN,
#[default]
Unknown = SHT_UNKNOWN,
}
impl ShutterStatus {
pub const fn new() -> Self {
Self::Unknown
}
pub const fn create(val: u32) -> Self {
match val {
SHT_CLOSED => Self::Closed,
SHT_NOT_SUPPORTED => Self::NotSupported,
SHT_OPEN => Self::Open,
SHT_UNKNOWN => Self::Unknown,
_ => Self::Unknown,
}
}
}
impl From<ShutterStatus> for HardwareStatus {
fn from(val: ShutterStatus) -> Self {
match val {
ShutterStatus::Closed | ShutterStatus::Open => Self::Notification,
ShutterStatus::NotSupported => Self::Missing,
ShutterStatus::Unknown => Self::Warning,
}
}
}
impl From<ShutterStatus> for &'static str {
fn from(val: ShutterStatus) -> Self {
match val {
ShutterStatus::Closed => "closed",
ShutterStatus::Open => "open",
ShutterStatus::NotSupported => "not supported",
ShutterStatus::Unknown => "unknown",
}
}
}
impl From<&ShutterStatus> for &'static str {
fn from(val: &ShutterStatus) -> Self {
(*val).into()
}
}
impl fmt::Display for ShutterStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, r#""{}""#, <&str>::from(self))
}
}
impl_xfs_enum!(ShutterStatus, "shutterStatus");