Compare commits
2 changed files with 15 additions and 38 deletions
|
|
@ -12,7 +12,8 @@ pub struct ApiLock {
|
||||||
#[derive(Debug, Eq, PartialEq, Hash, Deserialize)]
|
#[derive(Debug, Eq, PartialEq, Hash, Deserialize)]
|
||||||
pub struct ApiLockStatus {
|
pub struct ApiLockStatus {
|
||||||
pub is_unreachable: bool,
|
pub is_unreachable: bool,
|
||||||
pub is_low_battery: bool,
|
#[serde(default)]
|
||||||
|
pub is_low_batteray: bool,
|
||||||
pub is_error_jammed: bool,
|
pub is_error_jammed: bool,
|
||||||
pub lock_target_level: LockTargetLevel,
|
pub lock_target_level: LockTargetLevel,
|
||||||
pub lock_state: LockState,
|
pub lock_state: LockState,
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ async fn main() -> eyre::Result<()> {
|
||||||
"dooris-over-ssh: Your personal door assistant with an extra serving of chaos"
|
"dooris-over-ssh: Your personal door assistant with an extra serving of chaos"
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"Usage: ssh dooris@dooris.ccchh.net <help | show-locks | lock <door> [wait|nowait] | unlock <door> [wait|nowait]>"
|
"Usage: ssh dooris@dooris.ccchh.net help | lock <door> [wait|nowait] | unlock <door> [wait|nowait]"
|
||||||
);
|
);
|
||||||
println!();
|
println!();
|
||||||
println!("Commands:");
|
println!("Commands:");
|
||||||
|
|
@ -52,7 +52,7 @@ async fn main() -> eyre::Result<()> {
|
||||||
" Also takes an additional parameter of \"wait\" or \"nowait\"which dictates"
|
" Also takes an additional parameter of \"wait\" or \"nowait\"which dictates"
|
||||||
);
|
);
|
||||||
println!(" whether the CLI exit as soon as the lock operation is queued or whether");
|
println!(" whether the CLI exit as soon as the lock operation is queued or whether");
|
||||||
println!(" it waits until the lock status changes to closed.");
|
println!(" it waits until the lock status changes to open.");
|
||||||
println!(" Defaults to \"wait\" if not specified.");
|
println!(" Defaults to \"wait\" if not specified.");
|
||||||
println!();
|
println!();
|
||||||
println!(" unlock <lock> [wait|nowait] -> Unlocks the lock identified with <lock>.");
|
println!(" unlock <lock> [wait|nowait] -> Unlocks the lock identified with <lock>.");
|
||||||
|
|
@ -60,7 +60,7 @@ async fn main() -> eyre::Result<()> {
|
||||||
" Also takes an additional parameter of \"wait\" or \"nowait\"which dictates"
|
" Also takes an additional parameter of \"wait\" or \"nowait\"which dictates"
|
||||||
);
|
);
|
||||||
println!(" whether the CLI exit as soon as the lock operation is queued or whether");
|
println!(" whether the CLI exit as soon as the lock operation is queued or whether");
|
||||||
println!(" it waits until the lock status changes to open.");
|
println!(" it waits until the lock status changes to closed.");
|
||||||
println!(" Defaults to \"wait\" if not specified.");
|
println!(" Defaults to \"wait\" if not specified.");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
@ -72,7 +72,6 @@ async fn main() -> eyre::Result<()> {
|
||||||
let lock = find_lock(&api, &lock_name).await?;
|
let lock = find_lock(&api, &lock_name).await?;
|
||||||
|
|
||||||
println!("dooris at your service, locking {} now…", lock.name);
|
println!("dooris at your service, locking {} now…", lock.name);
|
||||||
print_lock_warnings(&lock);
|
|
||||||
api.operate_lock(&lock.id, DesiredLockState::CLOSED).await?;
|
api.operate_lock(&lock.id, DesiredLockState::CLOSED).await?;
|
||||||
|
|
||||||
if wait_until_done {
|
if wait_until_done {
|
||||||
|
|
@ -91,8 +90,7 @@ async fn main() -> eyre::Result<()> {
|
||||||
let api = ApiClient::new_from_env()?;
|
let api = ApiClient::new_from_env()?;
|
||||||
let lock = find_lock(&api, &lock_name).await?;
|
let lock = find_lock(&api, &lock_name).await?;
|
||||||
|
|
||||||
println!("dooris at your service, unlocking {} now…", lock.name);
|
println!("dooris at your service, locking {} now…", lock.name);
|
||||||
print_lock_warnings(&lock);
|
|
||||||
api.operate_lock(&lock.id, DesiredLockState::OPEN).await?;
|
api.operate_lock(&lock.id, DesiredLockState::OPEN).await?;
|
||||||
|
|
||||||
if wait_until_done {
|
if wait_until_done {
|
||||||
|
|
@ -110,7 +108,15 @@ async fn main() -> eyre::Result<()> {
|
||||||
|
|
||||||
for i_lock in locks.iter() {
|
for i_lock in locks.iter() {
|
||||||
println!(">> {}", i_lock.name);
|
println!(">> {}", i_lock.name);
|
||||||
print_lock_warnings(&lock);
|
if i_lock.status.is_unreachable {
|
||||||
|
println!(" !!! Lock is currently unreachable !!!");
|
||||||
|
}
|
||||||
|
if i_lock.status.is_low_batteray {
|
||||||
|
println!(" !!! Lock has low battery !!!");
|
||||||
|
}
|
||||||
|
if i_lock.status.is_error_jammed {
|
||||||
|
println!(" !!! Lock is jammed !!!");
|
||||||
|
}
|
||||||
println!(" State: {:?}", i_lock.status.lock_state);
|
println!(" State: {:?}", i_lock.status.lock_state);
|
||||||
println!(" Desired State: {:?}", i_lock.status.lock_target_level);
|
println!(" Desired State: {:?}", i_lock.status.lock_target_level);
|
||||||
println!(" Acitivty: {:?}", i_lock.status.activity_state);
|
println!(" Acitivty: {:?}", i_lock.status.activity_state);
|
||||||
|
|
@ -158,33 +164,3 @@ async fn wait_for_lock_state(
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Display big warnings if the lock is in an error state like jammed/disconnected/low battery
|
|
||||||
fn print_lock_warnings(lock: &ApiLock) {
|
|
||||||
let has_any_error =
|
|
||||||
lock.status.is_unreachable || lock.status.is_low_battery || lock.status.is_error_jammed;
|
|
||||||
|
|
||||||
if has_any_error {
|
|
||||||
println!(" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
|
||||||
}
|
|
||||||
|
|
||||||
if lock.status.is_unreachable {
|
|
||||||
println!(" !!! !!!");
|
|
||||||
println!(" !!! Lock is currently unreachable !!!");
|
|
||||||
println!(" !!! !!!");
|
|
||||||
}
|
|
||||||
if lock.status.is_low_battery {
|
|
||||||
println!(" !!! !!!");
|
|
||||||
println!(" !!! Lock has low battery !!!");
|
|
||||||
println!(" !!! !!!");
|
|
||||||
}
|
|
||||||
if lock.status.is_error_jammed {
|
|
||||||
println!(" !!! !!!");
|
|
||||||
println!(" !!! Lock is jammed !!!");
|
|
||||||
println!(" !!! !!!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if has_any_error {
|
|
||||||
println!(" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue