Update xknx to 0.18.11 and fix flaky test (#57877)

* Update xknx to 0.18.11

* review: join the queue before actually asserting
This commit is contained in:
Marvin Wichmann 2021-10-17 09:43:18 +02:00 committed by GitHub
parent b6ed8ca206
commit 48d4cdf882
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 13 deletions

View File

@ -290,7 +290,6 @@ class KNXModule:
"""Start XKNX object. Connect to tunneling or Routing device."""
await self.xknx.start()
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.stop)
self.connected = True
async def stop(self, event: Event) -> None:
"""Stop XKNX object. Disconnect from tunneling or Routing device."""

View File

@ -2,7 +2,7 @@
"domain": "knx",
"name": "KNX",
"documentation": "https://www.home-assistant.io/integrations/knx",
"requirements": ["xknx==0.18.10"],
"requirements": ["xknx==0.18.11"],
"codeowners": ["@Julius2342", "@farmio", "@marvin-w"],
"quality_scale": "silver",
"iot_class": "local_push"

View File

@ -2427,7 +2427,7 @@ xbox-webapi==2.0.11
xboxapi==2.0.1
# homeassistant.components.knx
xknx==0.18.10
xknx==0.18.11
# homeassistant.components.bluesound
# homeassistant.components.fritz

View File

@ -1398,7 +1398,7 @@ wolf_smartset==0.1.11
xbox-webapi==2.0.11
# homeassistant.components.knx
xknx==0.18.10
xknx==0.18.11
# homeassistant.components.bluesound
# homeassistant.components.fritz

View File

@ -6,6 +6,7 @@ from unittest.mock import DEFAULT, AsyncMock, Mock, patch
import pytest
from xknx import XKNX
from xknx.core import XknxConnectionState
from xknx.dpt import DPTArray, DPTBinary
from xknx.telegram import Telegram, TelegramDirection
from xknx.telegram.address import GroupAddress, IndividualAddress
@ -53,6 +54,9 @@ class KNXTestKit:
side_effect=fish_xknx,
):
await async_setup_component(self.hass, KNX_DOMAIN, {KNX_DOMAIN: config})
await self.xknx.connection_manager.connection_state_changed(
XknxConnectionState.CONNECTED
)
await self.hass.async_block_till_done()
########################
@ -94,6 +98,7 @@ class KNXTestKit:
apci_type: type[APCI],
) -> None:
"""Assert outgoing telegram. One by one in timely order."""
await self.xknx.telegrams.join()
await self.hass.async_block_till_done()
try:
telegram = self._outgoing_telegrams.get_nowait()

View File

@ -1,5 +1,4 @@
"""Test KNX binary sensor."""
import asyncio
from datetime import timedelta
from homeassistant.components.knx.const import CONF_STATE_ADDRESS, CONF_SYNC_STATE
@ -120,6 +119,7 @@ async def test_binary_sensor_counter(hass: HomeAssistant, knx: KNXTestKit):
"""Test KNX binary_sensor with context timeout."""
async_fire_time_changed(hass, dt.utcnow())
events = async_capture_events(hass, "state_changed")
context_timeout = 1
await knx.setup_integration(
{
@ -127,7 +127,7 @@ async def test_binary_sensor_counter(hass: HomeAssistant, knx: KNXTestKit):
{
CONF_NAME: "test",
CONF_STATE_ADDRESS: "2/2/2",
BinarySensorSchema.CONF_CONTEXT_TIMEOUT: 0.001,
BinarySensorSchema.CONF_CONTEXT_TIMEOUT: context_timeout,
CONF_SYNC_STATE: False,
},
]
@ -145,9 +145,9 @@ async def test_binary_sensor_counter(hass: HomeAssistant, knx: KNXTestKit):
state = hass.states.get("binary_sensor.test")
assert state.state is STATE_OFF
assert state.attributes.get("counter") == 0
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=0.001))
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=context_timeout))
await hass.async_block_till_done()
await asyncio.sleep(0.002)
await knx.xknx.task_registry.block_till_done()
# state changed twice after context timeout - once to ON with counter 1 and once to counter 0
state = hass.states.get("binary_sensor.test")
assert state.state is STATE_ON
@ -169,18 +169,19 @@ async def test_binary_sensor_counter(hass: HomeAssistant, knx: KNXTestKit):
state = hass.states.get("binary_sensor.test")
assert state.state is STATE_ON
assert state.attributes.get("counter") == 0
await hass.async_block_till_done()
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=1))
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=context_timeout))
await knx.xknx.task_registry.block_till_done()
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test")
assert state.state is STATE_ON
assert state.attributes.get("counter") == 0
await hass.async_block_till_done()
await hass.async_block_till_done()
assert len(events) == 1
assert len(events) == 2
event = events.pop(0).data
assert event.get("new_state").attributes.get("counter") == 2
assert event.get("old_state").attributes.get("counter") == 0
event = events.pop(0).data
assert event.get("new_state").attributes.get("counter") == 0
assert event.get("old_state").attributes.get("counter") == 2
async def test_binary_sensor_reset(hass: HomeAssistant, knx: KNXTestKit):