|
| 1 | +"""Test Home Assistant supervisor client.""" |
| 2 | + |
| 3 | +from aioresponses import aioresponses |
| 4 | +from yarl import URL |
| 5 | + |
| 6 | +from aiohasupervisor import SupervisorClient |
| 7 | +from aiohasupervisor.models import HomeAssistantOptions |
| 8 | + |
| 9 | +from . import load_fixture |
| 10 | +from .const import SUPERVISOR_URL |
| 11 | + |
| 12 | + |
| 13 | +async def test_homeassistant_info( |
| 14 | + responses: aioresponses, supervisor_client: SupervisorClient |
| 15 | +) -> None: |
| 16 | + """Test Home Assistant info API.""" |
| 17 | + responses.get( |
| 18 | + f"{SUPERVISOR_URL}/core/info", |
| 19 | + status=200, |
| 20 | + body=load_fixture("homeassistant_info.json"), |
| 21 | + ) |
| 22 | + info = await supervisor_client.homeassistant.info() |
| 23 | + |
| 24 | + assert info.version == "2024.9.0" |
| 25 | + assert info.update_available is False |
| 26 | + assert info.arch == "aarch64" |
| 27 | + assert info.ssl is False |
| 28 | + assert info.port == 8123 |
| 29 | + assert info.audio_output is None |
| 30 | + |
| 31 | + |
| 32 | +async def test_homeassistant_stats( |
| 33 | + responses: aioresponses, supervisor_client: SupervisorClient |
| 34 | +) -> None: |
| 35 | + """Test Home Assistant stats API.""" |
| 36 | + responses.get( |
| 37 | + f"{SUPERVISOR_URL}/core/stats", |
| 38 | + status=200, |
| 39 | + body=load_fixture("homeassistant_stats.json"), |
| 40 | + ) |
| 41 | + stats = await supervisor_client.homeassistant.stats() |
| 42 | + |
| 43 | + assert stats.cpu_percent == 0.01 |
| 44 | + assert stats.memory_usage == 678883328 |
| 45 | + assert stats.memory_percent == 17.41 |
| 46 | + |
| 47 | + |
| 48 | +async def test_homeassistant_options( |
| 49 | + responses: aioresponses, supervisor_client: SupervisorClient |
| 50 | +) -> None: |
| 51 | + """Test Home Assistant options API.""" |
| 52 | + responses.post(f"{SUPERVISOR_URL}/core/options", status=200) |
| 53 | + assert ( |
| 54 | + await supervisor_client.homeassistant.options( |
| 55 | + HomeAssistantOptions(watchdog=False, backups_exclude_database=True) |
| 56 | + ) |
| 57 | + is None |
| 58 | + ) |
| 59 | + assert responses.requests.keys() == { |
| 60 | + ("POST", URL(f"{SUPERVISOR_URL}/core/options")) |
| 61 | + } |
| 62 | + |
| 63 | + |
| 64 | +async def test_homeassistant_update( |
| 65 | + responses: aioresponses, supervisor_client: SupervisorClient |
| 66 | +) -> None: |
| 67 | + """Test Home Assistant update API.""" |
| 68 | + responses.post(f"{SUPERVISOR_URL}/core/update", status=200) |
| 69 | + assert await supervisor_client.homeassistant.update() is None |
| 70 | + assert responses.requests.keys() == {("POST", URL(f"{SUPERVISOR_URL}/core/update"))} |
| 71 | + |
| 72 | + |
| 73 | +async def test_homeassistant_restart( |
| 74 | + responses: aioresponses, supervisor_client: SupervisorClient |
| 75 | +) -> None: |
| 76 | + """Test Home Assistant restart API.""" |
| 77 | + responses.post(f"{SUPERVISOR_URL}/core/restart", status=200) |
| 78 | + assert await supervisor_client.homeassistant.restart() is None |
| 79 | + assert responses.requests.keys() == { |
| 80 | + ("POST", URL(f"{SUPERVISOR_URL}/core/restart")) |
| 81 | + } |
| 82 | + |
| 83 | + |
| 84 | +async def test_homeassistant_stop( |
| 85 | + responses: aioresponses, supervisor_client: SupervisorClient |
| 86 | +) -> None: |
| 87 | + """Test Home Assistant stop API.""" |
| 88 | + responses.post(f"{SUPERVISOR_URL}/core/stop", status=200) |
| 89 | + assert await supervisor_client.homeassistant.stop() is None |
| 90 | + assert responses.requests.keys() == {("POST", URL(f"{SUPERVISOR_URL}/core/stop"))} |
| 91 | + |
| 92 | + |
| 93 | +async def test_homeassistant_start( |
| 94 | + responses: aioresponses, supervisor_client: SupervisorClient |
| 95 | +) -> None: |
| 96 | + """Test Home Assistant start API.""" |
| 97 | + responses.post(f"{SUPERVISOR_URL}/core/start", status=200) |
| 98 | + assert await supervisor_client.homeassistant.start() is None |
| 99 | + assert responses.requests.keys() == {("POST", URL(f"{SUPERVISOR_URL}/core/start"))} |
| 100 | + |
| 101 | + |
| 102 | +async def test_homeassistant_check_config( |
| 103 | + responses: aioresponses, supervisor_client: SupervisorClient |
| 104 | +) -> None: |
| 105 | + """Test Home Assistant check config API.""" |
| 106 | + responses.post(f"{SUPERVISOR_URL}/core/check", status=200) |
| 107 | + assert await supervisor_client.homeassistant.check_config() is None |
| 108 | + assert responses.requests.keys() == {("POST", URL(f"{SUPERVISOR_URL}/core/check"))} |
| 109 | + |
| 110 | + |
| 111 | +async def test_homeassistant_rebuild( |
| 112 | + responses: aioresponses, supervisor_client: SupervisorClient |
| 113 | +) -> None: |
| 114 | + """Test Home Assistant rebuild API.""" |
| 115 | + responses.post(f"{SUPERVISOR_URL}/core/rebuild", status=200) |
| 116 | + assert await supervisor_client.homeassistant.rebuild() is None |
| 117 | + assert responses.requests.keys() == { |
| 118 | + ("POST", URL(f"{SUPERVISOR_URL}/core/rebuild")) |
| 119 | + } |
0 commit comments