mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-14 02:11:54 -04:00
cec: Add HdmiCecState::from_str
This commit is contained in:
parent
e25b1a7ca7
commit
d7b391b432
1 changed files with 15 additions and 2 deletions
17
src/cec.rs
17
src/cec.rs
|
@ -6,8 +6,9 @@
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::{bail, Error, Result};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::str::FromStr;
|
||||||
use zbus::Connection;
|
use zbus::Connection;
|
||||||
|
|
||||||
use crate::systemd::{daemon_reload, EnableState, SystemdUnit};
|
use crate::systemd::{daemon_reload, EnableState, SystemdUnit};
|
||||||
|
@ -31,6 +32,18 @@ impl TryFrom<u32> for HdmiCecState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FromStr for HdmiCecState {
|
||||||
|
type Err = Error;
|
||||||
|
fn from_str(input: &str) -> Result<HdmiCecState, Self::Err> {
|
||||||
|
Ok(match input {
|
||||||
|
"disable" | "disabled" | "off" => HdmiCecState::Disabled,
|
||||||
|
"control-only" | "ControlOnly" => HdmiCecState::ControlOnly,
|
||||||
|
"control-wake" | "control-and-wake" | "ControlAndWake" => HdmiCecState::ControlAndWake,
|
||||||
|
v => bail!("No enum match for value {v}"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for HdmiCecState {
|
impl fmt::Display for HdmiCecState {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
@ -41,7 +54,7 @@ impl fmt::Display for HdmiCecState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct HdmiCecControl<'dbus> {
|
pub(crate) struct HdmiCecControl<'dbus> {
|
||||||
plasma_rc_unit: SystemdUnit<'dbus>,
|
plasma_rc_unit: SystemdUnit<'dbus>,
|
||||||
wakehook_unit: SystemdUnit<'dbus>,
|
wakehook_unit: SystemdUnit<'dbus>,
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue