Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Typo in in_progess_instances Function Name and Missing Domain Filtering #2523

Open
jleinenbach opened this issue Sep 14, 2024 · 0 comments

Comments

@jleinenbach
Copy link

jleinenbach commented Sep 14, 2024

Describe the bug

The function in_progess_instances in the Alexa Media integration contains a typo in its name and lacks domain-specific filtering. This prevents the function from correctly identifying in-progress configuration flows for the Alexa Media integration, potentially allowing duplicate configuration attempts and causing unexpected behavior.

To Reproduce

  1. Initiate a configuration flow for the Alexa Media integration in Home Assistant.
  2. Attempt to start another configuration flow for the same Alexa Media instance simultaneously.
  3. Observe that duplicate flows may be allowed due to the typo and lack of proper filtering.

Expected behavior

The function should be correctly named in_progress_instances and should filter configuration flows to include only those related to the Alexa Media integration. This ensures that duplicate configuration flows are prevented and only relevant flows are managed.

Screenshots

No screenshots available.

System details

  • Home Assistant version: 2024.9.1
  • alexa_media version (from const.py or HA startup log): 4.12.12
  • Is Amazon 2FA/2SV enabled (y/n): y
  • Amazon Domain: amazon.de

Additional context

The function in_progess_instances is intended to return a set of in-progress Alexa Media configuration flows. However, due to the typo in its name and the absence of filtering by DOMAIN, it does not function as intended. Correcting the function name to in_progress_instances and adding a filter to include only flows where entry["handler"] == DOMAIN will ensure accurate identification and management of in-progress flows for the Alexa Media integration.

Proposed Fix

Before

@callback
def in_progess_instances(hass):
    """Return a set of in progress Alexa Media flows."""
    return {entry["flow_id"] for entry in hass.config_entries.flow.async_progress()}

After

@callback
def in_progress_instances(hass):
    """Return a set of in-progress Alexa Media flows."""
    return {
        entry["flow_id"]
        for entry in hass.config_entries.flow.async_progress()
        if entry["handler"] == DOMAIN  # Ensure only Alexa Media flows are included
    }

After correcting the typo in config_flow.py, you also need to update the import statement in __init__.py to reference the newly renamed function in_progress_instances correctly.

Explanation of Improvements:

  1. Fixed Typo in Function Name:

    • Before: def in_progess_instances(hass):
    • After: def in_progress_instances(hass):
    • Reason: Corrects the spelling from in_progess_instances to in_progress_instances to ensure the function name is accurate and prevent potential call errors.
  2. Added Domain-Specific Filtering:

    • Before: The function returned all in-progress flow IDs without filtering.
    • After: The function now includes a condition if entry["handler"] == DOMAIN to filter and return only the flow IDs related to the Alexa Media integration.
    • Reason: Ensures that only Alexa Media-specific configuration flows are considered, preventing interference from other integrations' flows.

Where DOMAIN Comes From:

  • Definition in const.py:

    # const.py
    
    DOMAIN = "alexa_media"
    
    # Other constants...
    • Explanation: The DOMAIN constant uniquely identifies the Alexa Media integration within Home Assistant. It is defined in the const.py file and imported wherever needed in the integration's modules.
  • Usage in Config Flow:

    from .const import DOMAIN  # DOMAIN is defined as "alexa_media" in const.py
    • Explanation: The DOMAIN is imported from const.py to ensure that it consistently represents the Alexa Media integration across different parts of the codebase.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant