Improve broadlink sensor tests (#39632)
This commit is contained in:
parent
1034e4ec50
commit
48cfbf8662
1 changed files with 8 additions and 49 deletions
|
@ -4,18 +4,9 @@ from homeassistant.helpers.entity_registry import async_entries_for_device
|
||||||
|
|
||||||
from . import get_device
|
from . import get_device
|
||||||
|
|
||||||
from tests.async_mock import patch
|
|
||||||
from tests.common import mock_device_registry, mock_registry
|
from tests.common import mock_device_registry, mock_registry
|
||||||
|
|
||||||
|
|
||||||
def _patch_broadlink_gendevice(return_value):
|
|
||||||
"""Patch the broadlink gendevice method."""
|
|
||||||
return patch(
|
|
||||||
"homeassistant.components.broadlink.device.blk.gendevice",
|
|
||||||
return_value=return_value,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_a1_sensor_setup(hass):
|
async def test_a1_sensor_setup(hass):
|
||||||
"""Test a successful e-Sensor setup."""
|
"""Test a successful e-Sensor setup."""
|
||||||
device = get_device("Bedroom")
|
device = get_device("Bedroom")
|
||||||
|
@ -27,15 +18,11 @@ async def test_a1_sensor_setup(hass):
|
||||||
"light": 2,
|
"light": 2,
|
||||||
"noise": 1,
|
"noise": 1,
|
||||||
}
|
}
|
||||||
mock_entry = device.get_mock_entry()
|
|
||||||
mock_entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
device_registry = mock_device_registry(hass)
|
device_registry = mock_device_registry(hass)
|
||||||
entity_registry = mock_registry(hass)
|
entity_registry = mock_registry(hass)
|
||||||
|
|
||||||
with _patch_broadlink_gendevice(return_value=mock_api):
|
mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api)
|
||||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert mock_api.check_sensors_raw.call_count == 1
|
assert mock_api.check_sensors_raw.call_count == 1
|
||||||
device_entry = device_registry.async_get_device(
|
device_entry = device_registry.async_get_device(
|
||||||
|
@ -69,15 +56,11 @@ async def test_a1_sensor_update(hass):
|
||||||
"light": 2,
|
"light": 2,
|
||||||
"noise": 1,
|
"noise": 1,
|
||||||
}
|
}
|
||||||
mock_entry = device.get_mock_entry()
|
|
||||||
mock_entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
device_registry = mock_device_registry(hass)
|
device_registry = mock_device_registry(hass)
|
||||||
entity_registry = mock_registry(hass)
|
entity_registry = mock_registry(hass)
|
||||||
|
|
||||||
with _patch_broadlink_gendevice(return_value=mock_api):
|
mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api)
|
||||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
device_entry = device_registry.async_get_device(
|
device_entry = device_registry.async_get_device(
|
||||||
{(DOMAIN, mock_entry.unique_id)}, set()
|
{(DOMAIN, mock_entry.unique_id)}, set()
|
||||||
|
@ -116,15 +99,11 @@ async def test_rm_pro_sensor_setup(hass):
|
||||||
device = get_device("Office")
|
device = get_device("Office")
|
||||||
mock_api = device.get_mock_api()
|
mock_api = device.get_mock_api()
|
||||||
mock_api.check_sensors.return_value = {"temperature": 18.2}
|
mock_api.check_sensors.return_value = {"temperature": 18.2}
|
||||||
mock_entry = device.get_mock_entry()
|
|
||||||
mock_entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
device_registry = mock_device_registry(hass)
|
device_registry = mock_device_registry(hass)
|
||||||
entity_registry = mock_registry(hass)
|
entity_registry = mock_registry(hass)
|
||||||
|
|
||||||
with _patch_broadlink_gendevice(return_value=mock_api):
|
mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api)
|
||||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert mock_api.check_sensors.call_count == 1
|
assert mock_api.check_sensors.call_count == 1
|
||||||
device_entry = device_registry.async_get_device(
|
device_entry = device_registry.async_get_device(
|
||||||
|
@ -146,15 +125,11 @@ async def test_rm_pro_sensor_update(hass):
|
||||||
device = get_device("Office")
|
device = get_device("Office")
|
||||||
mock_api = device.get_mock_api()
|
mock_api = device.get_mock_api()
|
||||||
mock_api.check_sensors.return_value = {"temperature": 25.7}
|
mock_api.check_sensors.return_value = {"temperature": 25.7}
|
||||||
mock_entry = device.get_mock_entry()
|
|
||||||
mock_entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
device_registry = mock_device_registry(hass)
|
device_registry = mock_device_registry(hass)
|
||||||
entity_registry = mock_registry(hass)
|
entity_registry = mock_registry(hass)
|
||||||
|
|
||||||
with _patch_broadlink_gendevice(return_value=mock_api):
|
mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api)
|
||||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
device_entry = device_registry.async_get_device(
|
device_entry = device_registry.async_get_device(
|
||||||
{(DOMAIN, mock_entry.unique_id)}, set()
|
{(DOMAIN, mock_entry.unique_id)}, set()
|
||||||
|
@ -181,15 +156,11 @@ async def test_rm_mini3_no_sensor(hass):
|
||||||
device = get_device("Entrance")
|
device = get_device("Entrance")
|
||||||
mock_api = device.get_mock_api()
|
mock_api = device.get_mock_api()
|
||||||
mock_api.check_sensors.return_value = {"temperature": 0}
|
mock_api.check_sensors.return_value = {"temperature": 0}
|
||||||
mock_entry = device.get_mock_entry()
|
|
||||||
mock_entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
device_registry = mock_device_registry(hass)
|
device_registry = mock_device_registry(hass)
|
||||||
entity_registry = mock_registry(hass)
|
entity_registry = mock_registry(hass)
|
||||||
|
|
||||||
with _patch_broadlink_gendevice(return_value=mock_api):
|
mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api)
|
||||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert mock_api.check_sensors.call_count <= 1
|
assert mock_api.check_sensors.call_count <= 1
|
||||||
device_entry = device_registry.async_get_device(
|
device_entry = device_registry.async_get_device(
|
||||||
|
@ -205,15 +176,11 @@ async def test_rm4_pro_hts2_sensor_setup(hass):
|
||||||
device = get_device("Garage")
|
device = get_device("Garage")
|
||||||
mock_api = device.get_mock_api()
|
mock_api = device.get_mock_api()
|
||||||
mock_api.check_sensors.return_value = {"temperature": 22.5, "humidity": 43.7}
|
mock_api.check_sensors.return_value = {"temperature": 22.5, "humidity": 43.7}
|
||||||
mock_entry = device.get_mock_entry()
|
|
||||||
mock_entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
device_registry = mock_device_registry(hass)
|
device_registry = mock_device_registry(hass)
|
||||||
entity_registry = mock_registry(hass)
|
entity_registry = mock_registry(hass)
|
||||||
|
|
||||||
with _patch_broadlink_gendevice(return_value=mock_api):
|
mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api)
|
||||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert mock_api.check_sensors.call_count == 1
|
assert mock_api.check_sensors.call_count == 1
|
||||||
device_entry = device_registry.async_get_device(
|
device_entry = device_registry.async_get_device(
|
||||||
|
@ -238,15 +205,11 @@ async def test_rm4_pro_hts2_sensor_update(hass):
|
||||||
device = get_device("Garage")
|
device = get_device("Garage")
|
||||||
mock_api = device.get_mock_api()
|
mock_api = device.get_mock_api()
|
||||||
mock_api.check_sensors.return_value = {"temperature": 16.7, "humidity": 34.1}
|
mock_api.check_sensors.return_value = {"temperature": 16.7, "humidity": 34.1}
|
||||||
mock_entry = device.get_mock_entry()
|
|
||||||
mock_entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
device_registry = mock_device_registry(hass)
|
device_registry = mock_device_registry(hass)
|
||||||
entity_registry = mock_registry(hass)
|
entity_registry = mock_registry(hass)
|
||||||
|
|
||||||
with _patch_broadlink_gendevice(return_value=mock_api):
|
mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api)
|
||||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
device_entry = device_registry.async_get_device(
|
device_entry = device_registry.async_get_device(
|
||||||
{(DOMAIN, mock_entry.unique_id)}, set()
|
{(DOMAIN, mock_entry.unique_id)}, set()
|
||||||
|
@ -276,15 +239,11 @@ async def test_rm4_pro_no_sensor(hass):
|
||||||
device = get_device("Garage")
|
device = get_device("Garage")
|
||||||
mock_api = device.get_mock_api()
|
mock_api = device.get_mock_api()
|
||||||
mock_api.check_sensors.return_value = {"temperature": 0, "humidity": 0}
|
mock_api.check_sensors.return_value = {"temperature": 0, "humidity": 0}
|
||||||
mock_entry = device.get_mock_entry()
|
|
||||||
mock_entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
device_registry = mock_device_registry(hass)
|
device_registry = mock_device_registry(hass)
|
||||||
entity_registry = mock_registry(hass)
|
entity_registry = mock_registry(hass)
|
||||||
|
|
||||||
with _patch_broadlink_gendevice(return_value=mock_api):
|
mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api)
|
||||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert mock_api.check_sensors.call_count <= 1
|
assert mock_api.check_sensors.call_count <= 1
|
||||||
device_entry = device_registry.async_get_device(
|
device_entry = device_registry.async_get_device(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue