|
1 | 1 | """Test the Xbox remote platform.""" |
2 | 2 |
|
3 | 3 | from collections.abc import Generator |
4 | | -from unittest.mock import patch |
| 4 | +from unittest.mock import AsyncMock, patch |
5 | 5 |
|
6 | 6 | import pytest |
| 7 | +from pythonxbox.api.provider.smartglass.models import InputKeyType |
7 | 8 | from syrupy.assertion import SnapshotAssertion |
8 | 9 |
|
| 10 | +from homeassistant.components.remote import ( |
| 11 | + ATTR_DELAY_SECS, |
| 12 | + DOMAIN as REMOTE_DOMAIN, |
| 13 | + SERVICE_SEND_COMMAND, |
| 14 | +) |
9 | 15 | from homeassistant.config_entries import ConfigEntryState |
10 | | -from homeassistant.const import Platform |
| 16 | +from homeassistant.const import ( |
| 17 | + ATTR_COMMAND, |
| 18 | + ATTR_ENTITY_ID, |
| 19 | + SERVICE_TURN_OFF, |
| 20 | + SERVICE_TURN_ON, |
| 21 | + Platform, |
| 22 | +) |
11 | 23 | from homeassistant.core import HomeAssistant |
12 | 24 | from homeassistant.helpers import entity_registry as er |
13 | 25 |
|
@@ -40,3 +52,160 @@ async def test_remotes( |
40 | 52 | assert config_entry.state is ConfigEntryState.LOADED |
41 | 53 |
|
42 | 54 | await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id) |
| 55 | + |
| 56 | + |
| 57 | +@pytest.mark.parametrize( |
| 58 | + ("button", "payload"), |
| 59 | + [ |
| 60 | + ("A", InputKeyType.A), |
| 61 | + ("B", InputKeyType.B), |
| 62 | + ("X", InputKeyType.X), |
| 63 | + ("Y", InputKeyType.Y), |
| 64 | + ("Up", InputKeyType.Up), |
| 65 | + ("Down", InputKeyType.Down), |
| 66 | + ("Left", InputKeyType.Left), |
| 67 | + ("Right", InputKeyType.Right), |
| 68 | + ("Menu", InputKeyType.Menu), |
| 69 | + ("View", InputKeyType.View), |
| 70 | + ("Nexus", InputKeyType.Nexus), |
| 71 | + ], |
| 72 | +) |
| 73 | +async def test_send_button_command( |
| 74 | + hass: HomeAssistant, |
| 75 | + xbox_live_client: AsyncMock, |
| 76 | + config_entry: MockConfigEntry, |
| 77 | + button: str, |
| 78 | + payload: InputKeyType, |
| 79 | +) -> None: |
| 80 | + """Test remote send button command.""" |
| 81 | + |
| 82 | + config_entry.add_to_hass(hass) |
| 83 | + await hass.config_entries.async_setup(config_entry.entry_id) |
| 84 | + await hass.async_block_till_done() |
| 85 | + |
| 86 | + assert config_entry.state is ConfigEntryState.LOADED |
| 87 | + |
| 88 | + await hass.services.async_call( |
| 89 | + REMOTE_DOMAIN, |
| 90 | + SERVICE_SEND_COMMAND, |
| 91 | + {ATTR_COMMAND: button, ATTR_DELAY_SECS: 0}, |
| 92 | + target={ATTR_ENTITY_ID: "remote.xone"}, |
| 93 | + blocking=True, |
| 94 | + ) |
| 95 | + |
| 96 | + xbox_live_client.smartglass.press_button.assert_called_once_with("HIJKLMN", payload) |
| 97 | + |
| 98 | + |
| 99 | +@pytest.mark.parametrize( |
| 100 | + ("command", "call_method"), |
| 101 | + [ |
| 102 | + ("WakeUp", "wake_up"), |
| 103 | + ("TurnOff", "turn_off"), |
| 104 | + ("Reboot", "reboot"), |
| 105 | + ("Mute", "mute"), |
| 106 | + ("Unmute", "unmute"), |
| 107 | + ("Play", "play"), |
| 108 | + ("Pause", "pause"), |
| 109 | + ("Previous", "previous"), |
| 110 | + ("Next", "next"), |
| 111 | + ("GoHome", "go_home"), |
| 112 | + ("GoBack", "go_back"), |
| 113 | + ("ShowGuideTab", "show_guide_tab"), |
| 114 | + ("ShowGuide", "show_tv_guide"), |
| 115 | + ], |
| 116 | +) |
| 117 | +async def test_send_command( |
| 118 | + hass: HomeAssistant, |
| 119 | + xbox_live_client: AsyncMock, |
| 120 | + config_entry: MockConfigEntry, |
| 121 | + command: str, |
| 122 | + call_method: str, |
| 123 | +) -> None: |
| 124 | + """Test remote send command.""" |
| 125 | + |
| 126 | + config_entry.add_to_hass(hass) |
| 127 | + await hass.config_entries.async_setup(config_entry.entry_id) |
| 128 | + await hass.async_block_till_done() |
| 129 | + |
| 130 | + assert config_entry.state is ConfigEntryState.LOADED |
| 131 | + |
| 132 | + await hass.services.async_call( |
| 133 | + REMOTE_DOMAIN, |
| 134 | + SERVICE_SEND_COMMAND, |
| 135 | + {ATTR_COMMAND: command, ATTR_DELAY_SECS: 0}, |
| 136 | + target={ATTR_ENTITY_ID: "remote.xone"}, |
| 137 | + blocking=True, |
| 138 | + ) |
| 139 | + |
| 140 | + call = getattr(xbox_live_client.smartglass, call_method) |
| 141 | + call.assert_called_once_with("HIJKLMN") |
| 142 | + |
| 143 | + |
| 144 | +async def test_send_text( |
| 145 | + hass: HomeAssistant, |
| 146 | + xbox_live_client: AsyncMock, |
| 147 | + config_entry: MockConfigEntry, |
| 148 | +) -> None: |
| 149 | + """Test remote send text.""" |
| 150 | + |
| 151 | + config_entry.add_to_hass(hass) |
| 152 | + await hass.config_entries.async_setup(config_entry.entry_id) |
| 153 | + await hass.async_block_till_done() |
| 154 | + |
| 155 | + assert config_entry.state is ConfigEntryState.LOADED |
| 156 | + |
| 157 | + await hass.services.async_call( |
| 158 | + REMOTE_DOMAIN, |
| 159 | + SERVICE_SEND_COMMAND, |
| 160 | + {ATTR_COMMAND: "Hello", ATTR_DELAY_SECS: 0}, |
| 161 | + target={ATTR_ENTITY_ID: "remote.xone"}, |
| 162 | + blocking=True, |
| 163 | + ) |
| 164 | + |
| 165 | + xbox_live_client.smartglass.insert_text.assert_called_once_with("HIJKLMN", "Hello") |
| 166 | + |
| 167 | + |
| 168 | +async def test_turn_on( |
| 169 | + hass: HomeAssistant, |
| 170 | + xbox_live_client: AsyncMock, |
| 171 | + config_entry: MockConfigEntry, |
| 172 | +) -> None: |
| 173 | + """Test remote turn on.""" |
| 174 | + |
| 175 | + config_entry.add_to_hass(hass) |
| 176 | + await hass.config_entries.async_setup(config_entry.entry_id) |
| 177 | + await hass.async_block_till_done() |
| 178 | + |
| 179 | + assert config_entry.state is ConfigEntryState.LOADED |
| 180 | + |
| 181 | + await hass.services.async_call( |
| 182 | + REMOTE_DOMAIN, |
| 183 | + SERVICE_TURN_ON, |
| 184 | + target={ATTR_ENTITY_ID: "remote.xone"}, |
| 185 | + blocking=True, |
| 186 | + ) |
| 187 | + |
| 188 | + xbox_live_client.smartglass.wake_up.assert_called_once_with("HIJKLMN") |
| 189 | + |
| 190 | + |
| 191 | +async def test_turn_off( |
| 192 | + hass: HomeAssistant, |
| 193 | + xbox_live_client: AsyncMock, |
| 194 | + config_entry: MockConfigEntry, |
| 195 | +) -> None: |
| 196 | + """Test remote turn off.""" |
| 197 | + |
| 198 | + config_entry.add_to_hass(hass) |
| 199 | + await hass.config_entries.async_setup(config_entry.entry_id) |
| 200 | + await hass.async_block_till_done() |
| 201 | + |
| 202 | + assert config_entry.state is ConfigEntryState.LOADED |
| 203 | + |
| 204 | + await hass.services.async_call( |
| 205 | + REMOTE_DOMAIN, |
| 206 | + SERVICE_TURN_OFF, |
| 207 | + target={ATTR_ENTITY_ID: "remote.xone"}, |
| 208 | + blocking=True, |
| 209 | + ) |
| 210 | + |
| 211 | + xbox_live_client.smartglass.turn_off.assert_called_once_with("HIJKLMN") |
0 commit comments