Skip to content

Commit

Permalink
Forward handling of system messages (#420)
Browse files Browse the repository at this point in the history
* Forward handling of system messages

* Fix return
  • Loading branch information
ludeeus authored Mar 23, 2023
1 parent 4bdbdb0 commit 9e2687e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions hass_nabucasa/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ async def async_cloud_connect_update(self, connect: bool) -> None:
async def async_alexa_message(self, payload: dict[Any, Any]) -> dict[Any, Any]:
"""process cloud alexa message to client."""

@abstractmethod
async def async_system_message(self, payload: dict[Any, Any]) -> None:
"""process cloud system message to client."""

@abstractmethod
async def async_google_message(self, payload: dict[Any, Any]) -> dict[Any, Any]:
"""Process cloud google message to client."""
Expand Down
4 changes: 2 additions & 2 deletions hass_nabucasa/iot.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ async def _async_handle_handler_message(self, message: dict[str, Any]) -> None:

@HANDLERS.register("system")
async def async_handle_system(cloud: Cloud, payload: dict[str, Any]) -> None:
"""We ignore incoming system IoT messages."""
return None
"""Handle an incoming IoT message for System."""
return await cloud.client.async_system_message(payload)


@HANDLERS.register("alexa")
Expand Down
6 changes: 6 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, loop, websession):
self.mock_alexa = []
self.mock_google = []
self.mock_webhooks = []
self.mock_system = []

self.mock_return = []
self._base_path = None
Expand Down Expand Up @@ -98,6 +99,11 @@ async def async_webhook_message(self, payload):
self.mock_webhooks.append(payload)
return self.mock_return.pop()

async def async_system_message(self, payload):
"""Process cloud system message to client."""
self.mock_system.append(payload)
return self.mock_return.pop()

async def async_cloudhooks_update(self, data):
"""Update internal cloudhooks data."""
self._cloudhooks = data
Expand Down
9 changes: 9 additions & 0 deletions tests/test_iot.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ async def test_handler_webhook(cloud_mock):
assert resp == {"test": 5}


async def test_handler_system(cloud_mock):
"""Test handler system."""
cloud_mock.client.mock_return.append({"test": 5})
resp = await iot.async_handle_system(cloud_mock, {"test-discovery": True})

assert len(cloud_mock.client.mock_system) == 1
assert resp == {"test": 5}


async def test_handler_remote_sni(cloud_mock):
"""Test handler Webhook."""
assert not cloud_mock.client.pref_should_connect
Expand Down

0 comments on commit 9e2687e

Please sign in to comment.