From 09d1c90e670fa5fdb4a9df33e52bc17a2cbd06c6 Mon Sep 17 00:00:00 2001 From: marvin-w Date: Thu, 28 Apr 2022 20:54:18 +0200 Subject: [PATCH] Test invalid payload type for websocket subscription --- tests/components/knx/conftest.py | 21 ++++++++++++++++++++- tests/components/knx/test_websocket.py | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/components/knx/conftest.py b/tests/components/knx/conftest.py index e5cf18b0c3..f5c322341e 100644 --- a/tests/components/knx/conftest.py +++ b/tests/components/knx/conftest.py @@ -11,7 +11,13 @@ from xknx.dpt import DPTArray, DPTBinary from xknx.io import DEFAULT_MCAST_GRP, DEFAULT_MCAST_PORT from xknx.telegram import Telegram, TelegramDirection from xknx.telegram.address import GroupAddress, IndividualAddress -from xknx.telegram.apci import APCI, GroupValueRead, GroupValueResponse, GroupValueWrite +from xknx.telegram.apci import ( + APCI, + GroupValueRead, + GroupValueResponse, + GroupValueWrite, + IndividualAddressRead, +) from homeassistant.components.knx.const import ( CONF_KNX_AUTOMATIC, @@ -188,6 +194,19 @@ class KNXTestKit: await self.xknx.telegrams.join() await self.hass.async_block_till_done() + async def receive_individual_address_read(self): + """Inject incoming IndividualAddressRead telegram.""" + self.xknx.telegrams.put_nowait( + Telegram( + destination_address=IndividualAddress(self.INDIVIDUAL_ADDRESS), + direction=TelegramDirection.INCOMING, + payload=IndividualAddressRead(), + source_address=IndividualAddress("1.3.5"), + ) + ) + await self.xknx.telegrams.join() + await self.hass.async_block_till_done() + async def receive_read( self, group_address: str, diff --git a/tests/components/knx/test_websocket.py b/tests/components/knx/test_websocket.py index d45560bd33..eb8bd6d26f 100644 --- a/tests/components/knx/test_websocket.py +++ b/tests/components/knx/test_websocket.py @@ -46,6 +46,7 @@ async def test_knx_subscribe_telegrams_command( await knx.receive_read("1/2/3") await knx.receive_write("1/3/4", True) await knx.receive_write("1/3/4", False) + await knx.receive_individual_address_read() await knx.receive_write("1/3/8", (0x34, 0x45)) # send outgoing events await hass.services.async_call( @@ -92,6 +93,6 @@ async def test_knx_subscribe_telegrams_command( assert res["event"]["type"] == "GroupValueWrite" assert ( res["event"]["source_address"] == "0.0.0" - ) # needs to be the currently connected IA connected to + ) # needs to be the IA currently connected to assert res["event"]["direction"] == "label.outgoing" assert res["event"]["timestamp"] is not None