Massive Overhaul of Structure, Functionality, and Usage, See Desc.#4
Open
XxInvictus wants to merge 48 commits into
Open
Massive Overhaul of Structure, Functionality, and Usage, See Desc.#4XxInvictus wants to merge 48 commits into
XxInvictus wants to merge 48 commits into
Conversation
Migrated codebase to a src-layout with alexa_manager as a package, added configuration and TOML-based settings, removed legacy main.py, and introduced modularized files for API, config, models, and utilities. Updated README with installation, usage, and configuration instructions, and added initial test suite and pyproject.toml for modern dependency management using uv.
Implements functions for syncing Home Assistant areas with Alexa groups, including batch update and creation logic. Adds a global DRY_RUN flag and modifies destructive actions (delete, create) to support dry-run simulation. Updates CLI documentation and argument parsing for new features. Expands test coverage for group sync, update, and dry-run behaviors.
This commit applies forgotten Ruff Format/Check
Introduces DRY_RUN handling for entity and group deletion, ensuring no network requests are made in dry-run mode. Adds normalization and conversion utilities for Home Assistant area names, and implements logic to skip ignored areas when creating Alexa groups. Updates configuration and tests to support these features.
Introduces an --interactive flag to require user confirmation before performing batch create or delete actions on entities and groups. Updates main.py to support interactive prompts, refactors API logic to delegate confirmation to main, and documents the new mode in README.md for safer destructive operations.
Added comprehensive ignore rules for JetBrains IDEs, Visual Studio Code, Python, and related tools. This update helps prevent IDE, build, and environment files from being tracked in version control, improving project cleanliness and reducing accidental commits of local or sensitive files.
Replaces 'uv install' with 'uv python install' and updates lockfile usage from 'uv sync --use-lock' to 'uv sync --frozen' for improved clarity and accuracy in dependency management instructions.
Introduces --test-alexa-groups CLI argument to test Alexa group creation, update, and deletion. Refactors Alexa group API/model to support expanded fields and robust applianceId handling. Updates .gitignore pattern, README CLI docs, and adds list sanitization utilities for hashable group fields.
Refactored test mocks in test_main.py to use create_groups_from_areas and IGNORED_HA_AREAS constant. Updated test_models.py to account for model sanitization of defaults field to stringified dicts. Minor formatting fix in main.py for rprint output.
Refactored sanitize_list, flatten_dict, and format_appliance_id_for_api from models.py to utils.py for better code organization and reuse. Updated imports and removed duplicate code from models.py.
Introduces helper functions for constructing AlexaEntity objects and normalizing Home Assistant entity IDs. Refactors batch confirmation and deletion logic for entities and groups, improving dry-run support and error handling. Updates configuration loading to use safer defaults and clarifies config sections. Enhances utility functions with better type annotations, error handling, and documentation. Moves group creation logic to a dedicated function and exposes it for testing.
Expanded test coverage for utils, config, models, and API modules to include edge cases such as empty, malformed, large, and invalid inputs. Improved print_table to handle non-dict rows gracefully. Refactored test mocks for clarity and consistency.
Add action for pytests
Introduces pydantic-based validation for configuration loading in config.py, ensuring robust config parsing and error reporting. Enhances error handling and logging in api.py for entity loading and group creation, ensuring DRY_RUN is respected throughout. Updates dependencies to include pydantic, adds code review suggestions, and improves test reliability.
Split main.py CLI logic into modular functions for argument parsing, flag setting, GET action handling, action dispatch, and failure reporting. Enhanced type validation and error handling in models.py, including stricter input checks and improved docstrings. Improved utils.py progress bar to catch and log unexpected errors, ensuring failed items are collected. Updated tests to verify new error handling and CLI exit behavior. Removed obsolete CODE_REVIEW_SUGGESTIONS.md.
Added workflow badges, a detailed index, and horizontal rules to improve navigation and clarity. Updated usage examples to use 'uv run' consistently and reorganized sections for better readability.
Refactored functions in api.py to set the headers argument default to None and assign ALEXA_HEADERS if not provided. This improves flexibility for custom header usage and avoids mutable default arguments.
Refactored mapping logic to use normalized exact string matching between Home Assistant entity IDs and Alexa Appliance IDs. Added normalization helper functions and updated output to show only exact matches, improving reliability of entity mapping.
Introduces a --filter-entities CLI argument to filter Alexa entities and endpoints by description for display and deletion actions. Updates argument parsing, action dispatch, and table output logic to support filtering. Adds filtering methods to AlexaEntities model and updates README with new usage examples.
Introduces .pre-commit-config.yaml to enable Ruff linting and formatting on commits. Adds pre-commit to project dependencies in pyproject.toml and requirements.txt for automated code quality checks.
Introduces support for sending Alexa commands via Home Assistant Alexa Media Player integration, including device and entity ID configuration, command sending, and device discovery with retry logic. Updates configuration, API, and CLI to support new features, and adds/updates tests for Alexa Media Player command functions and device discovery.
This commit adds extensive unit tests for Alexa group and entity management functions, including get_entities, update_alexa_group, find_group_by_id, put_alexa_group, update_alexa_groups_batch, sync_ha_alexa_groups, find_missing_ha_groups, create_alexa_group_for_ha_area, and sync_alexa_group_entities. The tests cover success and failure scenarios, edge cases, error handling, and large input sets to ensure robust functionality.
The sync_alexa_group_entities and sync_ha_alexa_groups functions now respect the global DRY_RUN config, logging intended actions and skipping API calls when enabled. This allows safer testing and auditing of changes without modifying Alexa groups.
Corrects the cron expression to run the workflow every Saturday at 1:00 AM UTC. The previous schedule was incorrect apparently Github didn't like Sunday.
Introduces a --full-sync CLI option that automates the entire Alexa/Home Assistant synchronization process, including deleting all Alexa entities, endpoints, and groups, triggering device rediscovery, waiting for completion, and syncing HA areas with Alexa groups. Adds a dedicated delete_endpoints function for improved endpoint deletion logic. Updates documentation and expands test coverage for new and existing features.
Refactored usage of DRY_RUN to use dynamic_config for runtime changes. Added DRY_RUN checks to Alexa device discovery and sync functions, allowing workflows to simulate actions without making actual API calls. Updated main workflow summary to consolidate discovery status.
Unifies and renames area normalization and conversion functions for consistency across the codebase. Updates all usages to use `normalise_area_name` for normalization (now using underscores and lowercase) and `convert_normalised_area_to_alexa_name` for Alexa group name formatting. Removes duplicate normalization logic from config, updates tests, and ensures ignored areas are handled with normalized names.
Enhances wait_for_device_discovery to require the Alexa entity count to remain stable for several consecutive polls after an increase, reducing false positives. Updates full_sync_workflow to respect the --filter-entities flag for selective deletion of entities and endpoints, and improves group deletion handling. Adjusts related tests to match the new discovery logic.
Remove schedule
|
Completely amazing, I just removed my Plex devices in one shot |
|
Wow this looks very promising! Not able to get it to work though. I deleted several skills because I am switching to HA, but that left behind a lot of orphaned (ghost) devices. Getting an error for all devices that it tries to delete (Ring, TP-Link, Gree, etc..). > uv run alexa_manager --delete-entities --filter-entities
. . .
2025-11-11 23:02:59 DEBUG: Starting new HTTPS connection (1): na-api-alexa.amazon.com:443
2025-11-11 23:03:03 DEBUG: https://na-api-alexa.amazon.com:443 "GET /api/behaviors/entities?skillId=amzn1.ask.1p.smarthome&skillId=amzn1.ask.1p.smarthome HTTP/1.1" 200 None
2025-11-11 23:03:03 DEBUG: Loaded 385 Alexa entities.
Deleting Alexa entities... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0% -:--:--2025-11-11 23:03:03
2025-11-11 23:03:20 DEBUG: Starting new HTTPS connection (1): na-api-alexa.amazon.com:443
2025-11-11 23:03:24 DEBUG: Check delete response status code: 200
2025-11-11 23:03:24 DEBUG: Check delete response text: {"layout":{"type":"Default","template":{"header":{"primaryItem":{"type":"AlexaInterface","interfaceName":"Alexa.PowerController","instance":null,"version":"3","properties":{"supported":[{"name":"powerState"}],"readOnly":false,"proactivelyReported":true,"retrievable":true},"resources":null,"configuration":null,"layoutOptions":null,"semantics":null},"statusItems":[]},"secondary":{"items":[]},"tertiary":{"items":[]}},"options":{}}}
2025-11-11 23:03:24 ERROR: Unexpected error processing item 'AlexaEntity(id=***, displayName=***, description=Smart Wi-Fi Plug Mini, connected via TP-LINK Kasa, appliance_id=)': RetryError[<Future at 0x7584b9efc410 state=finished raised RetryError>] |
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.
I went a little bit crazy on this, totally understand if you don't want to accept the PR as it kind of became a beast. I am happy to manage it as a separate repo and add you to the Acknowledgements instead.
I didn't really come at this with a plan just that I wanted to improve it for my personal use so may be a bit of a mess as I have just thrown different functionality in.
Important
A little beware about the Github Actions, may want to trim them down to reduce chances of unintentional execution costs from overrunning included allocations. Mostly had them running pretty liberally just to prevent regression when adding functionality. If you keep them you will need to update the Github space name in the README widgets.
Some of the changes are listed below but I very well may miss something here:
src/and splitting different functionality into separate filesuvpackage manager and ruff linterpytest