Skip to content

fix: validate mapping options and add Partial Night state#336

Merged
guerrerotook merged 6 commits into
guerrerotook:mainfrom
clintongormley:fix/validate-mapping-options
Feb 26, 2026
Merged

fix: validate mapping options and add Partial Night state#336
guerrerotook merged 6 commits into
guerrerotook:mainfrom
clintongormley:fix/validate-mapping-options

Conversation

@clintongormley
Copy link
Copy Markdown
Collaborator

@clintongormley clintongormley commented Feb 26, 2026

This PR commits a few fixes relating to #329 that CoPilot identified (but in the wrong PR #332).

It also adds back the Partial Night and Partial Night Perimeter statuses as these are supported at least by verisure France, as discussed in #335 (comment)

We are missing the status code for partial-night-plus-perimeter so, if somebody sets that, we will have to show the Custom status, as we did before #329 was merged. I've added a note to the README asking anybody in this situation to open an issue so that we can fix this problem.

Summary

  • Validate that saved mapping defaults are valid for the current perimeter setting when switching between STD/PERI options in config flow
  • Persist migrated mapping values to entry.data so they survive restarts
  • Use .value strings in defaults dicts for selector compatibility
  • Rename Partial → Partial Day, add Partial Night (Q / ARMNIGHT1) and Partial Night + Perimeter (ARMNIGHT1PERI1) states
  • Add strings.json and sync Spanish translations

Relates to #329

Test plan

  • Verify config flow shows correct dropdown options for STD vs PERI
  • Toggle perimeter checkbox and confirm mapping defaults reset correctly
  • Restart HA and verify migrated mappings persist
  • Test Partial Night arming sends ARMNIGHT1 command
  • Verify unknown protomResponse codes fall back to ARMED_CUSTOM_BYPASS

🤖 Generated with Claude Code

clintongormley and others added 6 commits February 26, 2026 08:59
When peri_alarm changes between step 1 and step 2 of the options flow,
saved mapping values (e.g. PERI_ONLY) may not be in the new options list
(STD_OPTIONS). Reset to the appropriate default when this happens.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The migration logic derived mapping defaults from the PERI_alarm checkbox
but only set them in the runtime config dict. Without calling
async_update_entry, the migrated values were lost on restart, causing
the migration to re-run every time.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The config_flow selector expects string values, but STD_DEFAULTS and
PERI_DEFAULTS contained SecuritasState enum objects. This caused
mismatches when comparing defaults against valid_values (which are
strings from state.value). Use .value to store strings directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Create strings.json as the source of truth for translations, synced
with en.json. Add missing mappings section to es.json with Spanish
translations for the alarm state mapping options step.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Partial Night (ARMNIGHT1 / protomResponse Q) exists in some countries.
Rename PARTIAL → PARTIAL_DAY, PARTIAL_PERI → PARTIAL_DAY_PERI, and add
PARTIAL_NIGHT and PARTIAL_NIGHT_PERI with their commands and mappings.

- Update STD_OPTIONS/PERI_OPTIONS to include the new states
- Default Night button to Partial Night (STD) / Partial Night + Peri (PERI)
- Use .value strings in defaults for selector compatibility
- Create strings.json, sync es.json with mappings and new fields
- Update plan doc to correct Q/ARMNIGHT1 documentation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Explains how Securitas modes map to HA alarm buttons, default mappings
for standard and perimeter installations, and the disarm-before-rearm
behavior. Notes that Partial Night + Perimeter status code is unknown.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@clintongormley clintongormley marked this pull request as ready for review February 26, 2026 12:53
@clintongormley
Copy link
Copy Markdown
Collaborator Author

@poupounetjoyeux This PR adds back the partial night statuses you asked for

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the alarm state mapping feature introduced in PR #329 by adding validation for mapping options when switching perimeter modes, persisting migrated mappings, and introducing Partial Night alarm states. The changes improve the robustness of the configuration flow and expand support for alarm states that exist in some Securitas/Verisure regions (particularly France).

Changes:

  • Added validation to reset alarm state mappings to defaults when switching between STD/PERI perimeter modes if saved mappings are invalid for the new mode
  • Modified migration logic to persist converted mapping values to entry.data to survive HA restarts
  • Renamed PARTIAL → PARTIAL_DAY and PARTIAL_PERI → PARTIAL_DAY_PERI for clarity
  • Added PARTIAL_NIGHT (Q / ARMNIGHT1) and PARTIAL_NIGHT_PERI (command ARMNIGHT1PERI1, status code unknown) states
  • Added strings.json as English fallback translation file and synchronized Spanish translations
  • Fixed typo "alamr" → "alarm" in README
  • Documented the known limitation that PARTIAL_NIGHT_PERI status code is unknown and will show as Custom Bypass

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
docs/plans/2026-02-12-configurable-alarm-mapping-design.md Updated design documentation to reflect 8 alarm states (added Partial Night variants), updated table with protomResponse codes and API commands, clarified that Partial Night exists in some countries
custom_components/securitas/translations/es.json Added Spanish translations for the mappings step in options flow
custom_components/securitas/strings.json Added new file with English translations as fallback (matches en.json structure)
custom_components/securitas/securitas_direct_new_api/const.py Renamed PARTIAL to PARTIAL_DAY and PARTIAL_PERI to PARTIAL_DAY_PERI; added PARTIAL_NIGHT and PARTIAL_NIGHT_PERI states; added Q protomResponse mapping; changed defaults dicts to use .value strings instead of enum instances
custom_components/securitas/config_flow.py Added _valid_map helper function that validates saved mappings against current perimeter setting and resets to defaults if invalid
custom_components/securitas/__init__.py Added persistence logic to save migrated mapping values to entry.data via async_update_entry
README.md Added comprehensive Alarm State Mapping section documenting all modes, how mapping works, default mappings, and known limitations; fixed typo "alamr" → "alarm"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread custom_components/securitas/__init__.py
@guerrerotook guerrerotook merged commit 385a98e into guerrerotook:main Feb 26, 2026
7 checks passed
@clintongormley
Copy link
Copy Markdown
Collaborator Author

Thanks @guerrerotook

@clintongormley clintongormley deleted the fix/validate-mapping-options branch February 26, 2026 18:13
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.

3 participants