feat: configurable report mode, batch history import, and offline timeout#70
Open
wxtry wants to merge 19 commits intomash2k3:mainfrom
Open
feat: configurable report mode, batch history import, and offline timeout#70wxtry wants to merge 19 commits intomash2k3:mainfrom
wxtry wants to merge 19 commits intomash2k3:mainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Options were silently wiped by async_create_entry(data={})
- Now: async_update_entry for model data, async_create_entry for options
- Use config_entry.entry_id instead of private _config_entry_id
- Guard _auto_switch_report_mode_on_battery_state() with options check - Default initial TLV config to Historic mode - Change JSON default update_interval from 15s to 300s Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- TLV Historic mode uses config_entry.options timeout (default 65 min) - JSON devices use config_entry.options timeout (default 65 min) - Real-time mode keeps fixed 300s timeout Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add _import_batch_statistics() helper - CMD 0x42 history: all points imported via async_import_statistics - Latest point still updates entity current state - Statistics aligned to 5-minute boundaries - Fix test_batch_history alignment test math (1709500123 % 300 = 223, not 123) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Type 17: parse batch sensorData, update entities from latest point - Import all batch points to HA long-term statistics - Send ACK when need_ack=1 - Type 13 explicitly ignored (was silently dropped before) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
HA's async_import_statistics requires statistic_id to be lowercase.
async_import_statistics validates statistic_id as entity_id format and requires source="recorder". External statistics need async_add_external_statistics which accepts the colon-separated format. Also adds enhanced status logging and error handling for statistics import to aid debugging offline timeout behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
HA requires timestamps at the top of the hour (minutes=0, seconds=0). Changed from 5-minute alignment to 1-hour alignment, and aggregate multiple data points within the same hour by averaging. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Firmware 2.0.6 sends historical data via CMD 0x31 instead of CMD 0x42. Both carry identical sensorData[] arrays. Treat CMD 0x31 the same as CMD 0x42 for batch statistics import. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Keep recorder dependency addition but revert fork-specific name, documentation URL, issue tracker, and version to upstream values. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
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.
Summary
Three enhancements for TLV and JSON device support:
Configurable auto-switch report mode — Adds an
auto_switch_report_modeoption (default: disabled) so users can control whether the integration automatically switches between realtime/historic mode on charge state changes.Batch history data import to HA Statistics — Imports historical data points (JSON Type 17, TLV CMD 0x42 and CMD 0x31) into Home Assistant long-term statistics via
async_add_external_statistics. Data is aggregated into hourly buckets with proper timestamp alignment. Supports both firmware 1.x (CMD 0x42) and 2.x (CMD 0x31) formats.Configurable offline timeout — Adds an
offline_timeout_minutesoption (default: 65, range: 5–1440) to accommodate devices in Historic reporting mode that only report every ~60 minutes.All three options are configurable per-device via the Options Flow UI.
Changes
sensor.py: Add_import_batch_statistics(), configurable timeout logic, auto-switch guard, CMD 0x31 supportconfig_flow.py: Extend OptionsFlowHandler with new optionsconst.py: New constants for options and defaultsmanifest.json: Addrecorderdependencytranslations/en.json: UI labels for new optionstests/: Unit tests for all three featuresTest plan
test_auto_switch.py— verifies auto-switch guard logictest_batch_history.py— verifies statistics metadata, timestamp alignment, hourly averaging, zero-timestamp filteringtest_offline_timeout.py— verifies configurable timeout behavior🤖 Generated with Claude Code