8000 Add missing type hints to websocket_api by KapJI · Pull Request #50915 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add missing type hints to websock 8000 et_api #50915

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

Merged
merged 3 commits into from
May 21, 2021

Conversation

KapJI
Copy link
Member
@KapJI KapJI commented May 21, 2021

Proposed change

websocket_api is added to .strict-typing and many integrations depend on it but it was missing type annotation for significant part of its methods.

Remove all # mypy: comments.

There're few non typing changes:

  • ActiveConnection.user can't be None
  • ActiveConnection.refresh_token_id can't be None

To confirm this I checked not just typing but also how ActiveConnection and RefreshToken are created.

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:

8000
@probot-home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this pull request as its been labeled with an integration (websocket_api) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@KapJI KapJI force-pushed the strict-websockets branch from dae153b to c5c4cf7 Compare May 21, 2021 00:21
@KapJI KapJI mentioned this pull request May 21, 2021
21 tasks
"""Initialize the websocket API."""
hass.http.register_view(http.WebsocketAPIView)
hass.http.register_view(http.WebsocketAPIView())
Copy link
Member Author

Choose a reason for hiding this comment

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

It'll be instantiated in register_view anyway. I think it's better to do this here to have cleaner register_view interface.

else:
self.refresh_token_id = None

self.refresh_token_id = refresh_token.id
Copy link
Member Author
@KapJI KapJI May 21, 2021

Choose a reason for hiding this comment

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

ActiveConnection is created only in websocket_api/api.py where it's explicitly checked that refresh_token is not None.

"""Output error message."""
connection.send_message(
messages.error_message(msg["id"], message_id, message)
)

if connection.user is None:
Copy link
Member Author

Choose a reason for hiding this comment

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

connection.user is set from RefreshToken.user. I checked both places where RefreshToken is created in homeassistant/auth/auth_store.py and they both look to me as not None.

And RefreshToken.user is typed accordingly as not optional.

Copy link
Member

Choose a reason for hiding this comment

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

@balloob can you verify this?

Copy link
Member

Choose a reason for hiding this comment

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

Correct. All refresh tokens are bound to a user (which can be "system generated").

Copy link
Member

Choose a reason for hiding this comment

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

Just rememebred. This is a relic of the past. We used to have api_password logins which were not bound to a user.

Copy link
Member
@MartinHjelmare MartinHjelmare 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!

@balloob balloob merged commit 42ff687 into home-assistant:dev May 21, 2021
@KapJI KapJI deleted the strict-websockets branch May 21, 2021 17:57
@github-actions github-actions bot locked and limited conversation to collaborators May 22, 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.

4 participants
0