hass-core/tests/components/temper/test_sensor.py
J. Nick Koston 9a79320861
Mark executor jobs as background unless created from a tracked task ()
* Mark executor jobs as background unless created from a tracked task

If the current task is not tracked the executor job should not
be a background task to avoid delaying startup and shutdown.

Currently any executor job created in a untracked task or
background task would end up being tracked and delaying
startup/shutdown

* import exec has the same issue

* Avoid tracking import executor jobs

There is no reason to track these jobs as they are always awaited
and we do not want to support fire and forget import executor jobs

* fix xiaomi_miio

* lots of fire time changed without background await

* revert changes moved to other PR

* more

* more

* more

* m

* m

* p

* fix fire and forget tests

* scrape

* sonos

* system

* more

* capture callback before block

* coverage

* more

* more races

* more races

* more

* missed some

* more fixes

* missed some more

* fix

* remove unneeded

* one more race

* two
2024-03-30 00:16:53 -04:00

36 lines
1.1 KiB
Python

"""The tests for the temper (USB temperature sensor) component."""
from datetime import timedelta
from unittest.mock import Mock, patch
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
from tests.common import async_fire_time_changed
async def test_temperature_readback(hass: HomeAssistant) -> None:
"""Test for reading sensors."""
mock_temper_device = Mock()
mock_temper_device.get_temperature.return_value = 12.3
utcnow = dt_util.utcnow()
with patch(
"temperusb.temper.TemperHandler.get_devices",
return_value=[mock_temper_device],
):
await async_setup_component(
hass,
"sensor",
{"sensor": {"platform": "temper", "name": "mydevicename"}},
)
await hass.async_block_till_done()
async_fire_time_changed(hass, utcnow + timedelta(seconds=70))
await hass.async_block_till_done(wait_background_tasks=True)
temperature = hass.states.get("sensor.mydevicename")
assert temperature
assert temperature.state == "12.3"