Skip to content

Prana Integration - Refactoring#168639

Draft
LucaTheHacker wants to merge 2 commits intohome-assistant:devfrom
LucaTheHacker:dev
Draft

Prana Integration - Refactoring#168639
LucaTheHacker wants to merge 2 commits intohome-assistant:devfrom
LucaTheHacker:dev

Conversation

@LucaTheHacker
Copy link
Copy Markdown

Breaking change

Given some changes in the internal scheme it may be necessary to delete and re-create all the entities.

Proposed change

Currently the Prana Integration is not really similar to other fan implementations on HA, given this I have modified a bunch of behaviors to make it more usable and natural, along with fixing naming schemes for outside and inside temperature sensors that do not work properly due to Prana API.
I believe these changes make up for a good improvement in User Experience.

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

AI disclaimer, I have used Claude Code with Opus 4.7 to write this PR. Given the very small integration and the ability to directly test everything by hand, I'm quite sure everything is correct and should not break.

Given that the upstream API from prana appears to return improper data, such as "outside_temperature_2" instead of "inside_temperature", I have added some logic to automatically fix naming. Once Prana fixes their API, that code will not be necessary anymore.

Changes:
fan.py — restructured fan exposition

  • bound is now read once at setup as a device capability, not per-call state.
  • Linked models (coord.data.bound == True) → single primary fan entity fan.prana_ (translation_key="ventilation", name=None).
  • Split models → two independent fans supply_fan + extract_fan.
  • Added preset_modes = [auto, auto_plus, night, boost] on the fan(s). Preset setter calls the device-side switch; comment documents that the device auto-clears prior mode.
  • speed_count stays derived from the API's max_speed (no hardcoding).
  • Removed runtime _api_target_key branching (now fixed per description).

switch.py — junk drawer → two real toggles

  • Removed bound, auto, auto_plus (moved to preset modes / device capability).
  • Kept only heater and winter — both anti-ice protections that run alongside any preset.

sensor.py — mislabeled field workaround

  • Exposes only inside_temperature and outside_temperature.

  • Each has a fallback for devices where the primary field is None and the real data lives in the swap-labeled secondary (coord.data.outside_temperature_2 for inside, coord.data.inside_temperature_2
    for outside). Comment flags this as a library workaround with link to upstream.

  • Dropped the _2 entities (they were the same two sensors with swapped labels, not extra data).

  • This PR fixes or closes issue: fixes #

  • This PR is related to issue:

  • Link to documentation pull request:

  • Link to developer documentation pull request:

  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • 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.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

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 diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings April 20, 2026 16:55
Copy link
Copy Markdown

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hello @LucaTheHacker,

When attempting to inspect the commits of your pull request for CLA signature status among all authors we encountered commit(s) which were not linked to a GitHub account, thus not allowing us to determine their status(es).

The commits that are missing a linked GitHub account are the following:

Unfortunately, we are unable to accept this pull request until this situation is corrected.

Here are your options:

  1. If you had an email address set for the commit that simply wasn't linked to your GitHub account you can link that email now and it will retroactively apply to your commits. The simplest way to do this is to click the link to one of the above commits and look for a blue question mark in a blue circle in the top left. Hovering over that bubble will show you what email address you used. Clicking on that button will take you to your email address settings on GitHub. Just add the email address on that page and you're all set. GitHub has more information about this option in their help center.

  2. If you didn't use an email address at all, it was an invalid email, or it's one you can't link to your GitHub, you will need to change the authorship information of the commit and your global Git settings so this doesn't happen again going forward. GitHub provides some great instructions on how to change your authorship information in their help center.

    • If you only made a single commit you should be able to run
      git commit --amend --author="Author Name <email@address.com>"
      
      (substituting "Author Name" and "email@address.com" for your actual information) to set the authorship information.
    • If you made more than one commit and the commit with the missing authorship information is not the most recent one you have two options:
      1. You can re-create all commits missing authorship information. This is going to be the easiest solution for developers that aren't extremely confident in their Git and command line skills.
      2. You can use this script that GitHub provides to rewrite history. Please note: this should be used only if you are very confident in your abilities and understand its impacts.
    • Whichever method you choose, I will come by to re-check the pull request once you push the fixes to this branch.

