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

Add Fritz services #50056

Merged
merged 5 commits into from
May 11, 2021
Merged

Conversation

chemelli74
Copy link
Contributor

Proposed change

Add reconnect and reboot services for Fritz devices.

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

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

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

Hey there @mammuth, @AaronDavidSchneider, mind taking a look at this pull request as its been labeled with an integration (fritz) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

Copy link
Contributor

@AaronDavidSchneider AaronDavidSchneider left a comment

Choose a reason for hiding this comment

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

Works well! I think I would change the way how entities and devices are linked to fritzbox_tools.

Also: We need to handle those devices that have no way of reconnecting.

This is what I get if I reconnect a router that is connected as a repeater:

2021-05-04 09:19:34 ERROR (MainThread) [homeassistant] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/schneider/codes/personal/hass/venv/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 233, in reconnect
    self.call_action("WANIPConn1", "ForceTermination")
  File "/Users/schneider/codes/personal/hass/venv/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 227, in call_action
    return self.soaper.execute(service, action_name, arguments)
  File "/Users/schneider/codes/personal/hass/venv/lib/python3.9/site-packages/fritzconnection/core/soaper.py", line 238, in execute
    return handle_response(response)
  File "/Users/schneider/codes/personal/hass/venv/lib/python3.9/site-packages/fritzconnection/core/soaper.py", line 222, in handle_response
    raise_fritzconnection_error(response)
  File "/Users/schneider/codes/personal/hass/venv/lib/python3.9/site-packages/fritzconnection/core/soaper.py", line 147, in raise_fritzconnection_error
    raise exception(message)
fritzconnection.core.exceptions.FritzConnectionException: UPnPError:
errorCode: 403
errorDescription: Not available Action

homeassistant/components/fritz/services.py Outdated Show resolved Hide resolved
@chemelli74
Copy link
Contributor Author

fritzconnection.core.exceptions.FritzConnectionException: UPnPError:
errorCode: 403
errorDescription: Not available Action

I would expect a different error in such cases:
https://fritzconnection.readthedocs.io/en/1.0.1/sources/api.html#fritzconnection.core.exceptions.FritzActionError
or
https://fritzconnection.readthedocs.io/en/1.0.1/sources/api.html#fritzconnection.core.exceptions.FritzServiceError

@chemelli74
Copy link
Contributor Author

fritzconnection.core.exceptions.FritzConnectionException: UPnPError:
errorCode: 403
errorDescription: Not available Action

I would expect a different error in such cases:
https://fritzconnection.readthedocs.io/en/1.0.1/sources/api.html#fritzconnection.core.exceptions.FritzActionError
or
https://fritzconnection.readthedocs.io/en/1.0.1/sources/api.html#fritzconnection.core.exceptions.FritzServiceError

Updated documentation: https://fritzconnection.readthedocs.io/en/1.2.1/sources/introduction.html#module-usage

@chemelli74
Copy link
Contributor Author

File "/Users/schneider/codes/personal/hass/venv/lib/python3.9/site-packages/fritzconnection/core/soaper.py", line 147, in raise_fritzconnection_error
raise exception(message)
fritzconnection.core.exceptions.FritzConnectionException: UPnPError:
errorCode: 403
errorDescription: Not available Action

Should be fixed now, please retest.

Simone

target:
entity:
integration: fritz
domain: binary_sensor
Copy link
Member

@bdraco bdraco May 5, 2021

Choose a reason for hiding this comment

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

If the goal is to target the binary sensor entities, register these as entity services

https://developers.home-assistant.io/docs/dev_101_services/#entity-services

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea was to target only a device, but didn't find a way to filter out all entities from GUI.
So I choice to filter by binary sensor and allow both to work ( device and entity).

Copy link
Contributor

@AaronDavidSchneider AaronDavidSchneider left a comment

Choose a reason for hiding this comment

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

works as expected

f"Failed to call service '{service_call.service}'. Config entry for target not found"
)

for entry in fritzbox_entry_ids:
Copy link
Member

Choose a reason for hiding this comment

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

Should we use asyncio.gather here?

Copy link
Member

Choose a reason for hiding this comment

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

Actually no since it's generating executor jobs.

Copy link
Member

Choose a reason for hiding this comment

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

We would save some context switches if we would wrap the iteration inside a function and make the service helper sync.

@bdraco bdraco merged commit d877c0c into home-assistant:dev May 11, 2021
@chemelli74 chemelli74 deleted the chemelli74-fritz-services branch May 11, 2021 21:01
@mib1185
Copy link
Contributor

mib1185 commented May 11, 2021

Since this merge mypy check fail -> https://github.com/home-assistant/core/runs/2559970649

Error: homeassistant/components/fritz/services.py:49: error: Item "None" of "Optional[ConfigEntry]" has no attribute "domain"  [union-attr]

@mib1185 mib1185 mentioned this pull request May 11, 2021
21 tasks
@KapJI
Copy link
Member

KapJI commented May 11, 2021

That's probably because of conflict between this and #50327

@chemelli74 @bdraco can you please fix it?

I wish github had merge-time checks against current master 😕

chemelli74 added a commit to chemelli74/core that referenced this pull request May 11, 2021
@frenck
Copy link
Member

frenck commented May 11, 2021

This PR adds services, but is missing a documentation PR to document these. This PR should not have been merged without those.

@chemelli74 Please open up a documentation PR. Thanks 👍

bdraco pushed a commit that referenced this pull request May 11, 2021
@bdraco
Copy link
Member

bdraco commented May 11, 2021

mypy fix: #50497

dhcp conflict fix (not related but other reason the CI is failing) #50498


async def async_setup_services(hass: HomeAssistant):
"""Set up services for Fritz integration."""
if hass.data.get(FRITZ_SERVICES, False):
Copy link
Member

Choose a reason for hiding this comment

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

We have hass.services.has_service that could be used instead.


for entry in fritzbox_entry_ids:
_LOGGER.debug("Executing service %s", service_call.service)
fritz_tools = hass.data[DOMAIN].get(entry)
Copy link
Member

Choose a reason for hiding this comment

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

We don't check for None below. If that's not needed we should use dict[key] instead of dict.get(key).

chemelli74 added a commit to chemelli74/core that referenced this pull request May 12, 2021
@github-actions github-actions bot locked and limited conversation to collaborators May 13, 2021
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.

8 participants