Repository navigation
Conversation
Adds a Battery level trigger and state in Battery & Power, built on a generic SystemMetric condition with numeric operators and a pure SystemMetricTracker (de-dupe, edge triggering, hysteresis, hold, cooldown, loop breaker, baseline) that guarantees every opened state closes. Open states and loop-breaker pauses live in diy_runtime_prefs, which is not exported. PowerModule forwards battery level only when the percent changes. The old Battery level state tile is replaced; saved BatteryLevel automations keep running and convert when edited, and disabling or deleting an open one now runs its exit actions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
I am working on an enhancement to this for future modules as well, which lets you decide the time period for an increases by or decreases by condition. For e.g. if battery reduces 5% within 30 min. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
First step of System metrics, as discussed: DIY automations can now react when the battery level meets a numeric condition, as a Trigger (one-shot) or a State (entry and exit actions). Each metric gets its own tile in its domain section: Battery level sits in Battery & Power in both lists. Later metrics (volume, temperatures, Wi-Fi/BT battery) only add a source, an enum entry and a tile in their own section.
PowerModule. The shared logic is a plain, pure-KotlinSystemMetricTrackerthat each module holds, with unit tests.ACTION_BATTERY_CHANGEDfiltering: only integer-percent changes reach the tracker, so temperature/voltage/status broadcasts (and charge-limit status flapping) are ignored.diy_runtime_prefsfile that's deliberately left out of export and backup (it describes this device's current state, likebattery_history_points). After an import, changed states close and imported ones are re-checked against the current level.Type of change
UI changes
A Battery level tile in Battery & Power in both the trigger and state lists (replacing the old state-only tile). Its sheet has a live "Now: 64%" reading, operator chips (state-only operators for states), a slider or range slider, and a collapsed Advanced section (stay true for, margin, and cooldown for triggers). Rows show a summary like "Battery level at most 20%".
State list: one Battery level tile in Battery & Power
Trigger list
Battery level sheet for a state (an old Battery level state opened, range kept)
Battery level sheet for a trigger
Loop breaker notification with Re-enable
Row summaries, and a row paused by the loop breaker
Checklist
Before submitting, please make sure:
develop(notmain)../gradlew assembleDebug../gradlew testDebugUnitTest.SettingsRepositoryfor keys and getter/setter methods. (No user settings. Runtime DIY state uses its owndiy_runtime_prefsfile next todiy_automations_prefs, so it stays out of export.)FeatureRegistry.ktfor search indexing. (N/A, no new settings.)ui/core/(RoundedCardContainer,IconToggleItem, etc.).res/values/strings.xmland drawables use rounded variants (R.drawable.rounded_*).Tested on a Pixel emulator with
dumpsys battery: a simulated charge limiter flapping 79↔80% with status and temperature changes for a minute fired nothing; triggers fire once and re-arm past the margin; the loop breaker trips on the 6th fire, Re-enable restores it and it trips again; disabling or deleting an active state (new and old Battery level) runs its exit actions; an old Battery level state converts on save without running actions; after a reboot or force-stop, active states stay active without re-running entry actions, and ones that became false exit; export, edit, import closes and re-opens states correctly. Release APK +36 KB, no dependency changes.🤖 Generated with Claude Code