Skip to content

Commit

Permalink
Add connection_info handler (#477)
Browse files Browse the repository at this point in the history
* Add connection_info handler

* Make it seperate

* cleanup

* Update hass_nabucasa/client.py

* Update hass_nabucasa/client.py

* Update hass_nabucasa/client.py

* Update hass_nabucasa/client.py
  • Loading branch information
ludeeus authored Jun 26, 2023
1 parent 3641621 commit 729a90b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hass_nabucasa/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ async def logout_cleanups(self) -> None:
async def async_cloud_connect_update(self, connect: bool) -> None:
"""Process cloud remote message to client."""

@abstractmethod
async def async_cloud_connection_info(
self, payload: dict[str, Any]
) -> dict[str, Any]:
"""Process cloud connection info message to client."""

@abstractmethod
async def async_alexa_message(self, payload: dict[str, Any]) -> dict[str, Any]:
"""process cloud alexa message to client."""
Expand Down
9 changes: 9 additions & 0 deletions hass_nabucasa/iot.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ async def async_handle_remote_sni(
return {"server": cloud.remote.snitun_server}


@HANDLERS.register("connection_info")
async def async_handle_connection_info(
cloud: Cloud[_ClientT],
payload: dict[str, Any],
) -> dict[str, Any]:
"""Handle connection info requests for cloud."""
return await cloud.client.async_cloud_connection_info(payload)


@HANDLERS.register("webhook")
async def async_handle_webhook(
cloud: Cloud[_ClientT], payload: dict[str, Any]
Expand Down
6 changes: 6 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, loop, websession):
self.mock_google = []
self.mock_webhooks = []
self.mock_system = []
self.mock_connection_info = []

self.mock_return = []
self._base_path = None
Expand Down Expand Up @@ -112,6 +113,11 @@ async def async_system_message(self, payload):
self.mock_system.append(payload)
return self.mock_return.pop()

async def async_cloud_connection_info(self, payload) -> dict[Any, Any]:
"""Process cloud connection info message to client."""
self.mock_connection_info.append(payload)
return self.mock_return.pop()

async def async_cloudhooks_update(self, data):
"""Update internal cloudhooks data."""
self._cloudhooks = data
Expand Down
7 changes: 7 additions & 0 deletions tests/test_iot.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ async def test_handler_remote_sni(cloud_mock):
assert resp == {"server": "1.1.1.1"}


async def test_handler_remote_sni_action(cloud_mock):
"""Test connection info."""
cloud_mock.client.mock_return.append({"test": 5})
resp = await iot.async_handle_connection_info(cloud_mock, {})
assert resp == {"test": 5}


async def test_send_message_no_answer(cloud_mock_iot):
"""Test sending a message that expects no answer."""
cloud_iot = iot.CloudIoT(cloud_mock_iot)
Expand Down

0 comments on commit 729a90b

Please sign in to comment.