hass-core/tests/components/hardkernel/test_hardware.py
Stefan Agner f903c536fb
Add Hardkernel ODROID-M1 (#89431)
* Add Hardkernel ODROID-M1

Add Hardkernel ODROID-M1 machine. ODROID-M1 is a Rockchip RK3568B2 SoC
based single board computer with 4xCortex-A55, NVMe support and up to
8GB of RAM.

* Update homeassistant/components/hardkernel/hardware.py

Co-authored-by: Franck Nijhof <frenck@frenck.nl>

* Fix tests

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
2023-03-09 14:18:19 +01:00

96 lines
2.9 KiB
Python

"""Test the Hardkernel hardware platform."""
from unittest.mock import patch
import pytest
from homeassistant.components.hardkernel.const import DOMAIN
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, MockModule, mock_integration
from tests.typing import WebSocketGenerator
async def test_hardware_info(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test we can get the board info."""
mock_integration(hass, MockModule("hassio"))
# Setup the config entry
config_entry = MockConfigEntry(
data={},
domain=DOMAIN,
options={},
title="Hardkernel",
)
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.hardkernel.get_os_info",
return_value={"board": "odroid-n2"},
):
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
client = await hass_ws_client(hass)
with patch(
"homeassistant.components.hardkernel.hardware.get_os_info",
return_value={"board": "odroid-n2"},
):
await client.send_json({"id": 1, "type": "hardware/info"})
msg = await client.receive_json()
assert msg["id"] == 1
assert msg["success"]
assert msg["result"] == {
"hardware": [
{
"board": {
"hassio_board_id": "odroid-n2",
"manufacturer": "hardkernel",
"model": "odroid-n2",
"revision": None,
},
"config_entries": [config_entry.entry_id],
"dongle": None,
"name": "Home Assistant Blue / Hardkernel ODROID-N2/N2+",
"url": None,
}
]
}
@pytest.mark.parametrize("os_info", [None, {"board": None}, {"board": "other"}])
async def test_hardware_info_fail(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, os_info
) -> None:
"""Test async_info raises if os_info is not as expected."""
mock_integration(hass, MockModule("hassio"))
# Setup the config entry
config_entry = MockConfigEntry(
data={},
domain=DOMAIN,
options={},
title="Hardkernel",
)
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.hardkernel.get_os_info",
return_value={"board": "odroid-n2"},
):
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
client = await hass_ws_client(hass)
with patch(
"homeassistant.components.hardkernel.hardware.get_os_info",
return_value=os_info,
):
await client.send_json({"id": 1, "type": "hardware/info"})
msg = await client.receive_json()
assert msg["id"] == 1
assert msg["success"]
assert msg["result"] == {"hardware": []}