1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +00:00

Reduce overhead to update passive bluetooth devices (#78545)

This commit is contained in:
J. Nick Koston
2022-09-16 12:24:20 +02:00
committed by GitHub
parent b093c2840b
commit 085abc74ee
25 changed files with 364 additions and 709 deletions

View File

@@ -1,8 +1,5 @@
"""Test the SensorPush config flow."""
"""Test the SensorPush sensors."""
from unittest.mock import patch
from homeassistant.components.bluetooth import BluetoothChange
from homeassistant.components.sensor import ATTR_STATE_CLASS
from homeassistant.components.sensorpush.const import DOMAIN
from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_UNIT_OF_MEASUREMENT
@@ -10,32 +7,22 @@ from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_UNIT_OF_MEASUREMENT
from . import HTPWX_SERVICE_INFO
from tests.common import MockConfigEntry
from tests.components.bluetooth import inject_bluetooth_service_info
async def test_sensors(hass):
"""Test setting up creates the sensors."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id="61DE521B-F0BF-9F44-64D4-75BBE1738105",
unique_id="4125DDBA-2774-4851-9889-6AADDD4CAC3D",
)
entry.add_to_hass(hass)
saved_callback = None
def _async_register_callback(_hass, _callback, _matcher, _mode):
nonlocal saved_callback
saved_callback = _callback
return lambda: None
with patch(
"homeassistant.components.bluetooth.update_coordinator.async_register_callback",
_async_register_callback,
):
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0
saved_callback(HTPWX_SERVICE_INFO, BluetoothChange.ADVERTISEMENT)
inject_bluetooth_service_info(hass, HTPWX_SERVICE_INFO)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 3