Skip to content

Add alarm control panel platform to NASweb integration#141582

Merged
emontnemery merged 3 commits into
home-assistant:devfrom
nasWebio:nasweb_zone
Nov 3, 2025
Merged

Add alarm control panel platform to NASweb integration#141582
emontnemery merged 3 commits into
home-assistant:devfrom
nasWebio:nasweb_zone

Conversation

@nasWebio
Copy link
Copy Markdown
Contributor

@nasWebio nasWebio commented Mar 27, 2025

Proposed change

Adds Alarm Control Panel platform to NASweb integration

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions Bot added the stale label May 26, 2025
@nasWebio
Copy link
Copy Markdown
Contributor Author

Waiting for the review

@github-actions github-actions Bot removed the stale label May 28, 2025
@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions Bot added the stale label Jul 27, 2025
@nasWebio
Copy link
Copy Markdown
Contributor Author

Waiting for the review

@github-actions github-actions Bot removed the stale label Jul 29, 2025
@emontnemery
Copy link
Copy Markdown
Contributor

@nasWebio please fix the merge conflicts

Copy link
Copy Markdown
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

Looks good, just needs a rebase and addressing the review comments.

current_zones: set[int] = set()

@callback
def _check_entities() -> None:
Copy link
Copy Markdown
Contributor

@emontnemery emontnemery Sep 2, 2025

Choose a reason for hiding this comment

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

This code is basically the same as for sensor and switch.
I think it would be a good idea to refactor to a shared helper function in homeassistant/components/nasweb/helpers.py or similar. The helper should take as input the entity class, and maybe some hints for the logging if that's really important.

That can happen in a separate PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm planning to get to it after adding platforms to change them all at once. Is it alright to make single PR for things like moving _chek_entities() to helpers.py and implementing some sort of NaswebEntity or it should be separated?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A combined PR which does several refactorings is fine, it just should not be part of a PR which adds new features or fixes bugs.

Comment thread homeassistant/components/nasweb/alarm_control_panel.py
Comment thread homeassistant/components/nasweb/alarm_control_panel.py Outdated
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._attr_alarm_state = AlarmControlPanelState(self._zone.state)
Copy link
Copy Markdown
Contributor

@emontnemery emontnemery Sep 2, 2025

Choose a reason for hiding this comment

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

Please add a map to map between the states used by the library and the Home Assistant states, e.g.:

NASWEB_STATE_TO_HA_STATE = {
    "disarmed" : AlarmControlPanelState.DISARMED,
}

...

self._attr_alarm_state = NASWEB_STATE_TO_HA_STATE[self._zone.state]  # We may want to add error handling, for example by catching `KeyError` and logging a warning + setting the state to `None` (which will be translated to unknown).

Note: Ideally, the library should export the possible states as constants.

Copy link
Copy Markdown
Contributor

@emontnemery emontnemery Sep 2, 2025

Choose a reason for hiding this comment

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

In case your library is used only for Home Assistant, I'd suggest to remove the function _convert_zone_status from the library, that should be a map in Home Assistant instead. Same for _convert_outputs_status.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should I add map with values as currently provided by library for this PR and make separate PR to bump library with changes to platforms (library is used only for Home Assistant)? Or correct approach would be to update library and make changes to implemented platforms within this PR?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The correct approach is:

  • A PR which updates the library and makes mandatory changes to the nasweb integrations
  • Update this PR once the PR updating the library is merged

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

#153208 is merged, so this should be unblocked.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this PR should be updated though. @nasWebio can you confirm?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will rebase and add state map.

Copy link
Copy Markdown
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @nasWebio 👍

@emontnemery emontnemery merged commit e8277cb into home-assistant:dev Nov 3, 2025
35 of 36 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants