Skip to content

Add raid array degraded state binary sensor to freebox sensors#95242

Merged
jbouwh merged 1 commit into
home-assistant:devfrom
fthiery:freebox-raid-degraded-sensor
Jul 5, 2023
Merged

Add raid array degraded state binary sensor to freebox sensors#95242
jbouwh merged 1 commit into
home-assistant:devfrom
fthiery:freebox-raid-degraded-sensor

Conversation

@fthiery
Copy link
Copy Markdown
Contributor

@fthiery fthiery commented Jun 26, 2023

Proposed change

I use the Freebox router for hosting my HA setup, with a RAID setup (the router has 4 SATA bays with sw RAID functionality and provides virtualization support). Unfortunately their product has no notification feature to report that the array is degraded (i discovered mine was degraded after a power loss event by chance), so i want to add this property to the current Freebox component, e.g. mostly to add a notification.

This PR basically creates one binary_sensor.freebox_server_r2_raid_array_0_degraded-like boolan sensor entity per RAID array in diagnostics entities.

Capture d’écran du 2023-06-30 12-26-20

  • This is my first attempt at contributing (so, probably not stellar ;), sorry about that.
  • For consistency reasons, i overwrote the original author disk mock data

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][dev-checklist]
  • I have followed the [perfect PR recommendations][perfect-pr]
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

@home-assistant
Copy link
Copy Markdown
Contributor

Hi @fthiery

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!

@home-assistant
Copy link
Copy Markdown
Contributor

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

Code owner commands

Code owners of freebox can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign freebox Removes the current integration label and assignees on the pull request, add the integration domain after the command.

@fthiery fthiery force-pushed the freebox-raid-degraded-sensor branch 2 times, most recently from ff6672d to 251f8b6 Compare June 26, 2023 10:36
Copy link
Copy Markdown
Contributor

@jbouwh jbouwh left a comment

Choose a reason for hiding this comment

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

Please add some tests specific for your feature. Not just change testdata.

Comment thread tests/components/freebox/const.py
@home-assistant home-assistant Bot marked this pull request as draft June 26, 2023 14:56
@home-assistant
Copy link
Copy Markdown
Contributor

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.

@fthiery fthiery force-pushed the freebox-raid-degraded-sensor branch from afc95b5 to 826c099 Compare June 28, 2023 21:15
@fthiery
Copy link
Copy Markdown
Contributor Author

fthiery commented Jun 28, 2023

Please add some tests specific for your feature. Not just change testdata.

I added a test, please take a look

@fthiery fthiery marked this pull request as ready for review June 28, 2023 21:20
@home-assistant home-assistant Bot requested a review from jbouwh June 28, 2023 21:21
@fthiery fthiery force-pushed the freebox-raid-degraded-sensor branch from 96e4da9 to 90f7d8c Compare June 28, 2023 21:24
@fthiery fthiery changed the title Add raid array degraded state binary sensor Add raid array degraded state binary sensor to Freebox sensors Jun 28, 2023
@fthiery fthiery force-pushed the freebox-raid-degraded-sensor branch from 90f7d8c to 28abc6e Compare June 30, 2023 07:09
Comment thread homeassistant/components/freebox/sensor.py Outdated
Comment thread homeassistant/components/freebox/sensor.py Outdated
@home-assistant home-assistant Bot marked this pull request as draft June 30, 2023 07:37
@fthiery fthiery force-pushed the freebox-raid-degraded-sensor branch from 9ac45d9 to a5ad0f0 Compare June 30, 2023 10:29
@fthiery fthiery marked this pull request as ready for review June 30, 2023 10:29
@fthiery
Copy link
Copy Markdown
Contributor Author

fthiery commented Jul 4, 2023

For the record, after applying the requested changes, i deployed this as custom_component and i'm having no issues

@fthiery fthiery force-pushed the freebox-raid-degraded-sensor branch from 466cf80 to b6183cb Compare July 4, 2023 15:57
@jbouwh
Copy link
Copy Markdown
Contributor

jbouwh commented Jul 4, 2023

Sorry accidentally rebased your branch. Can you try to add a test for the code that is not covered yet?
Also have a look at the _attr_name. May be this can set to None so we get translations. We should set _attr_has_entity_name to True.

@fthiery fthiery force-pushed the freebox-raid-degraded-sensor branch from 2ffb144 to b6183cb Compare July 5, 2023 07:43
@fthiery
Copy link
Copy Markdown
Contributor Author

fthiery commented Jul 5, 2023

