1 unstable release

0.1.0 Feb 28, 2021

#69 in #smart

Custom license

13KB
246 lines

vesync-rs

This crate lets you access and control your VeSync smart outlets including, for example, Etekcity smart plugs. You must have a VeSync account (which requires you install their iOS or Android app) in order to use this crate.

[depenencies]
vesync = "0.1"
use vesync_rs::{VeSyncAccount, VeSyncdevice, DeviceStatus};

const VESYNC_ACCOUNT: &str = "me@example.com";
const VESYNC_KEY: &str = "my-secret-password";

fn main() -> Result<(), ()> {
    let account = VeSyncAccount::login(VESYNC_ACCOUNT, VESYNC_KEY)?;
    let devices = account.devices()?;

    let outside_light = devices
        .iter()
        .find(|device| device.cid == "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
        .unwrap();

    // Toggle the state of the device
    outside_light.device_toggle()?;

    match outside_light.deviceStatus {
        DeviceStatus::On => println!("Outside light is on"),
        DeviceStatus::Off => println!("Outside light is off"),
        DeviceStatus::Unknown => println!("🤷‍♂️"), // toggle will update state, so this *should* be unreachable
    };

    Ok(())
}

TODO

  • Switch to nanoserde
  • Improve initial vesync-rs API
  • Strengthen VeSync API types (using Enums instead of Strings, whenever possible)
  • Investigate brightness (dimming) API

Changelog

  • Switched to attohttpc. This dropped the number of crates to build from 106 to 62 and the build time from about 1min30sec to 55sec.
  • Updated API to (hopefully) be more idiomatic.
  • Added ability to create VeSyncAccount using the accountID and tk directly (ie, without logging in). This lets you add those values to your source code instead of the raw credentials:
let account = VeSyncAccount { accountID: "1234".to_string(), tk: "ABCXYZ==".to_string() };
  • Added ability to create VeSyncDevice from the account and cid:
let mut inside_light = VeSyncDevice::from_id(&account, "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
inside_light.update();

Dependencies

~3–4.5MB
~84K SLoC