Ignore TAI8570 errors in onewire (#87154)
parent
5422ef239b
commit
783e6fdd36
|
@ -9,6 +9,8 @@ import os
|
||||||
from types import MappingProxyType
|
from types import MappingProxyType
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from pyownet import protocol
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
|
@ -419,6 +421,17 @@ def get_entities(
|
||||||
override_key or description.key,
|
override_key or description.key,
|
||||||
)
|
)
|
||||||
name = f"{device_id} {description.name}"
|
name = f"{device_id} {description.name}"
|
||||||
|
if family == "12":
|
||||||
|
# We need to check if there is TAI8570 plugged in
|
||||||
|
try:
|
||||||
|
onewire_hub.owproxy.read(device_file)
|
||||||
|
except protocol.OwnetError as err:
|
||||||
|
_LOGGER.debug(
|
||||||
|
"Ignoring unreachable sensor %s",
|
||||||
|
device_file,
|
||||||
|
exc_info=err,
|
||||||
|
)
|
||||||
|
continue
|
||||||
entities.append(
|
entities.append(
|
||||||
OneWireSensor(
|
OneWireSensor(
|
||||||
description=description,
|
description=description,
|
||||||
|
|
|
@ -178,5 +178,9 @@ def _setup_owproxy_mock_device_reads(
|
||||||
|
|
||||||
# Setup sub-device reads
|
# Setup sub-device reads
|
||||||
device_sensors = mock_device.get(platform, [])
|
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
|
||||||
|
for expected_sensor in device_sensors:
|
||||||
|
sub_read_side_effect.append(expected_sensor[ATTR_INJECT_READS])
|
||||||
for expected_sensor in device_sensors:
|
for expected_sensor in device_sensors:
|
||||||
sub_read_side_effect.append(expected_sensor[ATTR_INJECT_READS])
|
sub_read_side_effect.append(expected_sensor[ATTR_INJECT_READS])
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
"""Tests for 1-Wire sensors."""
|
"""Tests for 1-Wire sensors."""
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
|
from copy import deepcopy
|
||||||
import logging
|
import logging
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, _patch_dict, patch
|
||||||
|
|
||||||
|
from pyownet.protocol import OwnetError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.config_validation import ensure_list
|
from homeassistant.helpers.config_validation import ensure_list
|
||||||
|
|
||||||
|
@ -16,7 +18,12 @@ from . import (
|
||||||
check_entities,
|
check_entities,
|
||||||
setup_owproxy_mock_devices,
|
setup_owproxy_mock_devices,
|
||||||
)
|
)
|
||||||
from .const import ATTR_DEVICE_INFO, ATTR_UNKNOWN_DEVICE, MOCK_OWPROXY_DEVICES
|
from .const import (
|
||||||
|
ATTR_DEVICE_INFO,
|
||||||
|
ATTR_INJECT_READS,
|
||||||
|
ATTR_UNKNOWN_DEVICE,
|
||||||
|
MOCK_OWPROXY_DEVICES,
|
||||||
|
)
|
||||||
|
|
||||||
from tests.common import mock_device_registry, mock_registry
|
from tests.common import mock_device_registry, mock_registry
|
||||||
|
|
||||||
|
@ -68,3 +75,31 @@ async def test_sensors(
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
check_entities(hass, entity_registry, expected_entities)
|
check_entities(hass, entity_registry, expected_entities)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("device_id", ["12.111111111111"])
|
||||||
|
async def test_tai8570_sensors(
|
||||||
|
hass: HomeAssistant, config_entry: ConfigEntry, owproxy: MagicMock, device_id: str
|
||||||
|
) -> None:
|
||||||
|
"""The DS2602 is often used without TAI8570.
|
||||||
|
|
||||||
|
The sensors should be ignored.
|
||||||
|
"""
|
||||||
|
entity_registry = mock_registry(hass)
|
||||||
|
|
||||||
|
mock_devices = deepcopy(MOCK_OWPROXY_DEVICES)
|
||||||
|
mock_device = mock_devices[device_id]
|
||||||
|
mock_device[ATTR_INJECT_READS].append(OwnetError)
|
||||||
|
mock_device[ATTR_INJECT_READS].append(OwnetError)
|
||||||
|
|
||||||
|
with _patch_dict(MOCK_OWPROXY_DEVICES, mock_devices):
|
||||||
|
setup_owproxy_mock_devices(owproxy, Platform.SENSOR, [device_id])
|
||||||
|
|
||||||
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
expected_entities = mock_device[Platform.SENSOR]
|
||||||
|
for expected_entity in expected_entities:
|
||||||
|
entity_id = expected_entity[ATTR_ENTITY_ID]
|
||||||
|
registry_entry = entity_registry.entities.get(entity_id)
|
||||||
|
assert registry_entry is None
|
||||||
|
|
Loading…
Reference in New Issue