Sorry accidentally rebased your branch.

NP, i repushed

Can you try to add a test for the code that is not covered yet?

What are you referring to, all other sensors that were previously here and had zero tests ? Please be more specific.

Also have a look at the _attr_name. May be this can set to None so we get translations.

Well, i think we should not do that, because a Freebox can have multiple raid arrays, so the name should really include the raid array number.

Similar to the disk sensor: https://github.com/home-assistant/core/blob/dev/homeassistant/components/freebox/sensor.py#L191

What do you think ?

We should set _attr_has_entity_name to True.

Added

@fthiery fthiery force-pushed the freebox-raid-degraded-sensor branch from b6183cb to 4e17753 Compare July 5, 2023 09:07
@jbouwh
Copy link
Copy Markdown
Contributor

jbouwh commented Jul 5, 2023

What are you referring to, all other sensors that were previously here and had zero tests ? Please be more specific.

See CI tests. Since the new code has tests now, we need to test all cases.

Comment thread tests/components/freebox/test_sensors.py Outdated
@home-assistant home-assistant Bot marked this pull request as draft July 5, 2023 09:11
Comment thread tests/components/freebox/test_sensors.py Outdated
Comment thread homeassistant/components/freebox/binary_sensor.py Outdated
@fthiery
Copy link
Copy Markdown
Contributor Author

fthiery commented Jul 5, 2023

What are you referring to, all other sensors that were previously here and had zero tests ? Please be more specific.

See CI tests. Since the new code has tests now, we need to test all cases.

Are you asking me to test more cases on the specific feature i added (e.g. mocking a situation where the raid array gets degraded) or to test the previously existing sensors ?

@fthiery fthiery force-pushed the freebox-raid-degraded-sensor branch from 4e17753 to e520386 Compare July 5, 2023 09:42
@jbouwh
Copy link
Copy Markdown
Contributor

jbouwh commented Jul 5, 2023

What are you referring to, all other sensors that were previously here and had zero tests ? Please be more specific.

See CI tests. Since the new code has tests now, we need to test all cases.

Are you asking me to test more cases on the specific feature i added (e.g. mocking a situation where the raid array gets degraded) or to test the previously existing sensors ?

Not in this PR, but it would be nice if you did so. BTW the existing modules were listed in .coveragerc, hence they are allowed not to have tests.

These files are in .coveragerc:

    homeassistant/components/freebox/camera.py
    homeassistant/components/freebox/device_tracker.py
    homeassistant/components/freebox/home_base.py
    homeassistant/components/freebox/router.py
    homeassistant/components/freebox/sensor.py
    homeassistant/components/freebox/switch.py

Comment thread homeassistant/components/freebox/binary_sensor.py
Copy link
Copy Markdown
Contributor

@jbouwh jbouwh left a comment

Choose a reason for hiding this comment

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

Added some suggestions to let the CI tests pass and to test the sensor in a better way

Comment thread tests/components/freebox/test_binary_sensor.py Outdated
Comment thread tests/components/freebox/test_binary_sensor.py Outdated
Comment thread tests/components/freebox/test_binary_sensor.py
Comment thread tests/components/freebox/test_binary_sensor.py
@fthiery fthiery force-pushed the freebox-raid-degraded-sensor branch from 16295b2 to 25b9f5e Compare July 5, 2023 12:25
@fthiery fthiery marked this pull request as ready for review July 5, 2023 12:25
@home-assistant home-assistant Bot requested a review from jbouwh July 5, 2023 12:25
@fthiery fthiery force-pushed the freebox-raid-degraded-sensor branch from 25b9f5e to e66e43f Compare July 5, 2023 12:40
@jbouwh
Copy link
Copy Markdown
Contributor

jbouwh commented Jul 5, 2023

It seems you still have to update the docs: https://www.home-assistant.io/integrations/freebox/

Can you open a docs PR, keep in mind you target the PR to the next branch.

Copy link
Copy Markdown
Contributor

@jbouwh jbouwh left a comment

Choose a reason for hiding this comment

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

Needs a docs update, PR looks good,
Thnx @fthiery 👍

@fthiery
Copy link
Copy Markdown
Contributor Author

fthiery commented Jul 5, 2023

Needs a docs update, PR looks good, Thnx @fthiery +1

home-assistant/home-assistant.io#28080

@jbouwh jbouwh merged commit bd7057f into home-assistant:dev Jul 5, 2023
Comment thread tests/components/freebox/test_binary_sensor.py
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 6, 2023
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.

4 participants