1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Improve androidtv mac address handling and test coverage (#65749)

* Better mac addr handling and improve test coverage

* Apply suggested changes

* Apply more suggested changes
This commit is contained in:
ollo69
2022-02-06 23:15:50 +01:00
committed by GitHub
parent 50525e25b6
commit 341d039252
6 changed files with 94 additions and 118 deletions

View File

@@ -31,6 +31,7 @@ from homeassistant.components.androidtv.const import (
DEFAULT_PORT,
DOMAIN,
PROP_ETHMAC,
PROP_WIFIMAC,
)
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
@@ -42,6 +43,7 @@ from tests.components.androidtv.patchers import isfile
ADBKEY = "adbkey"
ETH_MAC = "a1:b1:c1:d1:e1:f1"
WIFI_MAC = "a2:b2:c2:d2:e2:f2"
HOST = "127.0.0.1"
VALID_DETECT_RULE = [{"paused": {"media_session_state": 3}}]
@@ -84,18 +86,28 @@ PATCH_SETUP_ENTRY = patch(
class MockConfigDevice:
"""Mock class to emulate Android TV device."""
def __init__(self, eth_mac=ETH_MAC):
def __init__(self, eth_mac=ETH_MAC, wifi_mac=None):
"""Initialize a fake device to test config flow."""
self.available = True
self.device_properties = {PROP_ETHMAC: eth_mac}
self.device_properties = {PROP_ETHMAC: eth_mac, PROP_WIFIMAC: wifi_mac}
async def adb_close(self):
"""Fake method to close connection."""
self.available = False
@pytest.mark.parametrize("config", [CONFIG_PYTHON_ADB, CONFIG_ADB_SERVER])
async def test_user(hass, config):
@pytest.mark.parametrize(
["config", "eth_mac", "wifi_mac"],
[
(CONFIG_PYTHON_ADB, ETH_MAC, None),
(CONFIG_ADB_SERVER, ETH_MAC, None),
(CONFIG_PYTHON_ADB, None, WIFI_MAC),
(CONFIG_ADB_SERVER, None, WIFI_MAC),
(CONFIG_PYTHON_ADB, ETH_MAC, WIFI_MAC),
(CONFIG_ADB_SERVER, ETH_MAC, WIFI_MAC),
],
)
async def test_user(hass, config, eth_mac, wifi_mac):
"""Test user config."""
flow_result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER, "show_advanced_options": True}
@@ -106,7 +118,7 @@ async def test_user(hass, config):
# test with all provided
with patch(
CONNECT_METHOD,
return_value=(MockConfigDevice(), None),
return_value=(MockConfigDevice(eth_mac, wifi_mac), None),
), PATCH_SETUP_ENTRY as mock_setup_entry, PATCH_GET_HOST_IP:
result = await hass.config_entries.flow.async_configure(
flow_result["flow_id"], user_input=config
@@ -273,7 +285,7 @@ async def test_invalid_serial(hass):
"""Test for invalid serialno."""
with patch(
CONNECT_METHOD,
return_value=(MockConfigDevice(eth_mac=""), None),
return_value=(MockConfigDevice(eth_mac=None), None),
), PATCH_GET_HOST_IP:
result = await hass.config_entries.flow.async_init(
DOMAIN,