-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
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
Conversation
Hey there @home-assistant/core, mind taking a look at this pull request as its been labeled with an integration ( |
"""Initialize the websocket API.""" | ||
hass.http.register_view(http.WebsocketAPIView) | ||
hass.http.register_view(http.WebsocketAPIView()) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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").
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
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 beNone
ActiveConnection.refresh_token_id
can't beNone
To confirm this I checked not just typing but also how
ActiveConnection
andRefreshToken
are created.Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: