Refactor patching in onewire tests (#135070)

This commit is contained in:
epenet 2025-01-08 15:14:51 +01:00 committed by GitHub
parent bc09e825a9
commit f05e234c30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 244 additions and 345 deletions

View File

@ -7,57 +7,62 @@ from unittest.mock import MagicMock
from pyownet.protocol import ProtocolError from pyownet.protocol import ProtocolError
from homeassistant.const import Platform
from .const import ATTR_INJECT_READS, MOCK_OWPROXY_DEVICES from .const import ATTR_INJECT_READS, MOCK_OWPROXY_DEVICES
def setup_owproxy_mock_devices( def setup_owproxy_mock_devices(owproxy: MagicMock, device_ids: list[str]) -> None:
owproxy: MagicMock, platform: Platform, device_ids: list[str]
) -> None:
"""Set up mock for owproxy.""" """Set up mock for owproxy."""
main_dir_return_value = [] dir_side_effect: dict[str, list] = {}
sub_dir_side_effect = [] read_side_effect: dict[str, list] = {}
main_read_side_effect = []
sub_read_side_effect = [] # Setup directory listing
dir_side_effect["/"] = [[f"/{device_id}/" for device_id in device_ids]]
for device_id in device_ids: for device_id in device_ids:
_setup_owproxy_mock_device( _setup_owproxy_mock_device(dir_side_effect, read_side_effect, device_id)
main_dir_return_value,
sub_dir_side_effect,
main_read_side_effect,
sub_read_side_effect,
device_id,
platform,
)
# Ensure enough read side effect def _dir(path: str) -> Any:
dir_side_effect = [main_dir_return_value, *sub_dir_side_effect] if (side_effect := dir_side_effect.get(path)) is None:
read_side_effect = ( raise NotImplementedError(f"Unexpected _dir call: {path}")
main_read_side_effect result = side_effect.pop(0)
+ sub_read_side_effect if (
+ [ProtocolError("Missing injected value")] * 20 isinstance(result, Exception)
) or isinstance(result, type)
owproxy.return_value.dir.side_effect = dir_side_effect and issubclass(result, Exception)
owproxy.return_value.read.side_effect = read_side_effect ):
raise result
return result
def _read(path: str) -> Any:
if (side_effect := read_side_effect.get(path)) is None:
raise NotImplementedError(f"Unexpected _read call: {path}")
if len(side_effect) == 0:
raise ProtocolError(f"Missing injected value for: {path}")
result = side_effect.pop(0)
if (
isinstance(result, Exception)
or isinstance(result, type)
and issubclass(result, Exception)
):
raise result
return result
owproxy.return_value.dir.side_effect = _dir
owproxy.return_value.read.side_effect = _read
def _setup_owproxy_mock_device( def _setup_owproxy_mock_device(
main_dir_return_value: list, dir_side_effect: dict[str, list], read_side_effect: dict[str, list], device_id: str
sub_dir_side_effect: list,
main_read_side_effect: list,
sub_read_side_effect: list,
device_id: str,
platform: Platform,
) -> None: ) -> None:
"""Set up mock for owproxy.""" """Set up mock for owproxy."""
mock_device = MOCK_OWPROXY_DEVICES[device_id] mock_device = MOCK_OWPROXY_DEVICES[device_id]
# Setup directory listing
main_dir_return_value += [f"/{device_id}/"]
if "branches" in mock_device: if "branches" in mock_device:
# Setup branch directory listing # Setup branch directory listing
for branch, branch_details in mock_device["branches"].items(): for branch, branch_details in mock_device["branches"].items():
sub_dir_side_effect = dir_side_effect.setdefault(
f"/{device_id}/{branch}", []
)
sub_dir_side_effect.append( sub_dir_side_effect.append(
[ # dir on branch [ # dir on branch
f"/{device_id}/{branch}/{sub_device_id}/" f"/{device_id}/{branch}/{sub_device_id}/"
@ -65,46 +70,31 @@ def _setup_owproxy_mock_device(
] ]
) )
_setup_owproxy_mock_device_reads( _setup_owproxy_mock_device_reads(read_side_effect, mock_device, "/", device_id)
main_read_side_effect,
sub_read_side_effect,
mock_device,
device_id,
platform,
)
if "branches" in mock_device: if "branches" in mock_device:
for branch_details in mock_device["branches"].values(): for branch, branch_details in mock_device["branches"].items():
for sub_device_id, sub_device in branch_details.items(): for sub_device_id, sub_device in branch_details.items():
_setup_owproxy_mock_device_reads( _setup_owproxy_mock_device_reads(
main_read_side_effect, read_side_effect,
sub_read_side_effect,
sub_device, sub_device,
f"/{device_id}/{branch}/",
sub_device_id, sub_device_id,
platform,
) )
def _setup_owproxy_mock_device_reads( def _setup_owproxy_mock_device_reads(
main_read_side_effect: list, read_side_effect: dict[str, list], mock_device: Any, root_path: str, device_id: str
sub_read_side_effect: list,
mock_device: Any,
device_id: str,
platform: Platform,
) -> None: ) -> None:
"""Set up mock for owproxy.""" """Set up mock for owproxy."""
# Setup device reads # Setup device reads
main_read_side_effect += [device_id[0:2].encode()] family_read_side_effect = read_side_effect.setdefault(
f"{root_path}{device_id}/family", []
)
family_read_side_effect += [device_id[0:2].encode()]
if ATTR_INJECT_READS in mock_device: if ATTR_INJECT_READS in mock_device:
main_read_side_effect += mock_device[ATTR_INJECT_READS] for k, v in mock_device[ATTR_INJECT_READS].items():
device_read_side_effect = read_side_effect.setdefault(
# Setup sub-device reads f"{root_path}{device_id}{k}", []
device_sensors = mock_device.get(platform, [])
if platform is Platform.SENSOR and device_id.startswith("12"):
# We need to check if there is TAI8570 plugged in
sub_read_side_effect.extend(
expected_sensor[ATTR_INJECT_READS] for expected_sensor in device_sensors
)
sub_read_side_effect.extend(
expected_sensor[ATTR_INJECT_READS] for expected_sensor in device_sensors
) )
device_read_side_effect += v

View File

@ -2,333 +2,242 @@
from pyownet.protocol import ProtocolError from pyownet.protocol import ProtocolError
from homeassistant.components.onewire.const import Platform
ATTR_DEVICE_FILE = "device_file"
ATTR_INJECT_READS = "inject_reads" ATTR_INJECT_READS = "inject_reads"
MOCK_OWPROXY_DEVICES = { MOCK_OWPROXY_DEVICES = {
"00.111111111111": { "00.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"", # read device type "/type": [b""],
], },
}, },
"05.111111111111": { "05.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS2405", # read device type "/type": [b"DS2405"],
], "/PIO": [b" 1"],
Platform.SWITCH: [ },
{ATTR_INJECT_READS: b" 1"},
],
}, },
"10.111111111111": { "10.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS18S20", # read device type "/type": [b"DS18S20"],
], "/temperature": [b" 25.123"],
Platform.SENSOR: [ },
{ATTR_INJECT_READS: b" 25.123"},
],
}, },
"12.111111111111": { "12.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS2406", # read device type "/type": [b"DS2406"],
], # TAI8570 values are read twice:
Platform.BINARY_SENSOR: [ # - once during init to make sure TAI8570 is accessible
{ATTR_INJECT_READS: b" 1"}, # - once during first update to get the actual values
{ATTR_INJECT_READS: b" 0"}, "/TAI8570/temperature": [b" 25.123", b" 25.123"],
], "/TAI8570/pressure": [b" 1025.123", b" 1025.123"],
Platform.SENSOR: [ "/PIO.A": [b" 1"],
{ATTR_INJECT_READS: b" 25.123"}, "/PIO.B": [b" 0"],
{ATTR_INJECT_READS: b" 1025.123"}, "/latch.A": [b" 1"],
], "/latch.B": [b" 0"],
Platform.SWITCH: [ "/sensed.A": [b" 1"],
{ATTR_INJECT_READS: b" 1"}, "/sensed.B": [b" 0"],
{ATTR_INJECT_READS: b" 0"}, },
{ATTR_INJECT_READS: b" 1"},
{ATTR_INJECT_READS: b" 0"},
],
}, },
"1D.111111111111": { "1D.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS2423", # read device type "/type": [b"DS2423"],
], "/counter.A": [b" 251123"],
Platform.SENSOR: [ "/counter.B": [b" 248125"],
{ATTR_INJECT_READS: b" 251123"}, }
{ATTR_INJECT_READS: b" 248125"},
],
}, },
"16.111111111111": { "16.111111111111": {
# Test case for issue #115984, where the device type cannot be read # Test case for issue #115984, where the device type cannot be read
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {"/type": [ProtocolError()]},
ProtocolError(), # read device type
],
}, },
"1F.111111111111": { "1F.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {"/type": [b"DS2409"]},
b"DS2409", # read device type
],
"branches": { "branches": {
"aux": {}, "aux": {},
"main": { "main": {
"1D.111111111111": { "1D.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS2423", # read device type "/type": [b"DS2423"],
], "/counter.A": [b" 251123"],
Platform.SENSOR: [ "/counter.B": [b" 248125"],
{
ATTR_DEVICE_FILE: "/1F.111111111111/main/1D.111111111111/counter.A",
ATTR_INJECT_READS: b" 251123",
}, },
{
ATTR_DEVICE_FILE: "/1F.111111111111/main/1D.111111111111/counter.B",
ATTR_INJECT_READS: b" 248125",
},
],
}, },
}, },
}, },
}, },
"22.111111111111": { "22.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS1822", # read device type "/type": [b"DS1822"],
], "/temperature": [ProtocolError],
Platform.SENSOR: [
{
ATTR_INJECT_READS: ProtocolError,
}, },
],
}, },
"26.111111111111": { "26.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS2438", # read device type "/type": [b"DS2438"],
], "/temperature": [b" 25.123"],
Platform.SENSOR: [ "/humidity": [b" 72.7563"],
{ATTR_INJECT_READS: b" 25.123"}, "/HIH3600/humidity": [b" 73.7563"],
{ATTR_INJECT_READS: b" 72.7563"}, "/HIH4000/humidity": [b" 74.7563"],
{ATTR_INJECT_READS: b" 73.7563"}, "/HIH5030/humidity": [b" 75.7563"],
{ATTR_INJECT_READS: b" 74.7563"}, "/HTM1735/humidity": [ProtocolError],
{ATTR_INJECT_READS: b" 75.7563"}, "/B1-R1-A/pressure": [b" 969.265"],
{ "/S3-R1-A/illuminance": [b" 65.8839"],
ATTR_INJECT_READS: ProtocolError, "/VAD": [b" 2.97"],
"/VDD": [b" 4.74"],
"/vis": [b" 0.12"],
"/IAD": [b" 1"],
}, },
{ATTR_INJECT_READS: b" 969.265"},
{ATTR_INJECT_READS: b" 65.8839"},
{ATTR_INJECT_READS: b" 2.97"},
{ATTR_INJECT_READS: b" 4.74"},
{ATTR_INJECT_READS: b" 0.12"},
],
Platform.SWITCH: [
{ATTR_INJECT_READS: b" 1"},
],
}, },
"28.111111111111": { "28.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS18B20", # read device type "/type": [b"DS18B20"],
], "/temperature": [b" 26.984"],
Platform.SENSOR: [ },
{ATTR_INJECT_READS: b" 26.984"},
],
}, },
"28.222222222222": { "28.222222222222": {
# This device has precision options in the config entry # This device has precision options in the config entry
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS18B20", # read device type "/type": [b"DS18B20"],
], "/temperature9": [b" 26.984"],
Platform.SENSOR: [
{
ATTR_DEVICE_FILE: "/28.222222222222/temperature9",
ATTR_INJECT_READS: b" 26.984",
}, },
],
}, },
"28.222222222223": { "28.222222222223": {
# This device has an illegal precision option in the config entry # This device has an illegal precision option in the config entry
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS18B20", # read device type "/type": [b"DS18B20"],
], "/temperature": [b" 26.984"],
Platform.SENSOR: [
{
ATTR_DEVICE_FILE: "/28.222222222223/temperature",
ATTR_INJECT_READS: b" 26.984",
}, },
],
}, },
"29.111111111111": { "29.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS2408", # read device type "/type": [b"DS2408"],
], "/PIO.0": [b" 1"],
Platform.BINARY_SENSOR: [ "/PIO.1": [b" 0"],
{ATTR_INJECT_READS: b" 1"}, "/PIO.2": [b" 1"],
{ATTR_INJECT_READS: b" 0"}, "/PIO.3": [ProtocolError],
{ATTR_INJECT_READS: b" 0"}, "/PIO.4": [b" 1"],
{ "/PIO.5": [b" 0"],
ATTR_INJECT_READS: ProtocolError, "/PIO.6": [b" 1"],
"/PIO.7": [b" 0"],
"/latch.0": [b" 1"],
"/latch.1": [b" 0"],
"/latch.2": [b" 1"],
"/latch.3": [b" 0"],
"/latch.4": [b" 1"],
"/latch.5": [b" 0"],
"/latch.6": [b" 1"],
"/latch.7": [b" 0"],
"/sensed.0": [b" 1"],
"/sensed.1": [b" 0"],
"/sensed.2": [b" 0"],
"/sensed.3": [ProtocolError],
"/sensed.4": [b" 0"],
"/sensed.5": [b" 0"],
"/sensed.6": [b" 0"],
"/sensed.7": [b" 0"],
}, },
{ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 0"},
],
Platform.SWITCH: [
{ATTR_INJECT_READS: b" 1"},
{ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 1"},
{
ATTR_INJECT_READS: ProtocolError,
},
{ATTR_INJECT_READS: b" 1"},
{ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 1"},
{ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 1"},
{ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 1"},
{ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 1"},
{ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 1"},
{ATTR_INJECT_READS: b" 0"},
],
}, },
"30.111111111111": { "30.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS2760", # read device type "/type": [b"DS2760"],
], "/temperature": [b" 26.984"],
Platform.SENSOR: [ "/typeK/temperature": [b" 173.7563"],
{ATTR_INJECT_READS: b" 26.984"}, "/volt": [b" 2.97"],
{ "/vis": [b" 0.12"],
ATTR_DEVICE_FILE: "/30.111111111111/typeK/temperature",
ATTR_INJECT_READS: b" 173.7563",
}, },
{ATTR_INJECT_READS: b" 2.97"},
{ATTR_INJECT_READS: b" 0.12"},
],
}, },
"3A.111111111111": { "3A.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS2413", # read device type "/type": [b"DS2413"],
], "/PIO.A": [b" 1"],
Platform.BINARY_SENSOR: [ "/PIO.B": [b" 0"],
{ATTR_INJECT_READS: b" 1"}, "/sensed.A": [b" 1"],
{ATTR_INJECT_READS: b" 0"}, "/sensed.B": [b" 0"],
], },
Platform.SWITCH: [
{ATTR_INJECT_READS: b" 1"},
{ATTR_INJECT_READS: b" 0"},
],
}, },
"3B.111111111111": { "3B.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS1825", # read device type "/type": [b"DS1825"],
], "/temperature": [b" 28.243"],
Platform.SENSOR: [ },
{ATTR_INJECT_READS: b" 28.243"},
],
}, },
"42.111111111111": { "42.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS28EA00", # read device type "/type": [b"DS28EA00"],
], "/temperature": [b" 29.123"],
Platform.SENSOR: [ },
{ATTR_INJECT_READS: b" 29.123"},
],
}, },
"A6.111111111111": { "A6.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"DS2438", # read device type "/type": [b"DS2438"],
], "/temperature": [b" 25.123"],
Platform.SENSOR: [ "/humidity": [b" 72.7563"],
{ATTR_INJECT_READS: b" 25.123"}, "/HIH3600/humidity": [b" 73.7563"],
{ATTR_INJECT_READS: b" 72.7563"}, "/HIH4000/humidity": [b" 74.7563"],
{ATTR_INJECT_READS: b" 73.7563"}, "/HIH5030/humidity": [b" 75.7563"],
{ATTR_INJECT_READS: b" 74.7563"}, "/HTM1735/humidity": [ProtocolError],
{ATTR_INJECT_READS: b" 75.7563"}, "/B1-R1-A/pressure": [b" 969.265"],
{ "/S3-R1-A/illuminance": [b" 65.8839"],
ATTR_INJECT_READS: ProtocolError, "/VAD": [b" 2.97"],
"/VDD": [b" 4.74"],
"/vis": [b" 0.12"],
"/IAD": [b" 1"],
}, },
{ATTR_INJECT_READS: b" 969.265"},
{ATTR_INJECT_READS: b" 65.8839"},
{ATTR_INJECT_READS: b" 2.97"},
{ATTR_INJECT_READS: b" 4.74"},
{ATTR_INJECT_READS: b" 0.12"},
],
Platform.SWITCH: [
{ATTR_INJECT_READS: b" 1"},
],
}, },
"EF.111111111111": { "EF.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"HobbyBoards_EF", # read type "/type": [b"HobbyBoards_EF"],
], "/humidity/humidity_corrected": [b" 67.745"],
Platform.SENSOR: [ "/humidity/humidity_raw": [b" 65.541"],
{ATTR_INJECT_READS: b" 67.745"}, "/humidity/temperature": [b" 25.123"],
{ATTR_INJECT_READS: b" 65.541"}, },
{ATTR_INJECT_READS: b" 25.123"},
],
}, },
"EF.111111111112": { "EF.111111111112": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"HB_MOISTURE_METER", # read type "/type": [b"HB_MOISTURE_METER"],
b" 1", # read is_leaf_0 "/moisture/is_leaf.0": [b" 1"],
b" 1", # read is_leaf_1 "/moisture/is_leaf.1": [b" 1"],
b" 0", # read is_leaf_2 "/moisture/is_leaf.2": [b" 0"],
b" 0", # read is_leaf_3 "/moisture/is_leaf.3": [b" 0"],
], "/moisture/sensor.0": [b" 41.745"],
Platform.SENSOR: [ "/moisture/sensor.1": [b" 42.541"],
{ATTR_INJECT_READS: b" 41.745"}, "/moisture/sensor.2": [b" 43.123"],
{ATTR_INJECT_READS: b" 42.541"}, "/moisture/sensor.3": [b" 44.123"],
{ATTR_INJECT_READS: b" 43.123"}, "/moisture/is_moisture.0": [b" 1"],
{ATTR_INJECT_READS: b" 44.123"}, "/moisture/is_moisture.1": [b" 1"],
], "/moisture/is_moisture.2": [b" 0"],
Platform.SWITCH: [ "/moisture/is_moisture.3": [b" 0"],
{ATTR_INJECT_READS: b"1"}, },
{ATTR_INJECT_READS: b"1"},
{ATTR_INJECT_READS: b"0"},
{ATTR_INJECT_READS: b"0"},
{ATTR_INJECT_READS: b"1"},
{ATTR_INJECT_READS: b"1"},
{ATTR_INJECT_READS: b"0"},
{ATTR_INJECT_READS: b"0"},
],
}, },
"EF.111111111113": { "EF.111111111113": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"HB_HUB", # read type "/type": [b"HB_HUB"],
], "/hub/branch.0": [b" 1"],
Platform.BINARY_SENSOR: [ "/hub/branch.1": [b" 0"],
{ATTR_INJECT_READS: b"1"}, "/hub/branch.2": [b" 1"],
{ATTR_INJECT_READS: b"0"}, "/hub/branch.3": [b" 0"],
{ATTR_INJECT_READS: b"1"}, "/hub/short.0": [b" 1"],
{ATTR_INJECT_READS: b"0"}, "/hub/short.1": [b" 0"],
], "/hub/short.2": [b" 1"],
Platform.SWITCH: [ "/hub/short.3": [b" 0"],
{ATTR_INJECT_READS: b"1"}, },
{ATTR_INJECT_READS: b"0"},
{ATTR_INJECT_READS: b"1"},
{ATTR_INJECT_READS: b"0"},
],
}, },
"7E.111111111111": { "7E.111111111111": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"EDS", # read type "/type": [b"EDS"],
b"EDS0068", # read device_type - note EDS specific "/device_type": [b"EDS0068"],
], "/EDS0068/temperature": [b" 13.9375"],
Platform.SENSOR: [ "/EDS0068/pressure": [b" 1012.21"],
{ATTR_INJECT_READS: b" 13.9375"}, "/EDS0068/light": [b" 65.8839"],
{ATTR_INJECT_READS: b" 1012.21"}, "/EDS0068/humidity": [b" 41.375"],
{ATTR_INJECT_READS: b" 65.8839"}, },
{ATTR_INJECT_READS: b" 41.375"},
],
}, },
"7E.222222222222": { "7E.222222222222": {
ATTR_INJECT_READS: [ ATTR_INJECT_READS: {
b"EDS", # read type "/type": [b"EDS"],
b"EDS0066", # read device_type - note EDS specific "/device_type": [b"EDS0066"],
], "/EDS0066/temperature": [b" 13.9375"],
Platform.SENSOR: [ "/EDS0066/pressure": [b" 1012.21"],
{ATTR_INJECT_READS: b" 13.9375"}, },
{ATTR_INJECT_READS: b" 1012.21"},
],
}, },
} }