We apologize for this inconvenience, especially since it usually bites new contributors to Home Assistant. We hope you understand the need for us to protect ourselves and the great community we all have built legally. The best thing to come out of this is that you only need to fix this once and it benefits the entire Home Assistant and GitHub community.

Thanks, I look forward to checking this PR again soon! ❤️

@home-assistant
Copy link
Copy Markdown

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
Copy link
Copy Markdown

Hey there @prana-dev-official, mind taking a look at this pull request as it has been labeled with an integration (prana) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of prana can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign prana Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

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

Refactors the Prana integration’s entity model to better align with Home Assistant fan patterns, including consolidating “linked/bound” devices into a single ventilation fan and moving operating modes to fan preset modes.

Changes:

  • Restructures fan entities: linked models expose one “ventilation” fan; split models expose separate supply/extract fans with preset modes.
  • Simplifies switches to only anti-ice toggles (heater, winter) and removes the prior “mode-like” switches.
  • Adjusts temperature sensors to expose only inside/outside sensors with a fallback workaround for upstream mislabeling.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
homeassistant/components/prana/fan.py Implements linked vs split fan entity selection and adds preset modes.
homeassistant/components/prana/switch.py Removes bound/auto/auto_plus switches, leaving heater/winter toggles.
homeassistant/components/prana/sensor.py Drops *_2 temperature entities and adds swapped-field fallback logic.
homeassistant/components/prana/strings.json Updates entity strings for new fan preset modes and removes old switch/sensor entries.
homeassistant/components/prana/icons.json Adds icons for ventilation preset modes and removes old entity icons.
tests/components/prana/test_fan.py Updates fan tests for linked vs split behavior and API targeting.
tests/components/prana/test_switch.py Updates switch action tests to match remaining toggles.
tests/components/prana/snapshots/test_fan.ambr Deleted snapshot file for fan snapshot tests.
tests/components/prana/snapshots/test_switch.ambr Deleted snapshot file for switch snapshot tests.
tests/components/prana/snapshots/test_sensor.ambr Deleted snapshot file for sensor snapshot tests.

Comment thread homeassistant/components/prana/fan.py
Comment thread homeassistant/components/prana/strings.json
Comment on lines +36 to +40
"""Test the Prana fans snapshot (linked model, default fixture)."""
with patch("homeassistant.components.prana.PLATFORMS", [Platform.FAN]):
await async_init_integration(hass, mock_config_entry)

return target, fan_mock_state
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

Regenerate and commit the Syrupy snapshot for this test; the test still calls snapshot_platform but the corresponding test_fan snapshot file was removed, which will cause CI snapshot failures.

Copilot uses AI. Check for mistakes.
Comment thread tests/components/prana/test_switch.py
Comment on lines +75 to 103
# Devices only have two physical probes (one inside, one outside), but
# the upstream library mislabels the secondary pair: `inside_temperature_2`
# actually contains the outside reading and `outside_temperature_2` the
# inside one. On models where the primary fields are populated we use
# them; otherwise we fall back to the swapped secondary. Remove this
# workaround once upstream fixes the field labeling:
# https://github.com/prana-dev-official/prana-local-api
PranaSensorEntityDescription(
key=PranaSensorType.INSIDE_TEMPERATURE,
translation_key="inside_temperature",
value_fn=lambda coord: coord.data.inside_temperature,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
device_class=SensorDeviceClass.TEMPERATURE,
),
PranaSensorEntityDescription(
key=PranaSensorType.INSIDE_TEMPERATURE_2,
translation_key="inside_temperature_2",
value_fn=lambda coord: coord.data.inside_temperature_2,
value_fn=lambda coord: (
coord.data.inside_temperature
if coord.data.inside_temperature is not None
else coord.data.outside_temperature_2
),
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
device_class=SensorDeviceClass.TEMPERATURE,
),
PranaSensorEntityDescription(
key=PranaSensorType.OUTSIDE_TEMPERATURE,
translation_key="outside_temperature",
value_fn=lambda coord: coord.data.outside_temperature,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
device_class=SensorDeviceClass.TEMPERATURE,
),
PranaSensorEntityDescription(
key=PranaSensorType.OUTSIDE_TEMPERATURE_2,
translation_key="outside_temperature_2",
value_fn=lambda coord: coord.data.outside_temperature_2,
value_fn=lambda coord: (
coord.data.outside_temperature
if coord.data.outside_temperature is not None
else coord.data.inside_temperature_2
),
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
device_class=SensorDeviceClass.TEMPERATURE,
),
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

