Repository navigation
Add proactive readiness alerts, maintenance timer, and bundled bluepr… - #327
Merged
Merged
Conversation
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
Adds proactive generator readiness tracking persisted in Home Assistant storage (
Store), expands Home Assistant Repairs alerts for battery, exercise, maintenance, and subscription health, exposesHours Until Service,Missed Exercise, andReset Maintenance Timerentities per generator, and bundles three validated automation blueprints that install automatically on integration setup.Motivation
ConfigEntry.datawould trigger unnecessary reloads on every poll; usinghomeassistant.helpers.storage.Storekeeps persistence completely reload-free.Key Changes
custom_components/generac/const.py,config_flow.py,translations/{en,fr,nb,pt}.json):BUTTON = "button"toPLATFORMS([BINARY_SENSOR, SENSOR, WEATHER, IMAGE, BUTTON]).CONF_SERVICE_INTERVAL_HOURS = "service_interval_hours"(default100,int),CONF_EXERCISE_INTERVAL_DAYS = "exercise_interval_days"(default16,int;0disables missed-exercise alerts), andCONF_LOW_BATTERY_THRESHOLD = "low_battery_threshold"(default12.2,float) toCONF_OPTIONS.GeneracOptionsFlowHandlerwith_option_validator(non-negativeint/vol.Coerce(float)ranges) and safeentry_optionsmapping reads.en.json,fr.json,nb.json, andpt.json, plus Repairsissuesentries (low_battery_voltage,missed_exercise,maintenance_due,subscription_dunning) intranslations/en.json.custom_components/generac/readiness.py,coordinator.py,utils.py):entry_options,get_detail_property_value, andsafe_floathelpers intoutils.py(reused bysensor.py,readiness.py,issues.py,coordinator.py,config_flow.py, and__init__.py).ReadinessTrackerbacked byStore(hass, 1, f"{DOMAIN}.{entry.entry_id}.readiness")(instantiated only whenentry.entry_idis astr).{"last_exercise_ts": float, "last_run_time": float | None, "service_baseline_hours": float}: initializesservice_baseline_hours = current_run_time or 0.0on first sight to prevent day-1 false alarms, detects exercise activity viaapparatusStatus in (2, 3)(Running/Exercising) or positiverun_timedeltas between polls, and exposeshours_since_service,hours_until_service,days_since_exercise,is_missed_exercise, andasync_reset_service_timeron bothReadinessTrackerandGeneracDataUpdateCoordinator.custom_components/generac/issues.py,__init__.py):async_update_device_health_issuesandasync_delete_all_entry_issues(invoked alongsideasync_remove_readiness_storeinasync_remove_entry):low_battery_voltage(low_battery_voltage_{entry_id}_{device_id}): raised when generator detail property70satisfies0 < voltage < low_battery_threshold; cleared when>= threshold,0, orNone.missed_exercise(missed_exercise_{entry_id}_{device_id}): raised whenexercise_interval_days > 0and(now - last_exercise_ts) > exercise_interval_days * 86400; cleared on exercise/run activity or when set to0.maintenance_due(maintenance_due_{entry_id}_{device_id}): raised whenservice_interval_hours > 0 and hours_since_service >= service_interval_hoursordetail.hasMaintenanceAlert is True; cleared once timer is reset andhasMaintenanceAlertis falsy.subscription_dunning(subscription_dunning_{entry_id}_{device_id}): raised whendetail.subscription is not None and detail.subscription.isDunning is True; cleared otherwise.custom_components/generac/sensor.py,binary_sensor.py,button.py):HoursUntilServiceSensor(sensor.py,entity_key = "hours_until_service",entity_label = "Hours Until Service",SensorDeviceClass.DURATION, unitUnitOfTime.HOURS("h"),SensorStateClass.MEASUREMENT,_attr_icon = "mdi:wrench-clock").binary_sensor.pysensors(item: Item | None = None)and addedGeneracMissedExerciseSensor(entity_key = "missed_exercise",entity_label = "Missed Exercise",BinarySensorDeviceClass.PROBLEM) for generators (DEVICE_TYPE_GENERATOR).custom_components/generac/button.pywithResetServiceTimerButton(entity_key = "reset_service_timer",entity_label = "Reset Maintenance Timer",_attr_icon = "mdi:wrench-check"), resettingservice_baseline_hoursto currentrun_time, re-evaluating Repairs issues, and updating entity listeners immediately.custom_components/generac/blueprints.py,blueprints/automation/*.yaml,__init__.py,.pre-commit-config.yaml,README.md):generac_outage_load_shedding.yaml,generac_fault_dealer_alert.yaml, andgenerac_storm_readiness_digest.yaml.install_bundled_blueprints(idempotent, writes only when missing or modified) called viaawait hass.async_add_executor_job(...)inasync_setup_entry(logging a warning onOSError)..pre-commit-config.yamlcheck-yamlhook withargs: [--unsafe]for!inputtags and documented readiness alerts, maintenance timer, and bundled blueprints inREADME.md.tests/):tests/test_blueprints.py(validating all 3 YAML blueprints againstBlueprint(..., expected_domain="automation", schema=AUTOMATION_BLUEPRINT_SCHEMA),BlueprintInputssubstitution +_async_validate_config_item, andinstall_bundled_blueprints),tests/test_button.py, andtests/test_readiness.py.tests/test_issues.py,tests/test_sensor.py,tests/test_binary_sensor.py,tests/test_init.py,tests/test_config_flow.py, andtests/test_entity_registry.py(len(classes) == 37,NEW_SUFFIXESupdated).User Configuration / Migration Notes
unique_ids orentity_keys.service_baseline_hoursto their currentrun_timeandlast_exercise_tsto first-poll time on upgrade/first setup, avoiding day-1 false maintenance or missed-exercise alarms.<config>/blueprints/automation/generac/on integration setup.Test Plan
/Users/binarydev/Projects/ha-generac/.venv/bin/pytest --maxfail=3 --disable-warnings:155 passedacross all 16 test files (test_api.py,test_auth.py,test_binary_sensor.py,test_blueprints.py,test_button.py,test_config_flow.py,test_coordinator.py,test_diagnostics.py,test_entity.py,test_entity_registry.py,test_image.py,test_init.py,test_issues.py,test_readiness.py,test_sensor.py,test_weather.py)./opt/homebrew/bin/pre-commit run --all-files --show-diff-on-failure: all 8 hooks passed cleanly with zero remaining diffs.manifest.jsonandtranslations/{en,fr,nb,pt}.json, and exact{placeholder}parity betweenissues.pyandtranslations/en.json.