Repository navigation
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
Implements state-aware adaptive cloud polling (
idle,active,cooldown, andboostmodes) forGeneracDataUpdateCoordinator, introduces the generator Outage Boost Poll (button) platform entity, registers thegenerac.boost_pollingservice (documented inservices.yamlandtranslations/en.json), and exposesactive_scan_intervalconfiguration across the UI options and reconfigure flows.Motivation
900s default) and timely updates during generator runs, exercises, warnings, or utility power outages.active_scan_interval(120s default) when devices are active—with a300s cooldown back to idle—gives responsive live telemetry without hammering the API during standby.generac.boost_pollingaction lets users and automations trigger immediate fast polling on grid power loss.Key Changes
custom_components/generac/const.py):BUTTON = "button"toPLATFORMS([BINARY_SENSOR, SENSOR, WEATHER, IMAGE, BUTTON]).CONF_ACTIVE_SCAN_INTERVAL = "active_scan_interval",DEFAULT_ACTIVE_SCAN_INTERVAL = 120,ACTIVE_COOLDOWN_SECONDS = 300,DEFAULT_BOOST_DURATION_MINUTES = 30, andSERVICE_BOOST_POLLING = "boost_polling".CONF_ACTIVE_SCAN_INTERVAL(andbuttonviaPLATFORMS) toCONF_OPTIONS.custom_components/generac/coordinator.py):idle_scan_interval(CONF_SCAN_INTERVAL, default900) andactive_scan_interval(CONF_ACTIVE_SCAN_INTERVAL, default120) safely viacollections.abc.Mapping, clamping both>= 10s and computingfast_scan_interval = min(idle_scan_interval, active_scan_interval)._is_fleet_active(items)detecting generatorapparatusStatusin(2, 3, 4, 5)(Running,Exercising,Warning,Stopped),isConnecting is True,showWarning is True, or any apparatus property withisRunning is True._cooldown_until(300s) and_boost_untilviatime.monotonic(), exposespolling_mode("boost" | "active" | "cooldown" | "idle") andis_fast_pollingproperties, dynamically adjustsupdate_interval, and addsasync_trigger_boost(duration_seconds=DEFAULT_BOOST_DURATION_MINUTES * 60)to set boost duration, switch to fast polling, and request an immediate refresh.custom_components/generac/button.py):OutageBoostButton(GeneracEntity, ButtonEntity)for each generator (DEVICE_TYPE_GENERATOR) withentity_key = "boost_polling",entity_label = "Outage Boost Poll", and_attr_icon = "mdi:lightning-bolt-circle", callingawait self.coordinator.async_trigger_boost()on press.custom_components/generac/__init__.py,custom_components/generac/services.yaml):generac.boost_pollinginasync_setup_entrywithBOOST_POLLING_SCHEMA(duration_minutes1–120default30, optionalentry_id), targeting the matching or all loadedGeneracDataUpdateCoordinatorinstances (ignoring non-coordinator domain data).generac.boost_pollinginasync_unload_entrywhenunloadedisTrueand noGeneracDataUpdateCoordinatorremains inhass.data[DOMAIN].custom_components/generac/services.yamldocumentingboost_pollingfields and selectors.custom_components/generac/config_flow.py,translations/{en,fr,nb,pt}.json,README.md):CONF_ACTIVE_SCAN_INTERVALinasync_step_reconfigure(including across MFA flows) andGeneracOptionsFlowHandler(viaCONF_OPTIONS).translations/{en,fr,nb,pt}.jsonwithactive_scan_intervalandbuttonlabels, and added theservices.boost_pollingsection intranslations/en.json.buttonplatform, adaptive polling intervals/cooldown,Outage Boost Pollbutton, andgenerac.boost_pollingservice inREADME.md.tests/):tests/test_button.py(button attributes, generator-only platform setup, HAbutton.pressintegration).tests/test_coordinator.py(interval clamping,min(idle, active), mock options fallback,_is_fleet_activevariants,idle -> active -> cooldown -> idletransitions, andasync_trigger_boostlifecycle).tests/test_init.py(idempotent service registration, multi-entry &entry_idtargeting, out-of-range schema validation, non-coordinator domain key safety, unload cleanup, andservices.yaml+async_get_all_descriptionsvalidation).tests/test_entity_registry.py(NEW_SUFFIXESforboost_polling->button.generator_outage_boost_poll,len(classes) == 35) andtests/test_config_flow.py(test_options_flow,active_scan_intervalreconfigure + MFA preservation).User Configuration / Migration Notes
unique_ids orentity_keys.scan_interval(default900s) as the idle interval and gainactive_scan_interval(default120s) plus theOutage Boost Pollbutton entity per generator on reload/upgrade.generac.boost_pollingfrom automations.Test Plan
/Users/binarydev/Projects/ha-generac/.venv/bin/pytest --maxfail=3 --disable-warnings:146 passedacross all 14 test modules (test_api.py,test_auth.py,test_binary_sensor.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_sensor.py,test_weather.py)./opt/homebrew/bin/pre-commit run --all-files --show-diff-on-failure: all 8 hooks passed (check-added-large-files,check-yaml,end-of-file-fixer,trailing-whitespace,flake8,reorder-python-imports,black,prettier).manifest.jsonandtranslations/{en,fr,nb,pt}.json, plusservices.yamlvalidation against Home Assistant's_SERVICES_SCHEMAandasync_get_all_descriptions.