mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Tado bump 0.18.14 & race condition fix (#143531)
* Bump PyTado 0.18.14 * Add test
This commit is contained in:
parent
5fcdbd7742
commit
6f0c59f1be
@ -14,5 +14,5 @@
|
|||||||
},
|
},
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["PyTado"],
|
"loggers": ["PyTado"],
|
||||||
"requirements": ["python-tado==0.18.11"]
|
"requirements": ["python-tado==0.18.14"]
|
||||||
}
|
}
|
||||||
|
2
requirements_all.txt
generated
2
requirements_all.txt
generated
@ -2491,7 +2491,7 @@ python-snoo==0.6.5
|
|||||||
python-songpal==0.16.2
|
python-songpal==0.16.2
|
||||||
|
|
||||||
# homeassistant.components.tado
|
# homeassistant.components.tado
|
||||||
python-tado==0.18.11
|
python-tado==0.18.14
|
||||||
|
|
||||||
# homeassistant.components.technove
|
# homeassistant.components.technove
|
||||||
python-technove==2.0.0
|
python-technove==2.0.0
|
||||||
|
2
requirements_test_all.txt
generated
2
requirements_test_all.txt
generated
@ -2025,7 +2025,7 @@ python-snoo==0.6.5
|
|||||||
python-songpal==0.16.2
|
python-songpal==0.16.2
|
||||||
|
|
||||||
# homeassistant.components.tado
|
# homeassistant.components.tado
|
||||||
python-tado==0.18.11
|
python-tado==0.18.14
|
||||||
|
|
||||||
# homeassistant.components.technove
|
# homeassistant.components.technove
|
||||||
python-technove==2.0.0
|
python-technove==2.0.0
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
"""Test the Tado integration."""
|
"""Test the Tado integration."""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from PyTado.http import Http
|
||||||
|
|
||||||
from homeassistant.components.tado import DOMAIN
|
from homeassistant.components.tado import DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
@ -24,7 +30,37 @@ async def test_v1_migration(hass: HomeAssistant) -> None:
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert entry.version == 2
|
assert entry.version == 2
|
||||||
assert CONF_USERNAME not in entry.data
|
assert CONF_USERNAME not in entry.data
|
||||||
assert CONF_PASSWORD not in entry.data
|
|
||||||
|
|
||||||
assert entry.state is ConfigEntryState.SETUP_ERROR
|
|
||||||
assert len(hass.config_entries.flow.async_progress()) == 1
|
async def test_refresh_token_threading_lock(hass: HomeAssistant) -> None:
|
||||||
|
"""Test that threading.Lock in Http._refresh_token serializes concurrent calls."""
|
||||||
|
|
||||||
|
timestamps: list[tuple[str, float]] = []
|
||||||
|
lock = threading.Lock()
|
||||||
|
|
||||||
|
def fake_refresh_token(*args, **kwargs) -> bool:
|
||||||
|
"""Simulate the refresh token process with a threading lock."""
|
||||||
|
with lock:
|
||||||
|
timestamps.append(("start", time.monotonic()))
|
||||||
|
time.sleep(0.2)
|
||||||
|
timestamps.append(("end", time.monotonic()))
|
||||||
|
return True
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch("PyTado.http.Http._refresh_token", side_effect=fake_refresh_token),
|
||||||
|
patch("PyTado.http.Http.__init__", return_value=None),
|
||||||
|
):
|
||||||
|
http_instance = Http()
|
||||||
|
|
||||||
|
# Run two concurrent refresh token calls, should do the trick
|
||||||
|
await asyncio.gather(
|
||||||
|
hass.async_add_executor_job(http_instance._refresh_token),
|
||||||
|
hass.async_add_executor_job(http_instance._refresh_token),
|
||||||
|
)
|
||||||
|
|
||||||
|
end1 = timestamps[1][1]
|
||||||
|
start2 = timestamps[2][1]
|
||||||
|
|
||||||
|
assert start2 >= end1, (
|
||||||
|
f"Second refresh started before first ended: start2={start2}, end1={end1}."
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user