View File

@ -32,7 +32,7 @@ async def test_binary_sensors(
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test for 1-Wire binary sensors.""" """Test for 1-Wire binary sensors."""
setup_owproxy_mock_devices(owproxy, Platform.BINARY_SENSOR, [device_id]) setup_owproxy_mock_devices(owproxy, [device_id])
await hass.config_entries.async_setup(config_entry.entry_id) await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -48,7 +48,7 @@ async def test_binary_sensors(
) )
assert entity_entries == snapshot assert entity_entries == snapshot
setup_owproxy_mock_devices(owproxy, Platform.BINARY_SENSOR, [device_id]) setup_owproxy_mock_devices(owproxy, [device_id])
# Some entities are disabled, enable them and reload before checking states # Some entities are disabled, enable them and reload before checking states
for ent in entity_entries: for ent in entity_entries:
entity_registry.async_update_entity(ent.entity_id, disabled_by=None) entity_registry.async_update_entity(ent.entity_id, disabled_by=None)

View File

@ -47,7 +47,7 @@ async def test_entry_diagnostics(
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test config entry diagnostics.""" """Test config entry diagnostics."""
setup_owproxy_mock_devices(owproxy, Platform.SENSOR, [device_id]) setup_owproxy_mock_devices(owproxy, [device_id])
await hass.config_entries.async_setup(config_entry.entry_id) await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()

View File

@ -96,12 +96,12 @@ async def test_registry_cleanup(
dead_id = "28.111111111111" dead_id = "28.111111111111"
# Initialise with two components # Initialise with two components
setup_owproxy_mock_devices(owproxy, Platform.SENSOR, [live_id, dead_id]) setup_owproxy_mock_devices(owproxy, [live_id, dead_id])
await hass.config_entries.async_setup(entry_id) await hass.config_entries.async_setup(entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
# Reload with a device no longer on bus # Reload with a device no longer on bus
setup_owproxy_mock_devices(owproxy, Platform.SENSOR, [live_id]) setup_owproxy_mock_devices(owproxy, [live_id])
await hass.config_entries.async_reload(entry_id) await hass.config_entries.async_reload(entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(dr.async_entries_for_config_entry(device_registry, entry_id)) == 2 assert len(dr.async_entries_for_config_entry(device_registry, entry_id)) == 2

View File

@ -36,7 +36,7 @@ async def test_sensors(
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test for 1-Wire sensors.""" """Test for 1-Wire sensors."""
setup_owproxy_mock_devices(owproxy, Platform.SENSOR, [device_id]) setup_owproxy_mock_devices(owproxy, [device_id])
await hass.config_entries.async_setup(config_entry.entry_id) await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -52,7 +52,7 @@ async def test_sensors(
) )
assert entity_entries == snapshot assert entity_entries == snapshot
setup_owproxy_mock_devices(owproxy, Platform.SENSOR, [device_id]) setup_owproxy_mock_devices(owproxy, [device_id])
# Some entities are disabled, enable them and reload before checking states # Some entities are disabled, enable them and reload before checking states
for ent in entity_entries: for ent in entity_entries:
entity_registry.async_update_entity(ent.entity_id, disabled_by=None) entity_registry.async_update_entity(ent.entity_id, disabled_by=None)
@ -79,11 +79,11 @@ async def test_tai8570_sensors(
""" """
mock_devices = deepcopy(MOCK_OWPROXY_DEVICES) mock_devices = deepcopy(MOCK_OWPROXY_DEVICES)
mock_device = mock_devices[device_id] mock_device = mock_devices[device_id]
mock_device[ATTR_INJECT_READS].append(OwnetError) mock_device[ATTR_INJECT_READS]["/TAI8570/temperature"] = [OwnetError]
mock_device[ATTR_INJECT_READS].append(OwnetError) mock_device[ATTR_INJECT_READS]["/TAI8570/pressure"] = [OwnetError]
with _patch_dict(MOCK_OWPROXY_DEVICES, mock_devices): with _patch_dict(MOCK_OWPROXY_DEVICES, mock_devices):
setup_owproxy_mock_devices(owproxy, Platform.SENSOR, [device_id]) setup_owproxy_mock_devices(owproxy, [device_id])
with caplog.at_level(logging.DEBUG): with caplog.at_level(logging.DEBUG):
await hass.config_entries.async_setup(config_entry.entry_id) await hass.config_entries.async_setup(config_entry.entry_id)

View File

@ -39,7 +39,7 @@ async def test_switches(
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test for 1-Wire switches.""" """Test for 1-Wire switches."""
setup_owproxy_mock_devices(owproxy, Platform.SWITCH, [device_id]) setup_owproxy_mock_devices(owproxy, [device_id])
await hass.config_entries.async_setup(config_entry.entry_id) await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -55,7 +55,7 @@ async def test_switches(
) )
assert entity_entries == snapshot assert entity_entries == snapshot
setup_owproxy_mock_devices(owproxy, Platform.SWITCH, [device_id]) setup_owproxy_mock_devices(owproxy, [device_id])
# Some entities are disabled, enable them and reload before checking states # Some entities are disabled, enable them and reload before checking states
for ent in entity_entries: for ent in entity_entries:
entity_registry.async_update_entity(ent.entity_id, disabled_by=None) entity_registry.async_update_entity(ent.entity_id, disabled_by=None)
@ -76,7 +76,7 @@ async def test_switch_toggle(
device_id: str, device_id: str,
) -> None: ) -> None:
"""Test for 1-Wire switch TOGGLE service.""" """Test for 1-Wire switch TOGGLE service."""
setup_owproxy_mock_devices(owproxy, Platform.SWITCH, [device_id]) setup_owproxy_mock_devices(owproxy, [device_id])
await hass.config_entries.async_setup(config_entry.entry_id) await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()