switchbot_api/
switch_bot.rs1use std::rc::Rc;
2
3use super::*;
4
5#[derive(Debug, Default)]
6pub struct SwitchBot {
7 service: Rc<SwitchBotService>,
8 devices: DeviceList,
9}
10
11impl SwitchBot {
12 pub fn new() -> Self {
13 Self::default()
14 }
15
16 pub fn new_with_authentication(token: &str, secret: &str) -> Self {
17 Self {
18 service: SwitchBotService::new(token, secret),
19 ..Default::default()
20 }
21 }
22
23 pub fn set_authentication(&mut self, token: &str, secret: &str) {
24 self.service = SwitchBotService::new(token, secret);
25 }
26
27 pub fn devices(&self) -> &DeviceList {
28 &self.devices
29 }
30
31 pub async fn load_devices(&mut self) -> anyhow::Result<()> {
32 let devices = self.service.load_devices().await?;
33 self.devices = devices;
34 Ok(())
35 }
36}