diff options
Diffstat (limited to 'src/unit.rs')
| -rw-r--r-- | src/unit.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/unit.rs b/src/unit.rs index 90eecb4..cf3c5a2 100644 --- a/src/unit.rs +++ b/src/unit.rs | |||
| @@ -73,6 +73,19 @@ impl PressureUnit { | |||
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 75 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 76 | pub enum SignalStrengthUnit { | ||
| 77 | Dbm, | ||
| 78 | } | ||
| 79 | |||
| 80 | impl SignalStrengthUnit { | ||
| 81 | pub fn as_str(&self) -> &'static str { | ||
| 82 | match self { | ||
| 83 | SignalStrengthUnit::Dbm => crate::constants::HA_UNIT_SIGNAL_STRENGTH_DBM, | ||
| 84 | } | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 76 | pub enum EnergyUnit { | 89 | pub enum EnergyUnit { |
| 77 | KiloWattHour, | 90 | KiloWattHour, |
| 78 | } | 91 | } |
| @@ -442,6 +455,7 @@ pub enum Unit { | |||
| 442 | LightLux, | 455 | LightLux, |
| 443 | PressureHectoPascal, | 456 | PressureHectoPascal, |
| 444 | EnergyKiloWattHour, | 457 | EnergyKiloWattHour, |
| 458 | SignalStrengthDbm, | ||
| 445 | TimeMilliseconds, | 459 | TimeMilliseconds, |
| 446 | TimeSeconds, | 460 | TimeSeconds, |
| 447 | TimeMinutes, | 461 | TimeMinutes, |
| @@ -571,6 +585,7 @@ impl Unit { | |||
| 571 | Unit::LightLux => crate::constants::HA_UNIT_LIGHT_LUX, | 585 | Unit::LightLux => crate::constants::HA_UNIT_LIGHT_LUX, |
| 572 | Unit::PressureHectoPascal => crate::constants::HA_UNIT_PRESSURE_HPA, | 586 | Unit::PressureHectoPascal => crate::constants::HA_UNIT_PRESSURE_HPA, |
| 573 | Unit::EnergyKiloWattHour => crate::constants::HA_UNIT_ENERGY_KWH, | 587 | Unit::EnergyKiloWattHour => crate::constants::HA_UNIT_ENERGY_KWH, |
| 588 | Unit::SignalStrengthDbm => crate::constants::HA_UNIT_SIGNAL_STRENGTH_DBM, | ||
| 574 | Unit::TimeMilliseconds => crate::constants::HA_UNIT_TIME_MILLISECONDS, | 589 | Unit::TimeMilliseconds => crate::constants::HA_UNIT_TIME_MILLISECONDS, |
| 575 | Unit::TimeSeconds => crate::constants::HA_UNIT_TIME_SECONDS, | 590 | Unit::TimeSeconds => crate::constants::HA_UNIT_TIME_SECONDS, |
| 576 | Unit::TimeMinutes => crate::constants::HA_UNIT_TIME_MINUTES, | 591 | Unit::TimeMinutes => crate::constants::HA_UNIT_TIME_MINUTES, |
| @@ -750,6 +765,14 @@ impl From<PressureUnit> for Unit { | |||
| 750 | } | 765 | } |
| 751 | } | 766 | } |
| 752 | 767 | ||
| 768 | impl From<SignalStrengthUnit> for Unit { | ||
| 769 | fn from(unit: SignalStrengthUnit) -> Self { | ||
| 770 | match unit { | ||
| 771 | SignalStrengthUnit::Dbm => Unit::SignalStrengthDbm, | ||
| 772 | } | ||
| 773 | } | ||
| 774 | } | ||
| 775 | |||
| 753 | impl From<EnergyUnit> for Unit { | 776 | impl From<EnergyUnit> for Unit { |
| 754 | fn from(unit: EnergyUnit) -> Self { | 777 | fn from(unit: EnergyUnit) -> Self { |
| 755 | match unit { | 778 | match unit { |
| @@ -986,6 +1009,17 @@ impl TryFrom<Unit> for PressureUnit { | |||
| 986 | } | 1009 | } |
| 987 | } | 1010 | } |
| 988 | 1011 | ||
| 1012 | impl TryFrom<Unit> for SignalStrengthUnit { | ||
| 1013 | type Error = UnitConversionError; | ||
| 1014 | |||
| 1015 | fn try_from(unit: Unit) -> Result<Self, Self::Error> { | ||
| 1016 | match unit { | ||
| 1017 | Unit::SignalStrengthDbm => Ok(SignalStrengthUnit::Dbm), | ||
| 1018 | _ => Err(UnitConversionError), | ||
| 1019 | } | ||
| 1020 | } | ||
| 1021 | } | ||
| 1022 | |||
| 989 | impl TryFrom<Unit> for EnergyUnit { | 1023 | impl TryFrom<Unit> for EnergyUnit { |
| 990 | type Error = UnitConversionError; | 1024 | type Error = UnitConversionError; |
| 991 | 1025 | ||