Update the sensor snapshots (or stop using snapshot_platform) to match the new set of exposed temperature sensors; the existing test suite relies on Syrupy snapshots and removing them will break CI.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hello @LucaTheHacker,

When attempting to inspect the commits of your pull request for CLA signature status among all authors we encountered commit(s) which were not linked to a GitHub account, thus not allowing us to determine their status(es).

The commits that are missing a linked GitHub account are the following:

Unfortunately, we are unable to accept this pull request until this situation is corrected.

Here are your options:

  1. If you had an email address set for the commit that simply wasn't linked to your GitHub account you can link that email now and it will retroactively apply to your commits. The simplest way to do this is to click the link to one of the above commits and look for a blue question mark in a blue circle in the top left. Hovering over that bubble will show you what email address you used. Clicking on that button will take you to your email address settings on GitHub. Just add the email address on that page and you're all set. GitHub has more information about this option in their help center.

  2. If you didn't use an email address at all, it was an invalid email, or it's one you can't link to your GitHub, you will need to change the authorship information of the commit and your global Git settings so this doesn't happen again going forward. GitHub provides some great instructions on how to change your authorship information in their help center.

    • If you only made a single commit you should be able to run
      git commit --amend --author="Author Name <email@address.com>"
      
      (substituting "Author Name" and "email@address.com" for your actual information) to set the authorship information.
    • If you made more than one commit and the commit with the missing authorship information is not the most recent one you have two options:
      1. You can re-create all commits missing authorship information. This is going to be the easiest solution for developers that aren't extremely confident in their Git and command line skills.
      2. You can use this script that GitHub provides to rewrite history. Please note: this should be used only if you are very confident in your abilities and understand its impacts.
    • Whichever method you choose, I will come by to re-check the pull request once you push the fixes to this branch.

We apologize for this inconvenience, especially since it usually bites new contributors to Home Assistant. We hope you understand the need for us to protect ourselves and the great community we all have built legally. The best thing to come out of this is that you only need to fix this once and it benefits the entire Home Assistant and GitHub community.

Thanks, I look forward to checking this PR again soon! ❤️

Copy link
Copy Markdown

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @LucaTheHacker

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

Copilot AI review requested due to automatic review settings April 20, 2026 17:13
Copy link
Copy Markdown

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hello @LucaTheHacker,

When attempting to inspect the commits of your pull request for CLA signature status among all authors we encountered commit(s) which were not linked to a GitHub account, thus not allowing us to determine their status(es).

The commits that are missing a linked GitHub account are the following:

Unfortunately, we are unable to accept this pull request until this situation is corrected.

Here are your options:

  1. If you had an email address set for the commit that simply wasn't linked to your GitHub account you can link that email now and it will retroactively apply to your commits. The simplest way to do this is to click the link to one of the above commits and look for a blue question mark in a blue circle in the top left. Hovering over that bubble will show you what email address you used. Clicking on that button will take you to your email address settings on GitHub. Just add the email address on that page and you're all set. GitHub has more information about this option in their help center.

  2. If you didn't use an email address at all, it was an invalid email, or it's one you can't link to your GitHub, you will need to change the authorship information of the commit and your global Git settings so this doesn't happen again going forward. GitHub provides some great instructions on how to change your authorship information in their help center.

    • If you only made a single commit you should be able to run
      git commit --amend --author="Author Name <email@address.com>"
      
      (substituting "Author Name" and "email@address.com" for your actual information) to set the authorship information.
    • If you made more than one commit and the commit with the missing authorship information is not the most recent one you have two options:
      1. You can re-create all commits missing authorship information. This is going to be the easiest solution for developers that aren't extremely confident in their Git and command line skills.
      2. You can use this script that GitHub provides to rewrite history. Please note: this should be used only if you are very confident in your abilities and understand its impacts.
    • Whichever method you choose, I will come by to re-check the pull request once you push the fixes to this branch.

