fix: Resolve scenes.yaml path across different HA installation methods#12
Merged
thorstenhornung1 merged 1 commit intomainfrom Dec 15, 2025
Merged
Conversation
Implements proper path resolution to support relative paths like "scenes.yaml" across Docker, HAOS, VM, and core installations. ## Changes ### Path Resolution (Core Fix) - Update load_scenes_file() to accept hass parameter - Use hass.config.path() to resolve relative paths - Absolute paths continue to work unchanged - Enhanced error messages with both input and resolved paths - Added validation for empty paths and directories ### Auto-Detection with Graceful Fallback - Add _detect_scenes_path() method to auto-detect scenes file - Tries common paths: scenes.yaml, scenes.yml, config/scenes.yaml - Pre-fills config flow form with detected path - Shows warning if path cannot be auto-detected - User can manually adjust if needed ### Updated Call Sites - Runtime setup in __init__.py (line 46) - Config flow validation in config_flow.py (line 83) ## Benefits - Users can use default "scenes.yaml" without specifying absolute paths - Works consistently across all installation methods - Backward compatible - existing absolute paths work unchanged - Better UX with auto-detection and pre-filling - Clear error messages for troubleshooting Fixes hugobloem#217 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
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.
Problem
The integration fails to automatically locate
scenes.yamlacross different Home Assistant installation methods (Docker, HAOS, VM), requiring users to manually specify absolute paths like/config/scenes.yaml. This affects user experience and creates confusion during setup.User Impact:
scenes.yamldoes not workAffected Installations:
Root Cause
The integration uses
os.path.exists(scene_path)which resolves relative paths against the current working directory, not the Home Assistant configuration directory. Different installation methods have different working directories:/or/usr/src/app/config/root/configor/config~/.homeassistantThe integration did not leverage Home Assistant's
hass.config.path()method, which is specifically designed to handle this abstraction layer.Solution
Implemented a two-part solution:
1. Path Resolution (Core Fix)
Use Home Assistant's native
hass.config.path()API to properly resolve relative paths to the configuration directory, regardless of installation method.File:
custom_components/stateful_scenes/__init__.pyKey Changes:
How it works:
scenes.yaml) → resolved to{config_dir}/scenes.yaml/config/scenes.yaml) → used unchanged (backward compatible)scenes/custom.yaml) → resolved to{config_dir}/scenes/custom.yaml2. Auto-Detection with Graceful Fallback
Added intelligent path detection during configuration flow setup to improve user experience.
File:
custom_components/stateful_scenes/config_flow.pyKey Changes:
User Experience:
Changes Made
Updated Files
1.
__init__.py(Lines 89-145)load_scenes_file()signature to accepthassparameterhass.config.path()2.
config_flow.py(Lines 6, 65-97, 142-166)osimport for file existence checks_detect_scenes_path()method for auto-detectionasync_step_configure_internal_scenesto use auto-detectionload_scenes_file()call to passself.hassat line 83Benefits
For Users
✅ Default
scenes.yamlpath works out of the box✅ No need to determine absolute paths manually
✅ Works consistently across all installation methods
✅ Auto-detection pre-fills correct path
✅ Clear guidance if path cannot be found
✅ Backward compatible - existing configs continue to work
For Developers
✅ Follows Home Assistant best practices
✅ Uses official
hass.config.path()API✅ Better error messages for troubleshooting
✅ Reduced support burden
✅ Maintainable and well-documented code
Testing
Test Scenarios
scenes.yaml(default)scenes.yaml/config/scenes.yamlscenes/custom.yaml/config/scenes.yamlmissing.yaml""or" "scenes_folderInstallation Matrix
/configscenes.yaml/configscenes.yaml/configscenes.yaml~/.homeassistantscenes.yamlBreaking Changes
None. This is a pure enhancement with full backward compatibility:
Migration Guide
No action required. Users with existing configurations using absolute paths can optionally switch to relative paths for cleaner configuration, but it is not necessary.
Optional cleanup:
References
Checklist
hass.config.path()APIFixes hugobloem#217
🤖 Generated with Claude Code