Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integration failed when freebox is configured in bridge mode #103221

Merged
merged 61 commits into from Nov 18, 2023

Conversation

jflefebvre06
Copy link
Contributor

@jflefebvre06 jflefebvre06 commented Nov 2, 2023

Breaking change

Proposed change

Allows freebox integration to work for users who have configured their router in bridge mode.

The problem is due to the fact that in bridge mode, access to the Host list is not implemented.

freebox_api.exceptions.HttpRequestError: Request failed (APIResponse: {"msg": "Erreur lors de la r\u00e9cup\u00e9ration de la liste des h\u00f4tes : Interface invalide", "success": false, "error_code": "nodev"})

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 Black (black --fast 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.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

Copy link

@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 @jflefebvre06

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

home-assistant bot commented Nov 2, 2023

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 home-assistant bot marked this pull request as draft November 2, 2023 08:27
@home-assistant
Copy link

home-assistant bot commented Nov 2, 2023

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.

Copy link
Member

@Quentame Quentame left a comment

Choose a reason for hiding this comment

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

Not linked to VMs access but hosts access.

Please update your comments and description accordingly.

homeassistant/components/freebox/router.py Outdated Show resolved Hide resolved
homeassistant/components/freebox/router.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft November 2, 2023 09:05
jflefebvre06 and others added 2 commits November 2, 2023 11:05
OK thanks

Co-authored-by: Quentame <polletquentin74@me.com>
OK thanks

Co-authored-by: Quentame <polletquentin74@me.com>
@jflefebvre06
Copy link
Contributor Author

Comments updates

@jflefebvre06 jflefebvre06 marked this pull request as ready for review November 2, 2023 10:09
Copy link
Member

@Quentame Quentame left a comment

Choose a reason for hiding this comment

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

You have to apply the same "try once and don't retry next" mechanism as supports_raid and home_granted do.

Otherwise, HA will try to update hosts everytime and will always get an error.
We better want to test if it succeed the first time to continue fetching next times.

Copy link
Member

@Quentame Quentame left a comment

Choose a reason for hiding this comment

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

Just need to adjust the test, otherwise I'm good !

@@ -115,3 +115,21 @@ async def test_battery(
assert hass.states.get("sensor.telecommande_niveau_de_batterie").state == "25"
assert hass.states.get("sensor.ouverture_porte_niveau_de_batterie").state == "50"
assert hass.states.get("sensor.detecteur_niveau_de_batterie").state == "75"


async def test_get_hosts_list(
Copy link
Member

Choose a reason for hiding this comment

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

Not resolved.

Move this test to test_device_tracker.py

And you have to count number of devices linked to the router (--> router.devices):

  • 1 if in bridge mode : the router itself
  • more than 1 if not

@home-assistant home-assistant bot marked this pull request as draft November 18, 2023 10:08
@jflefebvre06
Copy link
Contributor Author

jflefebvre06 commented Nov 18, 2023

@Quentame if I add assert router_bridge_mode.call_count == 1 test failed " AssertionError: assert 2 == 1"
I think it is bebause acced durirng mock_router_get_hosts_list_error_not_json

    router().lan.get_hosts_list = AsyncMock(
        side_effect=HttpRequestError(
            "Request failed (APIResponse: %s)"
            % json.dumps(DATA_LAN_GET_HOSTS_LIST_MODE_BRIDGE)
        )
    )

@Quentame
Copy link
Member

@jflefebvre06 you did not understand my comment

Do not count the call to the router instance but to the amount of devices generated by the function call

The function call should normally be 1 at any test.

My Discord ID : quentame
We could talk if French there 😉

@jflefebvre06
Copy link
Contributor Author

Is there an example how to get the router ?

Copy link
Member

@Quentame Quentame left a comment

Choose a reason for hiding this comment

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

Test suggestions

tests/components/freebox/test_utils.py Outdated Show resolved Hide resolved
tests/components/freebox/test_device_tracker.py Outdated Show resolved Hide resolved
Copy link
Member

@Quentame Quentame left a comment

Choose a reason for hiding this comment

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

Should use device tracker platform for tests

tests/components/freebox/test_device_tracker.py Outdated Show resolved Hide resolved
tests/components/freebox/test_device_tracker.py Outdated Show resolved Hide resolved
tests/components/freebox/test_device_tracker.py Outdated Show resolved Hide resolved
@jflefebvre06 jflefebvre06 marked this pull request as ready for review November 18, 2023 22:12
Copy link
Member

@Quentame Quentame left a comment

Choose a reason for hiding this comment

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

Nice, thanks 🥳

@Quentame Quentame dismissed edenhaus’s stale review November 18, 2023 22:59

Comments addressed

@Quentame Quentame merged commit 9c86adf into home-assistant:dev Nov 18, 2023
22 of 23 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 20, 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.

Freebox : ClientConnectorError while setup when router is in bridge mode
3 participants