1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
use std::fmt;
use std::time::Duration;
use crate::{State, Technology};
use crate::platform::traits::BatteryDevice;
use crate::platform::Device;
pub struct Battery(Device);
impl Battery {
pub fn percentage(&self) -> f32 {
self.0.percentage()
}
pub fn energy(&self) -> u32 {
self.0.energy()
}
pub fn energy_full(&self) -> u32 {
self.0.energy_full()
}
pub fn energy_full_design(&self) -> u32 {
self.0.energy_full_design()
}
pub fn energy_rate(&self) -> u32 {
self.0.energy_rate()
}
pub fn voltage(&self) -> u32 {
self.0.voltage()
}
pub fn capacity(&self) -> f32 {
self.0.capacity()
}
pub fn state(&self) -> State {
self.0.state()
}
pub fn technology(&self) -> Technology {
self.0.technology()
}
pub fn temperature(&self) -> Option<f32> {
self.0.temperature()
}
pub fn cycle_count(&self) -> Option<u32> {
self.0.cycle_count()
}
pub fn vendor(&self) -> Option<&str> {
self.0.vendor()
}
pub fn model(&self) -> Option<&str> {
self.0.model()
}
pub fn serial_number(&self) -> Option<&str> {
self.0.serial_number()
}
pub fn time_to_full(&self) -> Option<Duration> {
self.0.time_to_full()
}
pub fn time_to_empty(&self) -> Option<Duration> {
self.0.time_to_empty()
}
#[allow(dead_code)]
pub(crate) fn get_ref(&self) -> &Device {
&self.0
}
pub(crate) fn get_mut_ref(&mut self) -> &mut Device {
&mut self.0
}
}
impl fmt::Debug for Battery {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Battery")
.field("vendor", &self.vendor())
.field("model", &self.model())
.field("serial_number", &self.serial_number())
.field("technology", &self.technology())
.field("state", &self.state())
.field("capacity", &self.capacity())
.field("temperature", &self.temperature())
.field("percentage", &self.percentage())
.field("cycle_count", &self.cycle_count())
.field("energy", &self.energy())
.field("energy_full", &self.energy_full())
.field("energy_full_design", &self.energy_full_design())
.field("energy_rate", &self.energy_rate())
.field("voltage", &self.voltage())
.field("time_to_full", &self.time_to_full())
.field("time_to_empty", &self.time_to_empty())
.finish()
}
}
impl From<Device> for Battery {
fn from(inner: Device) -> Self {
Battery(inner)
}
}