1pub mod auth;
32pub mod client;
33pub mod controllers;
34pub mod error;
35pub mod models;
36
37use client::AlarmClient;
38use error::Result;
39use models::garage_door::GarageDoor;
40use models::light::Light;
41use models::lock::Lock;
42use models::partition::{ArmingOption, Partition};
43use models::sensor::Sensor;
44use models::system::System;
45use models::thermostat::Thermostat;
46
47#[derive(Debug, Clone)]
49pub struct SystemStatus {
50 pub system: System,
51 pub partitions: Vec<Partition>,
52 pub sensors: Vec<Sensor>,
53 pub locks: Vec<Lock>,
54 pub garage_doors: Vec<GarageDoor>,
55 pub lights: Vec<Light>,
56 pub thermostats: Vec<Thermostat>,
57}
58
59pub struct AlarmDotCom {
64 client: AlarmClient,
65}
66
67impl AlarmDotCom {
68 pub fn new(username: impl Into<String>, password: impl Into<String>) -> Self {
70 AlarmDotCom {
71 client: AlarmClient::new(username, password),
72 }
73 }
74
75 pub fn set_trusted_device_cookie(&mut self, cookie: impl Into<String>) {
81 self.client.set_trusted_device_cookie(cookie);
82 }
83
84 pub fn trusted_device_cookie(&self) -> Option<&str> {
86 self.client.trusted_device_cookie()
87 }
88
89 pub async fn login(&mut self) -> Result<()> {
94 self.client.login().await
95 }
96
97 pub fn is_logged_in(&self) -> bool {
99 self.client.is_logged_in()
100 }
101
102 pub async fn keep_alive(&mut self) -> Result<bool> {
105 self.client.keep_alive().await
106 }
107
108 pub async fn fetch_status(&mut self) -> Result<SystemStatus> {
112 let system = controllers::systems::fetch_primary_system(&mut self.client).await?;
113
114 let partitions = controllers::partitions::fetch_partitions(&mut self.client)
115 .await
116 .unwrap_or_default();
117 let sensors = controllers::sensors::fetch_sensors(&mut self.client)
118 .await
119 .unwrap_or_default();
120 let locks = controllers::locks::fetch_locks(&mut self.client)
121 .await
122 .unwrap_or_default();
123 let garage_doors = controllers::garage_doors::fetch_garage_doors(&mut self.client)
124 .await
125 .unwrap_or_default();
126 let lights = controllers::lights::fetch_lights(&mut self.client)
127 .await
128 .unwrap_or_default();
129 let thermostats = controllers::thermostats::fetch_thermostats(&mut self.client)
130 .await
131 .unwrap_or_default();
132
133 Ok(SystemStatus {
134 system,
135 partitions,
136 sensors,
137 locks,
138 garage_doors,
139 lights,
140 thermostats,
141 })
142 }
143
144 pub async fn fetch_system(&mut self) -> Result<System> {
146 controllers::systems::fetch_primary_system(&mut self.client).await
147 }
148
149 pub async fn fetch_partitions(&mut self) -> Result<Vec<Partition>> {
153 controllers::partitions::fetch_partitions(&mut self.client).await
154 }
155
156 pub async fn arm_stay(&mut self, partition_id: &str, options: &[ArmingOption]) -> Result<()> {
158 controllers::partitions::arm_stay(&mut self.client, partition_id, options).await
159 }
160
161 pub async fn arm_away(&mut self, partition_id: &str, options: &[ArmingOption]) -> Result<()> {
163 controllers::partitions::arm_away(&mut self.client, partition_id, options).await
164 }
165
166 pub async fn arm_night(&mut self, partition_id: &str, options: &[ArmingOption]) -> Result<()> {
168 controllers::partitions::arm_night(&mut self.client, partition_id, options).await
169 }
170
171 pub async fn disarm(&mut self, partition_id: &str) -> Result<()> {
173 controllers::partitions::disarm(&mut self.client, partition_id).await
174 }
175
176 pub async fn clear_faults(&mut self, partition_id: &str) -> Result<()> {
178 controllers::partitions::clear_faults(&mut self.client, partition_id).await
179 }
180
181 pub async fn fetch_sensors(&mut self) -> Result<Vec<Sensor>> {
185 controllers::sensors::fetch_sensors(&mut self.client).await
186 }
187
188 pub async fn fetch_locks(&mut self) -> Result<Vec<Lock>> {
192 controllers::locks::fetch_locks(&mut self.client).await
193 }
194
195 pub async fn lock(&mut self, lock_id: &str) -> Result<()> {
197 controllers::locks::lock(&mut self.client, lock_id).await
198 }
199
200 pub async fn unlock(&mut self, lock_id: &str) -> Result<()> {
202 controllers::locks::unlock(&mut self.client, lock_id).await
203 }
204
205 pub async fn fetch_garage_doors(&mut self) -> Result<Vec<GarageDoor>> {
209 controllers::garage_doors::fetch_garage_doors(&mut self.client).await
210 }
211
212 pub async fn open_garage_door(&mut self, id: &str) -> Result<()> {
214 controllers::garage_doors::open(&mut self.client, id).await
215 }
216
217 pub async fn close_garage_door(&mut self, id: &str) -> Result<()> {
219 controllers::garage_doors::close(&mut self.client, id).await
220 }
221
222 pub async fn fetch_lights(&mut self) -> Result<Vec<Light>> {
226 controllers::lights::fetch_lights(&mut self.client).await
227 }
228
229 pub async fn turn_on_light(&mut self, id: &str) -> Result<()> {
231 controllers::lights::turn_on(&mut self.client, id).await
232 }
233
234 pub async fn turn_off_light(&mut self, id: &str) -> Result<()> {
236 controllers::lights::turn_off(&mut self.client, id).await
237 }
238
239 pub async fn set_light_brightness(&mut self, id: &str, level: u32) -> Result<()> {
241 controllers::lights::set_brightness(&mut self.client, id, level).await
242 }
243
244 pub async fn fetch_thermostats(&mut self) -> Result<Vec<Thermostat>> {
248 controllers::thermostats::fetch_thermostats(&mut self.client).await
249 }
250
251 pub async fn set_thermostat_mode(
253 &mut self,
254 id: &str,
255 mode: models::thermostat::ThermostatMode,
256 ) -> Result<()> {
257 controllers::thermostats::set_mode(&mut self.client, id, mode).await
258 }
259
260 pub async fn set_heat_setpoint(&mut self, id: &str, temp: f64) -> Result<()> {
262 controllers::thermostats::set_heat_setpoint(&mut self.client, id, temp).await
263 }
264
265 pub async fn set_cool_setpoint(&mut self, id: &str, temp: f64) -> Result<()> {
267 controllers::thermostats::set_cool_setpoint(&mut self.client, id, temp).await
268 }
269}