2022-06-25 16:02:38 +00:00
|
|
|
"""The init tests for the nexia platform."""
|
Fix not retrying on connection reset during nexia config entry setup (#93576)
* Fix not retrying on connection reset during nexia config entry setup
fixes
```
2023-05-26 00:15:39.129 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Alexander for nexia
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 558, in _request
resp = await req.send(conn)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 670, in send
await writer.write_headers(status_line, self.headers)
File "/usr/local/lib/python3.11/site-packages/aiohttp/http_writer.py", line 130, in write_headers
self._write(buf)
File "/usr/local/lib/python3.11/site-packages/aiohttp/http_writer.py", line 75, in _write
raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 387, in async_setup
result = await component.async_setup_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/nexia/__init__.py", line 47, in async_setup_entry
await nexia_home.login()
File "/usr/local/lib/python3.11/site-packages/nexia/home.py", line 385, in login
request = await self.post_url(self.API_MOBILE_ACCOUNTS_SIGN_IN_URL, payload)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/nexia/home.py", line 157, in post_url
response: aiohttp.ClientResponse = await self.session.post(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 572, in _request
raise ClientOSError(*exc.args) from exc
aiohttp.client_exceptions.ClientOSError: Cannot write to closing transport
```
* coverage
2023-05-26 01:52:44 +00:00
|
|
|
import aiohttp
|
|
|
|
|
2022-06-25 16:02:38 +00:00
|
|
|
from homeassistant.components.nexia.const import DOMAIN
|
Fix not retrying on connection reset during nexia config entry setup (#93576)
* Fix not retrying on connection reset during nexia config entry setup
fixes
```
2023-05-26 00:15:39.129 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Alexander for nexia
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 558, in _request
resp = await req.send(conn)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 670, in send
await writer.write_headers(status_line, self.headers)
File "/usr/local/lib/python3.11/site-packages/aiohttp/http_writer.py", line 130, in write_headers
self._write(buf)
File "/usr/local/lib/python3.11/site-packages/aiohttp/http_writer.py", line 75, in _write
raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 387, in async_setup
result = await component.async_setup_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/nexia/__init__.py", line 47, in async_setup_entry
await nexia_home.login()
File "/usr/local/lib/python3.11/site-packages/nexia/home.py", line 385, in login
request = await self.post_url(self.API_MOBILE_ACCOUNTS_SIGN_IN_URL, payload)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/nexia/home.py", line 157, in post_url
response: aiohttp.ClientResponse = await self.session.post(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 572, in _request
raise ClientOSError(*exc.args) from exc
aiohttp.client_exceptions.ClientOSError: Cannot write to closing transport
```
* coverage
2023-05-26 01:52:44 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntryState
|
2023-02-08 15:48:54 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2022-06-25 16:02:38 +00:00
|
|
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
|
|
|
from homeassistant.helpers.entity_registry import EntityRegistry
|
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
from .util import async_init_integration
|
|
|
|
|
2023-02-08 15:48:54 +00:00
|
|
|
from tests.typing import WebSocketGenerator
|
|
|
|
|
2022-06-25 16:02:38 +00:00
|
|
|
|
Fix not retrying on connection reset during nexia config entry setup (#93576)
* Fix not retrying on connection reset during nexia config entry setup
fixes
```
2023-05-26 00:15:39.129 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Alexander for nexia
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 558, in _request
resp = await req.send(conn)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 670, in send
await writer.write_headers(status_line, self.headers)
File "/usr/local/lib/python3.11/site-packages/aiohttp/http_writer.py", line 130, in write_headers
self._write(buf)
File "/usr/local/lib/python3.11/site-packages/aiohttp/http_writer.py", line 75, in _write
raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 387, in async_setup
result = await component.async_setup_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/nexia/__init__.py", line 47, in async_setup_entry
await nexia_home.login()
File "/usr/local/lib/python3.11/site-packages/nexia/home.py", line 385, in login
request = await self.post_url(self.API_MOBILE_ACCOUNTS_SIGN_IN_URL, payload)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/nexia/home.py", line 157, in post_url
response: aiohttp.ClientResponse = await self.session.post(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 572, in _request
raise ClientOSError(*exc.args) from exc
aiohttp.client_exceptions.ClientOSError: Cannot write to closing transport
```
* coverage
2023-05-26 01:52:44 +00:00
|
|
|
async def test_setup_retry_client_os_error(hass: HomeAssistant) -> None:
|
|
|
|
"""Verify we retry setup on aiohttp.ClientOSError."""
|
|
|
|
config_entry = await async_init_integration(hass, exception=aiohttp.ClientOSError)
|
|
|
|
assert config_entry.state == ConfigEntryState.SETUP_RETRY
|
|
|
|
|
|
|
|
|
2022-06-25 16:02:38 +00:00
|
|
|
async def remove_device(ws_client, device_id, config_entry_id):
|
|
|
|
"""Remove config entry from a device."""
|
|
|
|
await ws_client.send_json(
|
|
|
|
{
|
|
|
|
"id": 5,
|
|
|
|
"type": "config/device_registry/remove_config_entry",
|
|
|
|
"config_entry_id": config_entry_id,
|
|
|
|
"device_id": device_id,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
response = await ws_client.receive_json()
|
|
|
|
return response["success"]
|
|
|
|
|
|
|
|
|
2023-02-08 15:48:54 +00:00
|
|
|
async def test_device_remove_devices(
|
|
|
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
|
|
|
) -> None:
|
2022-06-25 16:02:38 +00:00
|
|
|
"""Test we can only remove a device that no longer exists."""
|
|
|
|
await async_setup_component(hass, "config", {})
|
|
|
|
config_entry = await async_init_integration(hass)
|
|
|
|
entry_id = config_entry.entry_id
|
|
|
|
device_registry = dr.async_get(hass)
|
|
|
|
|
|
|
|
registry: EntityRegistry = er.async_get(hass)
|
|
|
|
entity = registry.entities["sensor.nick_office_temperature"]
|
|
|
|
|
|
|
|
live_zone_device_entry = device_registry.async_get(entity.device_id)
|
|
|
|
assert (
|
|
|
|
await remove_device(
|
|
|
|
await hass_ws_client(hass), live_zone_device_entry.id, entry_id
|
|
|
|
)
|
|
|
|
is False
|
|
|
|
)
|
|
|
|
|
2023-08-22 12:41:15 +00:00
|
|
|
entity = registry.entities["sensor.master_suite_humidity"]
|
2022-06-25 16:02:38 +00:00
|
|
|
live_thermostat_device_entry = device_registry.async_get(entity.device_id)
|
|
|
|
assert (
|
|
|
|
await remove_device(
|
|
|
|
await hass_ws_client(hass), live_thermostat_device_entry.id, entry_id
|
|
|
|
)
|
|
|
|
is False
|
|
|
|
)
|
|
|
|
|
|
|
|
dead_device_entry = device_registry.async_get_or_create(
|
|
|
|
config_entry_id=config_entry.entry_id,
|
|
|
|
identifiers={(DOMAIN, "unused")},
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
await remove_device(await hass_ws_client(hass), dead_device_entry.id, entry_id)
|
|
|
|
is True
|
|
|
|
)
|