Compare commits

...
Author SHA1 Message Date
5850cff536
display lock warnings on every operation not just show-locks
Some checks failed
Build Container / Build Container (push) Failing after 2m43s
2026-07-23 14:19:42 +02:00
d0a865e85a
correct open/close wording which was incosistent 2026-07-23 14:13:30 +02:00
a750a67d17
add show-locks to usage string 2026-07-22 19:47:46 +02:00
2 changed files with 38 additions and 15 deletions

View file

@ -12,8 +12,7 @@ pub struct ApiLock {
#[derive(Debug, Eq, PartialEq, Hash, Deserialize)]
pub struct ApiLockStatus {
pub is_unreachable: bool,
#[serde(default)]
pub is_low_batteray: bool,
pub is_low_battery: bool,
pub is_error_jammed: bool,
pub lock_target_level: LockTargetLevel,
pub lock_state: LockState,

View file

@ -36,7 +36,7 @@ async fn main() -> eyre::Result<()> {
"dooris-over-ssh: Your personal door assistant with an extra serving of chaos"
);
println!(
"Usage: ssh dooris@dooris.ccchh.net help | lock <door> [wait|nowait] | unlock <door> [wait|nowait]"
"Usage: ssh dooris@dooris.ccchh.net <help | show-locks | lock <door> [wait|nowait] | unlock <door> [wait|nowait]>"
);
println!();
println!("Commands:");
@ -52,7 +52,7 @@ async fn main() -> eyre::Result<()> {
" 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!(" 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!();
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"
);
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.");
exit(0);
}
@ -72,6 +72,7 @@ async fn main() -> eyre::Result<()> {
let lock = find_lock(&api, &lock_name).await?;
println!("dooris at your service, locking {} now…", lock.name);
print_lock_warnings(&lock);
api.operate_lock(&lock.id, DesiredLockState::CLOSED).await?;
if wait_until_done {
@ -90,7 +91,8 @@ async fn main() -> eyre::Result<()> {
let api = ApiClient::new_from_env()?;
let lock = find_lock(&api, &lock_name).await?;
println!("dooris at your service, locking {} now…", lock.name);
println!("dooris at your service, unlocking {} now…", lock.name);
print_lock_warnings(&lock);
api.operate_lock(&lock.id, DesiredLockState::OPEN).await?;
if wait_until_done {
@ -108,15 +110,7 @@ async fn main() -> eyre::Result<()> {
for i_lock in locks.iter() {
println!(">> {}", i_lock.name);
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 !!!");
}
print_lock_warnings(&lock);
println!(" State: {:?}", i_lock.status.lock_state);
println!(" Desired State: {:?}", i_lock.status.lock_target_level);
println!(" Acitivty: {:?}", i_lock.status.activity_state);
@ -164,3 +158,33 @@ async fn wait_for_lock_state(
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!(" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
}
}