|
4 | 4 | from datetime import datetime |
5 | 5 |
|
6 | 6 | from homeassistant_api import Client |
| 7 | +from homeassistant_api.errors import RequestError |
| 8 | +from homeassistant_api.models import ConfigEntryDisabler |
7 | 9 | from homeassistant_api.models.events import Event |
8 | 10 | from homeassistant_api.models.states import State |
9 | 11 | from homeassistant_api.websocket import WebsocketClient |
@@ -197,6 +199,98 @@ def test_websocket_get_domain(websocket_client: WebsocketClient) -> None: |
197 | 199 | assert domain.services |
198 | 200 |
|
199 | 201 |
|
| 202 | +def test_get_nonuser_flows_in_progress(websocket_client: WebsocketClient) -> None: |
| 203 | + """Tests the `"type": "config_entries/flow/progress"` websocket command.""" |
| 204 | + # No flows in progress |
| 205 | + flows = websocket_client.get_nonuser_flows_in_progress() |
| 206 | + assert not flows |
| 207 | + |
| 208 | + |
| 209 | +def test_disable_enable_config_entry(websocket_client: WebsocketClient) -> None: |
| 210 | + """Tests the `"type": "config_entries/disable"` websocket command.""" |
| 211 | + # Get sun entry |
| 212 | + entry = websocket_client.get_config_entries()[0] |
| 213 | + assert entry.disabled_by is None |
| 214 | + |
| 215 | + # Disable entry |
| 216 | + websocket_client.disable_config_entry(entry.entry_id) |
| 217 | + |
| 218 | + # Check that it was disabled |
| 219 | + disabled_entry = websocket_client.get_config_entries()[0] |
| 220 | + assert disabled_entry.disabled_by is ConfigEntryDisabler.USER |
| 221 | + |
| 222 | + # Re-enable |
| 223 | + websocket_client.enable_config_entry(entry.entry_id) |
| 224 | + |
| 225 | + # Check that it was enable |
| 226 | + enabled_entry = websocket_client.get_config_entries()[0] |
| 227 | + assert enabled_entry.disabled_by is None |
| 228 | + |
| 229 | + |
| 230 | +def test_ignore_config_flow(websocket_client: WebsocketClient) -> None: |
| 231 | + """Tests the `"type": "config_entries/ignore_flow"` websocket command.""" |
| 232 | + # Currently not able to test as no flows are in progress. Send invalid parameters and handle that error |
| 233 | + try: |
| 234 | + websocket_client.ignore_config_flow("", "") |
| 235 | + except RequestError as error: |
| 236 | + assert ( |
| 237 | + error.__str__() |
| 238 | + == "An error occurred while making the request to 'Config entry not found' with data: 'not_found'" |
| 239 | + ) |
| 240 | + |
| 241 | + |
| 242 | +def test_get_config_entries(websocket_client: WebsocketClient) -> None: |
| 243 | + """Tests the `"type": "config_entries/get"` websocket command.""" |
| 244 | + # Check number of entries |
| 245 | + entries = websocket_client.get_config_entries() |
| 246 | + assert len(entries) == 4 |
| 247 | + |
| 248 | + # Check that entries have expected values |
| 249 | + sun = entries[0] |
| 250 | + # Usually some kind of float. Is 0.0 in testing environment |
| 251 | + assert sun.created_at == 0.0 |
| 252 | + assert sun.entry_id == "5f8426fa502435857743f302651753c9" |
| 253 | + assert sun.domain == "sun" |
| 254 | + assert sun.modified_at == 0.0 |
| 255 | + assert sun.title == "Sun" |
| 256 | + assert sun.source == "import" |
| 257 | + assert sun.supports_options is False |
| 258 | + assert sun.supports_remove_device is False |
| 259 | + assert sun.supports_unload is True |
| 260 | + assert sun.supports_reconfigure is False |
| 261 | + assert sun.supported_subentry_types == {} |
| 262 | + assert sun.pref_disable_new_entities is False |
| 263 | + assert sun.pref_disable_polling is False |
| 264 | + assert sun.disabled_by is None |
| 265 | + assert sun.reason is None |
| 266 | + assert sun.error_reason_translation_key is None |
| 267 | + assert sun.error_reason_translation_placeholders is None |
| 268 | + assert sun.num_subentries == 0 |
| 269 | + |
| 270 | + |
| 271 | +def test_get_entry_subentries(websocket_client: WebsocketClient) -> None: |
| 272 | + """Tests the `"type": "config_entries/subentries/list"` websocket command.""" |
| 273 | + # Currently not able to test as no entries with subentries available |
| 274 | + # Get the sun entry |
| 275 | + sun = websocket_client.get_config_entries()[0] |
| 276 | + assert sun |
| 277 | + |
| 278 | + # Get subentries for sun (empty tuple) |
| 279 | + assert not websocket_client.get_entry_subentries(sun.entry_id) |
| 280 | + |
| 281 | + |
| 282 | +def test_delete_entry_subentry(websocket_client: WebsocketClient) -> None: |
| 283 | + """Tests the `"type": "config_entries/subentries/delete"` websocket command.""" |
| 284 | + # Currently not able to test as no entries with subentries available. Send invalid parameters and handle that error |
| 285 | + try: |
| 286 | + websocket_client.delete_entry_subentry("", "") |
| 287 | + except RequestError as error: |
| 288 | + assert ( |
| 289 | + error.__str__() |
| 290 | + == "An error occurred while making the request to 'Config entry not found' with data: 'not_found'" |
| 291 | + ) |
| 292 | + |
| 293 | + |
200 | 294 | def test_trigger_service(cached_client: Client) -> None: |
201 | 295 | """Tests the `POST /api/services/<domain>/<service>` endpoint.""" |
202 | 296 | notify = cached_client.get_domain("notify") |
|
0 commit comments