2022-06-25 16:02:38 +00:00
|
|
|
"""The init tests for the nexia platform."""
|
2024-03-08 18:16:21 +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
|
|
|
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.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)
|
2024-04-05 15:37:00 +00:00
|
|
|
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
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
|
|
|
|
|
|
|
|
2023-02-08 15:48:54 +00:00
|
|
|
async def test_device_remove_devices(
|
2024-05-28 11:40:45 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
hass_ws_client: WebSocketGenerator,
|
|
|
|
device_registry: dr.DeviceRegistry,
|
|
|
|
entity_registry: er.EntityRegistry,
|
2023-02-08 15:48:54 +00:00
|
|
|
) -> 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
|
|
|
|
|
2024-05-28 11:40:45 +00:00
|
|
|
entity = entity_registry.entities["sensor.nick_office_temperature"]
|
2022-06-25 16:02:38 +00:00
|
|
|
|
|
|
|
live_zone_device_entry = device_registry.async_get(entity.device_id)
|
2024-04-30 10:50:35 +00:00
|
|
|
client = await hass_ws_client(hass)
|
|
|
|
response = await client.remove_device(live_zone_device_entry.id, entry_id)
|
|
|
|
assert not response["success"]
|
2022-06-25 16:02:38 +00:00
|
|
|
|
2024-05-28 11:40:45 +00:00
|
|
|
entity = 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)
|
2024-04-30 10:50:35 +00:00
|
|
|
response = await client.remove_device(live_thermostat_device_entry.id, entry_id)
|
|
|
|
assert not response["success"]
|
2022-06-25 16:02:38 +00:00
|
|
|
|
|
|
|
dead_device_entry = device_registry.async_get_or_create(
|
|
|
|
config_entry_id=config_entry.entry_id,
|
|
|
|
identifiers={(DOMAIN, "unused")},
|
|
|
|
)
|
2024-04-30 10:50:35 +00:00
|
|
|
response = await client.remove_device(dead_device_entry.id, entry_id)
|
|
|
|
assert response["success"]
|