-
Notifications
You must be signed in to change notification settings - Fork 788
Use Unix socket for Supervisor to Core communication #6590
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
Changes from 10 commits
5780bbc
5793501
2ad550a
ef4f882
916c63d
f06f8bd
b6c9704
c6d2a58
6d32b01
94adca1
b3a9eff
20e72b7
d022710
b4f5252
b289d9f
a314ed8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,6 @@ | |||||
|
|
||||||
| import aiohttp | ||||||
| from aiohttp import WSCloseCode, WSMessageTypeError, web | ||||||
| from aiohttp.client_exceptions import ClientConnectorError | ||||||
| from aiohttp.client_ws import ClientWebSocketResponse | ||||||
| from aiohttp.hdrs import AUTHORIZATION, CONTENT_TYPE | ||||||
| from aiohttp.http_websocket import WSMsgType | ||||||
|
|
@@ -179,57 +178,17 @@ async def api(self, request: web.Request): | |||||
|
|
||||||
| async def _websocket_client(self) -> ClientWebSocketResponse: | ||||||
| """Initialize a WebSocket API connection.""" | ||||||
| url = f"{self.sys_homeassistant.api_url}/api/websocket" | ||||||
|
|
||||||
| try: | ||||||
| client = await self.sys_websession.ws_connect( | ||||||
| url, heartbeat=30, ssl=False, max_msg_size=MAX_MESSAGE_SIZE_FROM_CORE | ||||||
| ) | ||||||
|
|
||||||
| # Handle authentication | ||||||
| data = await client.receive_json() | ||||||
|
|
||||||
| if data.get("type") == "auth_ok": | ||||||
| return client | ||||||
|
|
||||||
| if data.get("type") != "auth_required": | ||||||
| # Invalid protocol | ||||||
| raise APIError( | ||||||
| f"Got unexpected response from Home Assistant WebSocket: {data}", | ||||||
| _LOGGER.error, | ||||||
| ) | ||||||
|
|
||||||
| # Auth session | ||||||
| await self.sys_homeassistant.api.ensure_access_token() | ||||||
| await client.send_json( | ||||||
| { | ||||||
| "type": "auth", | ||||||
| "access_token": self.sys_homeassistant.api.access_token, | ||||||
| }, | ||||||
| dumps=json_dumps, | ||||||
| ws_client = await self.sys_homeassistant.api.connect_websocket( | ||||||
| max_msg_size=MAX_MESSAGE_SIZE_FROM_CORE | ||||||
| ) | ||||||
|
|
||||||
| data = await client.receive_json() | ||||||
|
|
||||||
| if data.get("type") == "auth_ok": | ||||||
| return client | ||||||
|
|
||||||
| # Renew the Token is invalid | ||||||
| if ( | ||||||
| data.get("type") == "invalid_auth" | ||||||
| and self.sys_homeassistant.refresh_token | ||||||
| ): | ||||||
| self.sys_homeassistant.api.access_token = None | ||||||
| return await self._websocket_client() | ||||||
|
|
||||||
| raise HomeAssistantAuthError() | ||||||
|
|
||||||
| except (RuntimeError, ValueError, TypeError, ClientConnectorError) as err: | ||||||
| return ws_client.client | ||||||
| except HomeAssistantAPIError as err: | ||||||
| _LOGGER.error("Error connecting to Home Assistant WebSocket: %s", err) | ||||||
| raise APIError() from err | ||||||
| except (RuntimeError, ValueError, TypeError) as err: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Looks like the AI is still not doing what you want here despite the instructions change. Is this a mypy problem by any chance? When it did it to me I noticed it was driven from a mypy error about it which was really because mypy was out of date in that environment.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be that this code predates my
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah with the centralized authentication logic in
Let's remove |
||||||
| _LOGGER.error("Client error on WebSocket API %s.", err) | ||||||
| except HomeAssistantAuthError: | ||||||
| _LOGGER.error("Failed authentication to Home Assistant WebSocket") | ||||||
|
|
||||||
| raise APIError() | ||||||
| raise APIError() from err | ||||||
|
agners marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| async def _proxy_message( | ||||||
| self, | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,7 @@ class MountBindOptions: | |
|
|
||
| propagation: PropagationMode | None = None | ||
| read_only_non_recursive: bool | None = None | ||
| create_mountpoint: bool | None = None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't seem like this is used anywhere?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this came from an earlier iteration, where I used different paths in |
||
|
|
||
| def to_dict(self) -> dict[str, Any]: | ||
| """To dictionary representation.""" | ||
|
|
@@ -97,6 +98,8 @@ def to_dict(self) -> dict[str, Any]: | |
| out["Propagation"] = self.propagation.value | ||
| if self.read_only_non_recursive is not None: | ||
| out["ReadOnlyNonRecursive"] = self.read_only_non_recursive | ||
| if self.create_mountpoint is not None: | ||
| out["CreateMountpoint"] = self.create_mountpoint | ||
| return out | ||
|
|
||
|
|
||
|
|
@@ -140,6 +143,7 @@ def to_dict(self) -> dict[str, str | int]: | |
| } | ||
|
|
||
|
|
||
| ENV_CORE_API_SOCKET = "SUPERVISOR_CORE_API_SOCKET" | ||
| ENV_DUPLICATE_LOG_FILE = "HA_DUPLICATE_LOG_FILE" | ||
| ENV_TIME = "TZ" | ||
| ENV_TOKEN = "SUPERVISOR_TOKEN" | ||
|
|
@@ -169,6 +173,12 @@ def to_dict(self) -> dict[str, str | int]: | |
| target=MACHINE_ID.as_posix(), | ||
| read_only=True, | ||
| ) | ||
| MOUNT_CORE_RUN = DockerMount( | ||
| type=MountType.BIND, | ||
| source="/run/supervisor", | ||
| target="/run/supervisor", | ||
| read_only=False, | ||
| ) | ||
| MOUNT_UDEV = DockerMount( | ||
| type=MountType.BIND, source="/run/udev", target="/run/udev", read_only=True | ||
| ) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.