mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Improve multi-device test coverage for greeneye_monitor (#63657)
This commit is contained in:
parent
15f1a850ba
commit
6c6607b5be
@ -128,6 +128,35 @@ SINGLE_MONITOR_CONFIG_VOLTAGE_SENSORS = make_single_monitor_config_with_sensors(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MULTI_MONITOR_CONFIG = {
|
||||||
|
DOMAIN: {
|
||||||
|
CONF_PORT: 7513,
|
||||||
|
CONF_MONITORS: [
|
||||||
|
{
|
||||||
|
CONF_SERIAL_NUMBER: "00000001",
|
||||||
|
CONF_TEMPERATURE_SENSORS: {
|
||||||
|
CONF_TEMPERATURE_UNIT: "C",
|
||||||
|
CONF_SENSORS: [{CONF_NUMBER: 1, CONF_NAME: "unit_1_temp_1"}],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
CONF_SERIAL_NUMBER: "00000002",
|
||||||
|
CONF_TEMPERATURE_SENSORS: {
|
||||||
|
CONF_TEMPERATURE_UNIT: "F",
|
||||||
|
CONF_SENSORS: [{CONF_NUMBER: 1, CONF_NAME: "unit_2_temp_1"}],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
CONF_SERIAL_NUMBER: "00000003",
|
||||||
|
CONF_TEMPERATURE_SENSORS: {
|
||||||
|
CONF_TEMPERATURE_UNIT: "C",
|
||||||
|
CONF_SENSORS: [{CONF_NUMBER: 1, CONF_NAME: "unit_3_temp_1"}],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def setup_greeneye_monitor_component_with_config(
|
async def setup_greeneye_monitor_component_with_config(
|
||||||
hass: HomeAssistant, config: ConfigType
|
hass: HomeAssistant, config: ConfigType
|
||||||
|
@ -6,23 +6,12 @@ from unittest.mock import AsyncMock
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.greeneye_monitor import (
|
from homeassistant.components.greeneye_monitor import DOMAIN
|
||||||
CONF_MONITORS,
|
|
||||||
CONF_NUMBER,
|
|
||||||
CONF_SERIAL_NUMBER,
|
|
||||||
CONF_TEMPERATURE_SENSORS,
|
|
||||||
DOMAIN,
|
|
||||||
)
|
|
||||||
from homeassistant.const import (
|
|
||||||
CONF_NAME,
|
|
||||||
CONF_PORT,
|
|
||||||
CONF_SENSORS,
|
|
||||||
CONF_TEMPERATURE_UNIT,
|
|
||||||
)
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .common import (
|
from .common import (
|
||||||
|
MULTI_MONITOR_CONFIG,
|
||||||
SINGLE_MONITOR_CONFIG_NO_SENSORS,
|
SINGLE_MONITOR_CONFIG_NO_SENSORS,
|
||||||
SINGLE_MONITOR_CONFIG_POWER_SENSORS,
|
SINGLE_MONITOR_CONFIG_POWER_SENSORS,
|
||||||
SINGLE_MONITOR_CONFIG_PULSE_COUNTERS,
|
SINGLE_MONITOR_CONFIG_PULSE_COUNTERS,
|
||||||
@ -155,35 +144,12 @@ async def test_multi_monitor_config(hass: HomeAssistant, monitors: AsyncMock) ->
|
|||||||
"""Test that component setup registers entities from multiple monitors correctly."""
|
"""Test that component setup registers entities from multiple monitors correctly."""
|
||||||
assert await setup_greeneye_monitor_component_with_config(
|
assert await setup_greeneye_monitor_component_with_config(
|
||||||
hass,
|
hass,
|
||||||
{
|
MULTI_MONITOR_CONFIG,
|
||||||
DOMAIN: {
|
|
||||||
CONF_PORT: 7513,
|
|
||||||
CONF_MONITORS: [
|
|
||||||
{
|
|
||||||
CONF_SERIAL_NUMBER: "00000001",
|
|
||||||
CONF_TEMPERATURE_SENSORS: {
|
|
||||||
CONF_TEMPERATURE_UNIT: "C",
|
|
||||||
CONF_SENSORS: [
|
|
||||||
{CONF_NUMBER: 1, CONF_NAME: "unit_1_temp_1"}
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
CONF_SERIAL_NUMBER: "00000002",
|
|
||||||
CONF_TEMPERATURE_SENSORS: {
|
|
||||||
CONF_TEMPERATURE_UNIT: "F",
|
|
||||||
CONF_SENSORS: [
|
|
||||||
{CONF_NUMBER: 1, CONF_NAME: "unit_2_temp_1"}
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert_temperature_sensor_registered(hass, 1, 1, "unit_1_temp_1")
|
assert_temperature_sensor_registered(hass, 1, 1, "unit_1_temp_1")
|
||||||
assert_temperature_sensor_registered(hass, 2, 1, "unit_2_temp_1")
|
assert_temperature_sensor_registered(hass, 2, 1, "unit_2_temp_1")
|
||||||
|
assert_temperature_sensor_registered(hass, 3, 1, "unit_3_temp_1")
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_and_shutdown(hass: HomeAssistant, monitors: AsyncMock) -> None:
|
async def test_setup_and_shutdown(hass: HomeAssistant, monitors: AsyncMock) -> None:
|
||||||
|
@ -13,6 +13,7 @@ from homeassistant.helpers.entity_registry import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from .common import (
|
from .common import (
|
||||||
|
MULTI_MONITOR_CONFIG,
|
||||||
SINGLE_MONITOR_CONFIG_POWER_SENSORS,
|
SINGLE_MONITOR_CONFIG_POWER_SENSORS,
|
||||||
SINGLE_MONITOR_CONFIG_PULSE_COUNTERS,
|
SINGLE_MONITOR_CONFIG_PULSE_COUNTERS,
|
||||||
SINGLE_MONITOR_CONFIG_TEMPERATURE_SENSORS,
|
SINGLE_MONITOR_CONFIG_TEMPERATURE_SENSORS,
|
||||||
@ -154,6 +155,17 @@ async def test_voltage_sensor(hass: HomeAssistant, monitors: AsyncMock) -> None:
|
|||||||
assert_sensor_state(hass, "sensor.voltage_1", "120.0")
|
assert_sensor_state(hass, "sensor.voltage_1", "120.0")
|
||||||
|
|
||||||
|
|
||||||
|
async def test_multi_monitor_sensors(hass: HomeAssistant, monitors: AsyncMock) -> None:
|
||||||
|
"""Test that sensors still work when multiple monitors are registered."""
|
||||||
|
await setup_greeneye_monitor_component_with_config(hass, MULTI_MONITOR_CONFIG)
|
||||||
|
connect_monitor(monitors, 1)
|
||||||
|
connect_monitor(monitors, 2)
|
||||||
|
connect_monitor(monitors, 3)
|
||||||
|
assert_sensor_state(hass, "sensor.unit_1_temp_1", "32.0")
|
||||||
|
assert_sensor_state(hass, "sensor.unit_2_temp_1", "0.0")
|
||||||
|
assert_sensor_state(hass, "sensor.unit_3_temp_1", "32.0")
|
||||||
|
|
||||||
|
|
||||||
def connect_monitor(monitors: AsyncMock, serial_number: int) -> MagicMock:
|
def connect_monitor(monitors: AsyncMock, serial_number: int) -> MagicMock:
|
||||||
"""Simulate a monitor connecting to Home Assistant. Returns the mock monitor API object."""
|
"""Simulate a monitor connecting to Home Assistant. Returns the mock monitor API object."""
|
||||||
monitor = mock_monitor(serial_number)
|
monitor = mock_monitor(serial_number)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user