Skip to content

Add config flow and yaml reload#56

Open
Snuffy2 wants to merge 1 commit intotwrecked:masterfrom
Snuffy2:Add-config_flow-and-yaml-reload
Open

Add config flow and yaml reload#56
Snuffy2 wants to merge 1 commit intotwrecked:masterfrom
Snuffy2:Add-config_flow-and-yaml-reload

Conversation

@Snuffy2
Copy link
Copy Markdown
Contributor

@Snuffy2 Snuffy2 commented Oct 1, 2025

Features

  • Add a config_flow to create new Momentary Switches
    • The settings/options for Momentary Switches created by config_flow can be changed in the Options
  • Continue to support YAML based Momentary Switches
  • Allow a Momentary Switch to be associated with another device
  • Allow for Reload of the YAML based Momentary Switches from the Developer Tools so changes can be made without restarting HA
    • While not a standalone separate config file, it still allows for YAML based momentary switches that can be changed without needing to restart HA

Note

  • It is likely that existing Momentary Switches will get new entity ids on first update. I'm not sure I'll be able to avoid this.
  • I did not implement the ! entity id naming functionality in the YAML or in the config_flow
  • No support for combining multiple Momentary Switches into a device.
  • The Slovak language strings are 100% AI generated so likely need to be refined
2025-10-02_20-09-49 864 2025-09-30_22-28-14

This pull request refactors and modernizes the momentary Home Assistant integration, focusing on simplifying configuration management, improving code clarity, and enhancing the options flow. The changes remove legacy YAML config support, unify configuration handling via the UI and YAML import, and update service registration and device management logic.

Configuration Management and Refactoring:

  • Replaced legacy YAML configuration logic with a unified approach that processes YAML via a reload service and handles all configuration through the same flow. Simplified initialization and entry setup in __init__.py and removed legacy device registry logic.
  • Consolidated constants and removed unused helpers from const.py, defining only the necessary configuration keys and defaults.

Options Flow and UI Improvements:

  • Redesigned the config flow in config_flow.py to use a unified schema builder for user input, supporting both UI and YAML import. Added a new options flow handler for config entries, allowing users to update options except for YAML-created switches.
  • Improved validation and normalization of user input, including handling of toggle duration, mode selection, and device association.

Service Registration and Device Management:

  • Added a reload service for the integration to allow YAML configuration to be reprocessed on demand. Updated device removal logic to use Home Assistant helpers, ensuring stale devices are cleaned up when entries are unloaded.

Fixes #54

@Snuffy2 Snuffy2 force-pushed the Add-config_flow-and-yaml-reload branch 11 times, most recently from 1f411c6 to 4f867a4 Compare October 2, 2025 23:51
@Snuffy2 Snuffy2 marked this pull request as ready for review October 3, 2025 00:14
@Snuffy2 Snuffy2 marked this pull request as draft October 4, 2025 14:50
@Snuffy2 Snuffy2 force-pushed the Add-config_flow-and-yaml-reload branch 7 times, most recently from a07219e to 1da52d9 Compare October 8, 2025 02:18
@Snuffy2
Copy link
Copy Markdown
Contributor Author

Snuffy2 commented Oct 8, 2025

I fixed the issues with the duplicate entities by redoing the unique_id generation and standardized to storing the toggle_for as a HA duration dict.

@Snuffy2 Snuffy2 marked this pull request as ready for review October 8, 2025 02:27
@Snuffy2 Snuffy2 force-pushed the Add-config_flow-and-yaml-reload branch from 1da52d9 to 8cb3a13 Compare October 8, 2025 02:30
@Snuffy2 Snuffy2 force-pushed the Add-config_flow-and-yaml-reload branch from 8cb3a13 to 6d827c2 Compare October 8, 2025 02:32
@twrecked
Copy link
Copy Markdown
Owner

I just tried this and the upgrade failed, none of my existing devices got brought in. It shows them all as "no longer provided by the momentary component".

I tried to delete the entries but I can't seem to see a way to add a YAML file back into the component.

This is one of the files that failed to upgrade. It has a bunch of triggers I used to test my system.

version: 1
switches:
- name: +bad weather check trigger
  toggle_for: 1
- name: +change alarm to away
  toggle_for: 1
- name: +change alarm to disarmed
  toggle_for: 1
- name: +change alarm to emergency
  toggle_for: 1
- name: +change alarm to home
  toggle_for: 1
- name: +change automations to running
  toggle_for: 1
- name: +change automations to stopped
  toggle_for: 1
- name: +change cameras to away
  toggle_for: 1
- name: +change cameras to disarmed
  toggle_for: 1
- name: +change cameras to home
  toggle_for: 1
- name: +change phase to daytime
  toggle_for: 1
- name: +change phase to evening
  toggle_for: 1
- name: +change phase to nighttime
  toggle_for: 1
- name: +everybody left check trigger
  toggle_for: 1

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

Successfully merging this pull request may close these issues.

Why are you using a external config file in 0.7?

2 participants