We apologize for this inconvenience, especially since it usually bites new contributors to Home Assistant. We hope you understand the need for us to protect ourselves and the great community we all have built legally. The best thing to come out of this is that you only need to fix this once and it benefits the entire Home Assistant and GitHub community.

Thanks, I look forward to checking this PR again soon! ❤️

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

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

homeassistant/components/prana/sensor.py:104

  • Add/update the Prana sensor snapshot file to reflect the removal of the *_temperature_2 entities (the snapshot test still exists in tests/components/prana/test_sensor.py, but tests/components/prana/snapshots/test_sensor.ambr was removed).
    # Devices only have two physical probes (one inside, one outside), but
    # the upstream library mislabels the secondary pair: `inside_temperature_2`
    # actually contains the outside reading and `outside_temperature_2` the
    # inside one. On models where the primary fields are populated we use
    # them; otherwise we fall back to the swapped secondary. Remove this
    # workaround once upstream fixes the field labeling:
    # https://github.com/prana-dev-official/prana-local-api
    PranaSensorEntityDescription(
        key=PranaSensorType.INSIDE_TEMPERATURE,
        translation_key="inside_temperature",
        value_fn=lambda coord: (
            coord.data.inside_temperature
            if coord.data.inside_temperature is not None
            else coord.data.outside_temperature_2
        ),
        native_unit_of_measurement=UnitOfTemperature.CELSIUS,
        device_class=SensorDeviceClass.TEMPERATURE,
    ),
    PranaSensorEntityDescription(
        key=PranaSensorType.OUTSIDE_TEMPERATURE,
        translation_key="outside_temperature",
        value_fn=lambda coord: (
            coord.data.outside_temperature
            if coord.data.outside_temperature is not None
            else coord.data.inside_temperature_2
        ),
        native_unit_of_measurement=UnitOfTemperature.CELSIUS,
        device_class=SensorDeviceClass.TEMPERATURE,
    ),
)

Comment on lines 29 to 34
"""Test the Prana switches snapshot."""
with patch("homeassistant.components.prana.PLATFORMS", [Platform.SWITCH]):
await async_init_integration(hass, mock_config_entry)

await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)

Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

Add updated snapshot files for the switch platform tests (the snapshot-based test_switches is still present but tests/components/prana/snapshots/test_switch.ambr was removed).

Copilot uses AI. Check for mistakes.
Comment on lines +43 to 47
"""Switch on/off calls set_switch with the corresponding key."""
await async_init_integration(hass, mock_config_entry)

entries = er.async_entries_for_config_entry(
entity_registry, mock_config_entry.entry_id
)
assert entries
target = f"switch.prana_recuperator{entity_suffix}"
target = f"switch.prana_recuperator_{switch_key}"

Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

Resolve the switch entity_id via the entity registry (or update the expected entity_id), since the translated name was changed to "Winter mode" which will likely generate switch.prana_recuperator_winter_mode rather than switch.prana_recuperator_winter in a fresh registry.

Copilot uses AI. Check for mistakes.
Comment on lines +29 to 41
async def test_fans(
hass: HomeAssistant,
mock_prana_api: AsyncMock,
mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
type_key: str,
is_bound_mode: bool,
) -> tuple[str, Any]:
"""Set up a Prana fan entity for service tests."""
mock_prana_api.get_state.return_value.bound = is_bound_mode
fan_mock_state = getattr(
mock_prana_api.get_state.return_value,
"bounded" if is_bound_mode else type_key,
)

await async_init_integration(hass, mock_config_entry)

unique_id = f"{mock_config_entry.unique_id}_{type_key}"
target = entity_registry.async_get_entity_id(FAN_DOMAIN, "prana", unique_id)

assert target, f"Entity with unique_id {unique_id} not found"
mock_prana_api: MagicMock,
snapshot: SnapshotAssertion,
) -> None:
"""Test the Prana fans snapshot (linked model, default fixture)."""
with patch("homeassistant.components.prana.PLATFORMS", [Platform.FAN]):
await async_init_integration(hass, mock_config_entry)

return target, fan_mock_state
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)

Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

Add updated snapshot files for the fan platform tests (the snapshot-based test_fans is still present but tests/components/prana/snapshots/test_fan.ambr was removed).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants