mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
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:
parent
b6ed8ca206
commit
48d4cdf882
@ -290,7 +290,6 @@ class KNXModule:
|
|||||||
"""Start XKNX object. Connect to tunneling or Routing device."""
|
"""Start XKNX object. Connect to tunneling or Routing device."""
|
||||||
await self.xknx.start()
|
await self.xknx.start()
|
||||||
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.stop)
|
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.stop)
|
||||||
self.connected = True
|
|
||||||
|
|
||||||
async def stop(self, event: Event) -> None:
|
async def stop(self, event: Event) -> None:
|
||||||
"""Stop XKNX object. Disconnect from tunneling or Routing device."""
|
"""Stop XKNX object. Disconnect from tunneling or Routing device."""
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"domain": "knx",
|
"domain": "knx",
|
||||||
"name": "KNX",
|
"name": "KNX",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/knx",
|
"documentation": "https://www.home-assistant.io/integrations/knx",
|
||||||
"requirements": ["xknx==0.18.10"],
|
"requirements": ["xknx==0.18.11"],
|
||||||
"codeowners": ["@Julius2342", "@farmio", "@marvin-w"],
|
"codeowners": ["@Julius2342", "@farmio", "@marvin-w"],
|
||||||
"quality_scale": "silver",
|
"quality_scale": "silver",
|
||||||
"iot_class": "local_push"
|
"iot_class": "local_push"
|
||||||
|
@ -2427,7 +2427,7 @@ xbox-webapi==2.0.11
|
|||||||
xboxapi==2.0.1
|
xboxapi==2.0.1
|
||||||
|
|
||||||
# homeassistant.components.knx
|
# homeassistant.components.knx
|
||||||
xknx==0.18.10
|
xknx==0.18.11
|
||||||
|
|
||||||
# homeassistant.components.bluesound
|
# homeassistant.components.bluesound
|
||||||
# homeassistant.components.fritz
|
# homeassistant.components.fritz
|
||||||
|
@ -1398,7 +1398,7 @@ wolf_smartset==0.1.11
|
|||||||
xbox-webapi==2.0.11
|
xbox-webapi==2.0.11
|
||||||
|
|
||||||
# homeassistant.components.knx
|
# homeassistant.components.knx
|
||||||
xknx==0.18.10
|
xknx==0.18.11
|
||||||
|
|
||||||
# homeassistant.components.bluesound
|
# homeassistant.components.bluesound
|
||||||
# homeassistant.components.fritz
|
# homeassistant.components.fritz
|
||||||
|
@ -6,6 +6,7 @@ from unittest.mock import DEFAULT, AsyncMock, Mock, patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from xknx import XKNX
|
from xknx import XKNX
|
||||||
|
from xknx.core import XknxConnectionState
|
||||||
from xknx.dpt import DPTArray, DPTBinary
|
from xknx.dpt import DPTArray, DPTBinary
|
||||||
from xknx.telegram import Telegram, TelegramDirection
|
from xknx.telegram import Telegram, TelegramDirection
|
||||||
from xknx.telegram.address import GroupAddress, IndividualAddress
|
from xknx.telegram.address import GroupAddress, IndividualAddress
|
||||||
@ -53,6 +54,9 @@ class KNXTestKit:
|
|||||||
side_effect=fish_xknx,
|
side_effect=fish_xknx,
|
||||||
):
|
):
|
||||||
await async_setup_component(self.hass, KNX_DOMAIN, {KNX_DOMAIN: config})
|
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()
|
await self.hass.async_block_till_done()
|
||||||
|
|
||||||
########################
|
########################
|
||||||
@ -94,6 +98,7 @@ class KNXTestKit:
|
|||||||
apci_type: type[APCI],
|
apci_type: type[APCI],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Assert outgoing telegram. One by one in timely order."""
|
"""Assert outgoing telegram. One by one in timely order."""
|
||||||
|
await self.xknx.telegrams.join()
|
||||||
await self.hass.async_block_till_done()
|
await self.hass.async_block_till_done()
|
||||||
try:
|
try:
|
||||||
telegram = self._outgoing_telegrams.get_nowait()
|
telegram = self._outgoing_telegrams.get_nowait()
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Test KNX binary sensor."""
|
"""Test KNX binary sensor."""
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from homeassistant.components.knx.const import CONF_STATE_ADDRESS, CONF_SYNC_STATE
|
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."""
|
"""Test KNX binary_sensor with context timeout."""
|
||||||
async_fire_time_changed(hass, dt.utcnow())
|
async_fire_time_changed(hass, dt.utcnow())
|
||||||
events = async_capture_events(hass, "state_changed")
|
events = async_capture_events(hass, "state_changed")
|
||||||
|
context_timeout = 1
|
||||||
|
|
||||||
await knx.setup_integration(
|
await knx.setup_integration(
|
||||||
{
|
{
|
||||||
@ -127,7 +127,7 @@ async def test_binary_sensor_counter(hass: HomeAssistant, knx: KNXTestKit):
|
|||||||
{
|
{
|
||||||
CONF_NAME: "test",
|
CONF_NAME: "test",
|
||||||
CONF_STATE_ADDRESS: "2/2/2",
|
CONF_STATE_ADDRESS: "2/2/2",
|
||||||
BinarySensorSchema.CONF_CONTEXT_TIMEOUT: 0.001,
|
BinarySensorSchema.CONF_CONTEXT_TIMEOUT: context_timeout,
|
||||||
CONF_SYNC_STATE: False,
|
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")
|
state = hass.states.get("binary_sensor.test")
|
||||||
assert state.state is STATE_OFF
|
assert state.state is STATE_OFF
|
||||||
assert state.attributes.get("counter") == 0
|
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 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 changed twice after context timeout - once to ON with counter 1 and once to counter 0
|
||||||
state = hass.states.get("binary_sensor.test")
|
state = hass.states.get("binary_sensor.test")
|
||||||
assert state.state is STATE_ON
|
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")
|
state = hass.states.get("binary_sensor.test")
|
||||||
assert state.state is STATE_ON
|
assert state.state is STATE_ON
|
||||||
assert state.attributes.get("counter") == 0
|
assert state.attributes.get("counter") == 0
|
||||||
await hass.async_block_till_done()
|
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=context_timeout))
|
||||||
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=1))
|
await knx.xknx.task_registry.block_till_done()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("binary_sensor.test")
|
state = hass.states.get("binary_sensor.test")
|
||||||
assert state.state is STATE_ON
|
assert state.state is STATE_ON
|
||||||
assert state.attributes.get("counter") == 0
|
assert state.attributes.get("counter") == 0
|
||||||
await hass.async_block_till_done()
|
assert len(events) == 2
|
||||||
await hass.async_block_till_done()
|
|
||||||
assert len(events) == 1
|
|
||||||
event = events.pop(0).data
|
event = events.pop(0).data
|
||||||
assert event.get("new_state").attributes.get("counter") == 2
|
assert event.get("new_state").attributes.get("counter") == 2
|
||||||
assert event.get("old_state").attributes.get("counter") == 0
|
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):
|
async def test_binary_sensor_reset(hass: HomeAssistant, knx: KNXTestKit):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user