mirror of
https://github.com/home-assistant/supervisor.git
synced 2026-05-08 17:08:36 +01:00
@@ -0,0 +1 @@
|
||||
"""Test for Boards D-Bus interfaces."""
|
||||
@@ -0,0 +1,78 @@
|
||||
"""Test Boards manager."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from dbus_fast.aio.message_bus import MessageBus
|
||||
from dbus_fast.aio.proxy_object import ProxyInterface
|
||||
import pytest
|
||||
|
||||
from supervisor.dbus.agent.boards import BoardManager
|
||||
from supervisor.exceptions import BoardInvalidError
|
||||
from supervisor.utils.dbus import DBUS_INTERFACE_PROPERTIES, DBus
|
||||
|
||||
|
||||
@pytest.fixture(name="dbus_mock_board")
|
||||
async def fixture_dbus_mock_board(request: pytest.FixtureRequest, dbus: list[str]):
|
||||
"""Mock Boards dbus object to particular board name for tests."""
|
||||
call_dbus = DBus.call_dbus
|
||||
|
||||
async def mock_call_dbus_specify_board(
|
||||
proxy_interface: ProxyInterface,
|
||||
method: str,
|
||||
*args,
|
||||
unpack_variants: bool = True,
|
||||
):
|
||||
if (
|
||||
proxy_interface.introspection.name == DBUS_INTERFACE_PROPERTIES
|
||||
and method == "call_get_all"
|
||||
and proxy_interface.path == "/io/hass/os/Boards"
|
||||
):
|
||||
return {"Board": request.param}
|
||||
|
||||
return call_dbus(
|
||||
proxy_interface, method, *args, unpack_variants=unpack_variants
|
||||
)
|
||||
|
||||
with patch(
|
||||
"supervisor.utils.dbus.DBus.call_dbus", new=mock_call_dbus_specify_board
|
||||
):
|
||||
yield dbus
|
||||
|
||||
|
||||
async def test_dbus_board(dbus: list[str], dbus_bus: MessageBus):
|
||||
"""Test DBus Board load."""
|
||||
board = BoardManager()
|
||||
await board.connect(dbus_bus)
|
||||
|
||||
assert board.board == "Yellow"
|
||||
assert board.yellow.power_led is True
|
||||
|
||||
with pytest.raises(BoardInvalidError):
|
||||
assert not board.supervised
|
||||
|
||||
|
||||
@pytest.mark.parametrize("dbus_mock_board", ["Supervised"], indirect=True)
|
||||
async def test_dbus_board_supervised(dbus_mock_board: list[str], dbus_bus: MessageBus):
|
||||
"""Test DBus Board load with supervised board."""
|
||||
board = BoardManager()
|
||||
await board.connect(dbus_bus)
|
||||
|
||||
assert board.board == "Supervised"
|
||||
assert board.supervised
|
||||
|
||||
with pytest.raises(BoardInvalidError):
|
||||
assert not board.yellow
|
||||
|
||||
|
||||
@pytest.mark.parametrize("dbus_mock_board", ["NotReal"], indirect=True)
|
||||
async def test_dbus_board_other(dbus_mock_board: list[str], dbus_bus: MessageBus):
|
||||
"""Test DBus Board load with board that has no dbus object."""
|
||||
board = BoardManager()
|
||||
await board.connect(dbus_bus)
|
||||
|
||||
assert board.board == "NotReal"
|
||||
|
||||
with pytest.raises(BoardInvalidError):
|
||||
assert not board.yellow
|
||||
with pytest.raises(BoardInvalidError):
|
||||
assert not board.supervised
|
||||
@@ -0,0 +1,54 @@
|
||||
"""Test Yellow board."""
|
||||
|
||||
import asyncio
|
||||
|
||||
from dbus_fast.aio.message_bus import MessageBus
|
||||
|
||||
from supervisor.dbus.agent.boards.yellow import Yellow
|
||||
|
||||
|
||||
async def test_dbus_yellow(dbus: list[str], dbus_bus: MessageBus):
|
||||
"""Test Yellow board load."""
|
||||
yellow = Yellow()
|
||||
await yellow.connect(dbus_bus)
|
||||
|
||||
assert yellow.name == "Yellow"
|
||||
assert yellow.disk_led is True
|
||||
assert yellow.heartbeat_led is True
|
||||
assert yellow.power_led is True
|
||||
|
||||
|
||||
async def test_dbus_yellow_set_disk_led(dbus: list[str], dbus_bus: MessageBus):
|
||||
"""Test setting disk led for Yellow board."""
|
||||
yellow = Yellow()
|
||||
await yellow.connect(dbus_bus)
|
||||
|
||||
dbus.clear()
|
||||
yellow.disk_led = False
|
||||
await asyncio.sleep(0)
|
||||
|
||||
assert dbus == ["/io/hass/os/Boards/Yellow-io.hass.os.Boards.Yellow.DiskLED"]
|
||||
|
||||
|
||||
async def test_dbus_yellow_set_heartbeat_led(dbus: list[str], dbus_bus: MessageBus):
|
||||
"""Test setting heartbeat led for Yellow board."""
|
||||
yellow = Yellow()
|
||||
await yellow.connect(dbus_bus)
|
||||
|
||||
dbus.clear()
|
||||
yellow.heartbeat_led = False
|
||||
await asyncio.sleep(0)
|
||||
|
||||
assert dbus == ["/io/hass/os/Boards/Yellow-io.hass.os.Boards.Yellow.HeartbeatLED"]
|
||||
|
||||
|
||||
async def test_dbus_yellow_set_power_led(dbus: list[str], dbus_bus: MessageBus):
|
||||
"""Test setting power led for Yellow board."""
|
||||
yellow = Yellow()
|
||||
await yellow.connect(dbus_bus)
|
||||
|
||||
dbus.clear()
|
||||
yellow.power_led = False
|
||||
await asyncio.sleep(0)
|
||||
|
||||
assert dbus == ["/io/hass/os/Boards/Yellow-io.hass.os.Boards.Yellow.PowerLED"]
|
||||
@@ -23,7 +23,7 @@ async def test_dbus_osagent_apparmor(coresys: CoreSys):
|
||||
await asyncio.sleep(0)
|
||||
assert coresys.dbus.agent.apparmor.version == "1.0.0"
|
||||
|
||||
fire_property_change_signal(coresys.dbus.agent, {}, ["ParserVersion"])
|
||||
fire_property_change_signal(coresys.dbus.agent.apparmor, {}, ["ParserVersion"])
|
||||
await asyncio.sleep(0)
|
||||
assert coresys.dbus.agent.apparmor.version == "2.13.2"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user