A Home Assistant custom integration that turns every numeric percent battery sensor into an actionable predicted-replacement-by datetime, with auto-detection of replacements, lithium/alkaline chemistry profiles, a confidence ladder, cold-start backfill from long-term statistics, and a forward-prediction service. HACS-installable. Implements the add-battery-lifetime OpenSpec change: - 56/62 tasks done (10.2-10.7 are manual-validation gates) - 18 spec requirements across 5 capabilities - 107 unit tests passing under pytest-homeassistant-custom-component Co-authored-by: Cursor <cursoragent@cursor.com>
64 lines
1.3 KiB
Bash
Executable File
64 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
usage() {
|
|
echo "Usage:"
|
|
echo " $0 create <topic> [base-branch]"
|
|
echo " $0 list"
|
|
echo " $0 remove <topic>"
|
|
exit 1
|
|
}
|
|
|
|
sanitize_topic() {
|
|
local topic="${1:-}"
|
|
if [[ -z "$topic" ]]; then
|
|
usage
|
|
fi
|
|
echo "$topic" | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | tr -cd 'a-z0-9._-'
|
|
}
|
|
|
|
cmd="${1:-}"
|
|
case "$cmd" in
|
|
create)
|
|
topic="$(sanitize_topic "${2:-}")"
|
|
base="${3:-master}"
|
|
branch="agent/${topic}"
|
|
wt_root=".worktree"
|
|
wt_path="${wt_root}/${topic}"
|
|
|
|
mkdir -p "$wt_root"
|
|
|
|
if [[ -e "$wt_path" ]]; then
|
|
echo "Worktree path already exists: $wt_path"
|
|
exit 1
|
|
fi
|
|
|
|
git fetch --all --prune
|
|
git worktree add "$wt_path" -b "$branch" "$base"
|
|
{
|
|
echo "owner=${USER:-unknown}"
|
|
echo "task=${topic}"
|
|
echo "branch=${branch}"
|
|
date -u +"created_at=%Y-%m-%dT%H:%M:%SZ"
|
|
} > "${wt_path}/.agent-lock"
|
|
echo "Created worktree: $wt_path"
|
|
echo "Branch: $branch"
|
|
;;
|
|
list)
|
|
git worktree list
|
|
;;
|
|
remove)
|
|
topic="$(sanitize_topic "${2:-}")"
|
|
wt_path=".worktree/${topic}"
|
|
if [[ ! -d "$wt_path" ]]; then
|
|
echo "Worktree path not found: $wt_path"
|
|
exit 1
|
|
fi
|
|
git worktree remove "$wt_path"
|
|
echo "Removed worktree: $wt_path"
|
|
;;
|
|
*)
|
|
usage
|
|
;;
|
|
esac
|