Add onewire test for more devices (#42037)
* Add tests for device families 12 and 26 * Update patch import to tests.async_mockpull/42308/head
parent
0c852b5f81
commit
2787a52ef7
|
@ -1,6 +1,4 @@
|
|||
"""Tests for 1-Wire devices connected on OWServer."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from pyownet.protocol import Error as ProtocolError
|
||||
import pytest
|
||||
|
||||
|
@ -10,9 +8,17 @@ from homeassistant.components.onewire.const import (
|
|||
PRESSURE_CBAR,
|
||||
)
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
|
||||
from homeassistant.const import (
|
||||
ELECTRICAL_CURRENT_AMPERE,
|
||||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
PRESSURE_MBAR,
|
||||
TEMP_CELSIUS,
|
||||
VOLT,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import mock_registry
|
||||
|
||||
MOCK_CONFIG = {
|
||||
|
@ -39,6 +45,24 @@ MOCK_DEVICE_SENSORS = {
|
|||
},
|
||||
]
|
||||
},
|
||||
"12.111111111111": {
|
||||
"sensors": [
|
||||
{
|
||||
"entity_id": "sensor.12_111111111111_temperature",
|
||||
"unique_id": "/12.111111111111/TAI8570/temperature",
|
||||
"injected_value": b" 25.123",
|
||||
"result": "25.1",
|
||||
"unit": TEMP_CELSIUS,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.12_111111111111_pressure",
|
||||
"unique_id": "/12.111111111111/TAI8570/pressure",
|
||||
"injected_value": b" 1025.123",
|
||||
"result": "1025.1",
|
||||
"unit": PRESSURE_MBAR,
|
||||
},
|
||||
]
|
||||
},
|
||||
"1D.111111111111": {
|
||||
"sensors": [
|
||||
{
|
||||
|
@ -68,6 +92,87 @@ MOCK_DEVICE_SENSORS = {
|
|||
},
|
||||
]
|
||||
},
|
||||
"26.111111111111": {
|
||||
"sensors": [
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_temperature",
|
||||
"unique_id": "/26.111111111111/temperature",
|
||||
"injected_value": b" 25.123",
|
||||
"result": "25.1",
|
||||
"unit": TEMP_CELSIUS,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_humidity",
|
||||
"unique_id": "/26.111111111111/humidity",
|
||||
"injected_value": b" 72.7563",
|
||||
"result": "72.8",
|
||||
"unit": PERCENTAGE,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_humidity_hih3600",
|
||||
"unique_id": "/26.111111111111/HIH3600/humidity",
|
||||
"injected_value": b" 73.7563",
|
||||
"result": "73.8",
|
||||
"unit": PERCENTAGE,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_humidity_hih4000",
|
||||
"unique_id": "/26.111111111111/HIH4000/humidity",
|
||||
"injected_value": b" 74.7563",
|
||||
"result": "74.8",
|
||||
"unit": PERCENTAGE,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_humidity_hih5030",
|
||||
"unique_id": "/26.111111111111/HIH5030/humidity",
|
||||
"injected_value": b" 75.7563",
|
||||
"result": "75.8",
|
||||
"unit": PERCENTAGE,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_humidity_htm1735",
|
||||
"unique_id": "/26.111111111111/HTM1735/humidity",
|
||||
"injected_value": ProtocolError,
|
||||
"result": "unknown",
|
||||
"unit": PERCENTAGE,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_pressure",
|
||||
"unique_id": "/26.111111111111/B1-R1-A/pressure",
|
||||
"injected_value": b" 969.265",
|
||||
"result": "969.3",
|
||||
"unit": PRESSURE_MBAR,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_illuminance",
|
||||
"unique_id": "/26.111111111111/S3-R1-A/illuminance",
|
||||
"injected_value": b" 65.8839",
|
||||
"result": "65.9",
|
||||
"unit": LIGHT_LUX,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_voltage_vad",
|
||||
"unique_id": "/26.111111111111/VAD",
|
||||
"injected_value": b" 2.97",
|
||||
"result": "3.0",
|
||||
"unit": VOLT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_voltage_vdd",
|
||||
"unique_id": "/26.111111111111/VDD",
|
||||
"injected_value": b" 4.74",
|
||||
"result": "4.7",
|
||||
"unit": VOLT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_current",
|
||||
"unique_id": "/26.111111111111/IAD",
|
||||
"injected_value": b" 1",
|
||||
"result": "1.0",
|
||||
"unit": ELECTRICAL_CURRENT_AMPERE,
|
||||
},
|
||||
]
|
||||
},
|
||||
"28.111111111111": {
|
||||
"sensors": [
|
||||
{
|
||||
|
@ -185,6 +290,9 @@ async def test_owserver_setup_valid_device(hass, device_id):
|
|||
for expected_sensor in expected_sensors:
|
||||
read_side_effect.append(expected_sensor["injected_value"])
|
||||
|
||||
# Ensure enough read side effect
|
||||
read_side_effect.extend([ProtocolError("Missing injected value")] * 10)
|
||||
|
||||
with patch("homeassistant.components.onewire.sensor.protocol.proxy") as owproxy:
|
||||
owproxy.return_value.dir.return_value = dir_return_value
|
||||
owproxy.return_value.read.side_effect = read_side_effect
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""Tests for 1-Wire devices connected on SysBus."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from pi1wire import InvalidCRCException, UnsupportResponseException
|
||||
import pytest
|
||||
|
||||
|
@ -9,6 +7,7 @@ from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
|||
from homeassistant.const import TEMP_CELSIUS
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import mock_registry
|
||||
|
||||
MOCK_CONFIG = {
|
||||
|
@ -34,6 +33,7 @@ MOCK_DEVICE_SENSORS = {
|
|||
},
|
||||
]
|
||||
},
|
||||
"12-111111111111": {"sensors": []},
|
||||
"1D-111111111111": {"sensors": []},
|
||||
"22-111111111111": {
|
||||
"sensors": [
|
||||
|
@ -46,6 +46,7 @@ MOCK_DEVICE_SENSORS = {
|
|||
},
|
||||
]
|
||||
},
|
||||
"26-111111111111": {"sensors": []},
|
||||
"28-111111111111": {
|
||||
"sensors": [
|
||||
{
|
||||
|
@ -99,6 +100,9 @@ async def test_onewiredirect_setup_valid_device(hass, device_id):
|
|||
for expected_sensor in expected_sensors:
|
||||
read_side_effect.append(expected_sensor["injected_value"])
|
||||
|
||||
# Ensure enough read side effect
|
||||
read_side_effect.extend([FileNotFoundError("Missing injected value")] * 20)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.onewire.sensor.os.path.isdir", return_value=True
|
||||
), patch("pi1wire._finder.glob.glob", return_value=glob_result,), patch(
|
||||
|
|
Loading…
Reference in New Issue