mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Update systembridgeconnector to 3.4.4 (#75362)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
c93d9d9a90
commit
64898af58e
@ -10,6 +10,10 @@ from systembridgeconnector.exceptions import (
|
|||||||
ConnectionClosedException,
|
ConnectionClosedException,
|
||||||
ConnectionErrorException,
|
ConnectionErrorException,
|
||||||
)
|
)
|
||||||
|
from systembridgeconnector.models.keyboard_key import KeyboardKey
|
||||||
|
from systembridgeconnector.models.keyboard_text import KeyboardText
|
||||||
|
from systembridgeconnector.models.open_path import OpenPath
|
||||||
|
from systembridgeconnector.models.open_url import OpenUrl
|
||||||
from systembridgeconnector.version import SUPPORTED_VERSION, Version
|
from systembridgeconnector.version import SUPPORTED_VERSION, Version
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -149,7 +153,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
coordinator: SystemBridgeDataUpdateCoordinator = hass.data[DOMAIN][
|
coordinator: SystemBridgeDataUpdateCoordinator = hass.data[DOMAIN][
|
||||||
call.data[CONF_BRIDGE]
|
call.data[CONF_BRIDGE]
|
||||||
]
|
]
|
||||||
await coordinator.websocket_client.open_path(call.data[CONF_PATH])
|
await coordinator.websocket_client.open_path(
|
||||||
|
OpenPath(path=call.data[CONF_PATH])
|
||||||
|
)
|
||||||
|
|
||||||
async def handle_open_url(call: ServiceCall) -> None:
|
async def handle_open_url(call: ServiceCall) -> None:
|
||||||
"""Handle the open url service call."""
|
"""Handle the open url service call."""
|
||||||
@ -157,21 +163,25 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
coordinator: SystemBridgeDataUpdateCoordinator = hass.data[DOMAIN][
|
coordinator: SystemBridgeDataUpdateCoordinator = hass.data[DOMAIN][
|
||||||
call.data[CONF_BRIDGE]
|
call.data[CONF_BRIDGE]
|
||||||
]
|
]
|
||||||
await coordinator.websocket_client.open_url(call.data[CONF_URL])
|
await coordinator.websocket_client.open_url(OpenUrl(url=call.data[CONF_URL]))
|
||||||
|
|
||||||
async def handle_send_keypress(call: ServiceCall) -> None:
|
async def handle_send_keypress(call: ServiceCall) -> None:
|
||||||
"""Handle the send_keypress service call."""
|
"""Handle the send_keypress service call."""
|
||||||
coordinator: SystemBridgeDataUpdateCoordinator = hass.data[DOMAIN][
|
coordinator: SystemBridgeDataUpdateCoordinator = hass.data[DOMAIN][
|
||||||
call.data[CONF_BRIDGE]
|
call.data[CONF_BRIDGE]
|
||||||
]
|
]
|
||||||
await coordinator.websocket_client.keyboard_keypress(call.data[CONF_KEY])
|
await coordinator.websocket_client.keyboard_keypress(
|
||||||
|
KeyboardKey(key=call.data[CONF_KEY])
|
||||||
|
)
|
||||||
|
|
||||||
async def handle_send_text(call: ServiceCall) -> None:
|
async def handle_send_text(call: ServiceCall) -> None:
|
||||||
"""Handle the send_keypress service call."""
|
"""Handle the send_keypress service call."""
|
||||||
coordinator: SystemBridgeDataUpdateCoordinator = hass.data[DOMAIN][
|
coordinator: SystemBridgeDataUpdateCoordinator = hass.data[DOMAIN][
|
||||||
call.data[CONF_BRIDGE]
|
call.data[CONF_BRIDGE]
|
||||||
]
|
]
|
||||||
await coordinator.websocket_client.keyboard_text(call.data[CONF_TEXT])
|
await coordinator.websocket_client.keyboard_text(
|
||||||
|
KeyboardText(text=call.data[CONF_TEXT])
|
||||||
|
)
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -7,12 +7,13 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import async_timeout
|
import async_timeout
|
||||||
from systembridgeconnector.const import EVENT_MODULE, EVENT_TYPE, TYPE_DATA_UPDATE
|
|
||||||
from systembridgeconnector.exceptions import (
|
from systembridgeconnector.exceptions import (
|
||||||
AuthenticationException,
|
AuthenticationException,
|
||||||
ConnectionClosedException,
|
ConnectionClosedException,
|
||||||
ConnectionErrorException,
|
ConnectionErrorException,
|
||||||
)
|
)
|
||||||
|
from systembridgeconnector.models.get_data import GetData
|
||||||
|
from systembridgeconnector.models.system import System
|
||||||
from systembridgeconnector.websocket_client import WebSocketClient
|
from systembridgeconnector.websocket_client import WebSocketClient
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ STEP_USER_DATA_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def validate_input(
|
async def _validate_input(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
data: dict[str, Any],
|
data: dict[str, Any],
|
||||||
) -> dict[str, str]:
|
) -> dict[str, str]:
|
||||||
@ -56,15 +57,12 @@ async def validate_input(
|
|||||||
try:
|
try:
|
||||||
async with async_timeout.timeout(30):
|
async with async_timeout.timeout(30):
|
||||||
await websocket_client.connect(session=async_get_clientsession(hass))
|
await websocket_client.connect(session=async_get_clientsession(hass))
|
||||||
await websocket_client.get_data(["system"])
|
hass.async_create_task(websocket_client.listen())
|
||||||
while True:
|
response = await websocket_client.get_data(GetData(modules=["system"]))
|
||||||
message = await websocket_client.receive_message()
|
_LOGGER.debug("Got response: %s", response.json())
|
||||||
_LOGGER.debug("Message: %s", message)
|
if response.data is None or not isinstance(response.data, System):
|
||||||
if (
|
raise CannotConnect("No data received")
|
||||||
message[EVENT_TYPE] == TYPE_DATA_UPDATE
|
system: System = response.data
|
||||||
and message[EVENT_MODULE] == "system"
|
|
||||||
):
|
|
||||||
break
|
|
||||||
except AuthenticationException as exception:
|
except AuthenticationException as exception:
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Authentication error when connecting to %s: %s", data[CONF_HOST], exception
|
"Authentication error when connecting to %s: %s", data[CONF_HOST], exception
|
||||||
@ -81,14 +79,12 @@ async def validate_input(
|
|||||||
except asyncio.TimeoutError as exception:
|
except asyncio.TimeoutError as exception:
|
||||||
_LOGGER.warning("Timed out connecting to %s: %s", data[CONF_HOST], exception)
|
_LOGGER.warning("Timed out connecting to %s: %s", data[CONF_HOST], exception)
|
||||||
raise CannotConnect from exception
|
raise CannotConnect from exception
|
||||||
|
except ValueError as exception:
|
||||||
|
raise CannotConnect from exception
|
||||||
|
|
||||||
_LOGGER.debug("%s Message: %s", TYPE_DATA_UPDATE, message)
|
_LOGGER.debug("Got System data: %s", system.json())
|
||||||
|
|
||||||
if "uuid" not in message["data"]:
|
return {"hostname": host, "uuid": system.uuid}
|
||||||
error = "No UUID in result!"
|
|
||||||
raise CannotConnect(error)
|
|
||||||
|
|
||||||
return {"hostname": host, "uuid": message["data"]["uuid"]}
|
|
||||||
|
|
||||||
|
|
||||||
async def _async_get_info(
|
async def _async_get_info(
|
||||||
@ -98,7 +94,7 @@ async def _async_get_info(
|
|||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
info = await validate_input(hass, user_input)
|
info = await _validate_input(hass, user_input)
|
||||||
except CannotConnect:
|
except CannotConnect:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
except InvalidAuth:
|
except InvalidAuth:
|
||||||
|
@ -5,6 +5,7 @@ import asyncio
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import async_timeout
|
import async_timeout
|
||||||
from pydantic import BaseModel # pylint: disable=no-name-in-module
|
from pydantic import BaseModel # pylint: disable=no-name-in-module
|
||||||
@ -17,8 +18,10 @@ from systembridgeconnector.models.battery import Battery
|
|||||||
from systembridgeconnector.models.cpu import Cpu
|
from systembridgeconnector.models.cpu import Cpu
|
||||||
from systembridgeconnector.models.disk import Disk
|
from systembridgeconnector.models.disk import Disk
|
||||||
from systembridgeconnector.models.display import Display
|
from systembridgeconnector.models.display import Display
|
||||||
|
from systembridgeconnector.models.get_data import GetData
|
||||||
from systembridgeconnector.models.gpu import Gpu
|
from systembridgeconnector.models.gpu import Gpu
|
||||||
from systembridgeconnector.models.memory import Memory
|
from systembridgeconnector.models.memory import Memory
|
||||||
|
from systembridgeconnector.models.register_data_listener import RegisterDataListener
|
||||||
from systembridgeconnector.models.system import System
|
from systembridgeconnector.models.system import System
|
||||||
from systembridgeconnector.websocket_client import WebSocketClient
|
from systembridgeconnector.websocket_client import WebSocketClient
|
||||||
|
|
||||||
@ -93,12 +96,14 @@ class SystemBridgeDataUpdateCoordinator(
|
|||||||
if not self.websocket_client.connected:
|
if not self.websocket_client.connected:
|
||||||
await self._setup_websocket()
|
await self._setup_websocket()
|
||||||
|
|
||||||
self.hass.async_create_task(self.websocket_client.get_data(modules))
|
self.hass.async_create_task(
|
||||||
|
self.websocket_client.get_data(GetData(modules=modules))
|
||||||
|
)
|
||||||
|
|
||||||
async def async_handle_module(
|
async def async_handle_module(
|
||||||
self,
|
self,
|
||||||
module_name: str,
|
module_name: str,
|
||||||
module,
|
module: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle data from the WebSocket client."""
|
"""Handle data from the WebSocket client."""
|
||||||
self.logger.debug("Set new data for: %s", module_name)
|
self.logger.debug("Set new data for: %s", module_name)
|
||||||
@ -174,7 +179,9 @@ class SystemBridgeDataUpdateCoordinator(
|
|||||||
|
|
||||||
self.hass.async_create_task(self._listen_for_data())
|
self.hass.async_create_task(self._listen_for_data())
|
||||||
|
|
||||||
await self.websocket_client.register_data_listener(MODULES)
|
await self.websocket_client.register_data_listener(
|
||||||
|
RegisterDataListener(modules=MODULES)
|
||||||
|
)
|
||||||
|
|
||||||
self.last_update_success = True
|
self.last_update_success = True
|
||||||
self.async_update_listeners()
|
self.async_update_listeners()
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "System Bridge",
|
"name": "System Bridge",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/system_bridge",
|
"documentation": "https://www.home-assistant.io/integrations/system_bridge",
|
||||||
"requirements": ["systembridgeconnector==3.3.2"],
|
"requirements": ["systembridgeconnector==3.4.4"],
|
||||||
"codeowners": ["@timmo001"],
|
"codeowners": ["@timmo001"],
|
||||||
"zeroconf": ["_system-bridge._tcp.local."],
|
"zeroconf": ["_system-bridge._tcp.local."],
|
||||||
"after_dependencies": ["zeroconf"],
|
"after_dependencies": ["zeroconf"],
|
||||||
|
@ -2294,7 +2294,7 @@ swisshydrodata==0.1.0
|
|||||||
synology-srm==0.2.0
|
synology-srm==0.2.0
|
||||||
|
|
||||||
# homeassistant.components.system_bridge
|
# homeassistant.components.system_bridge
|
||||||
systembridgeconnector==3.3.2
|
systembridgeconnector==3.4.4
|
||||||
|
|
||||||
# homeassistant.components.tailscale
|
# homeassistant.components.tailscale
|
||||||
tailscale==0.2.0
|
tailscale==0.2.0
|
||||||
|
@ -1558,7 +1558,7 @@ sunwatcher==0.2.1
|
|||||||
surepy==0.7.2
|
surepy==0.7.2
|
||||||
|
|
||||||
# homeassistant.components.system_bridge
|
# homeassistant.components.system_bridge
|
||||||
systembridgeconnector==3.3.2
|
systembridgeconnector==3.4.4
|
||||||
|
|
||||||
# homeassistant.components.tailscale
|
# homeassistant.components.tailscale
|
||||||
tailscale==0.2.0
|
tailscale==0.2.0
|
||||||
|
@ -2,21 +2,14 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from systembridgeconnector.const import (
|
from systembridgeconnector.const import MODEL_SYSTEM, TYPE_DATA_UPDATE
|
||||||
EVENT_DATA,
|
|
||||||
EVENT_MESSAGE,
|
|
||||||
EVENT_MODULE,
|
|
||||||
EVENT_SUBTYPE,
|
|
||||||
EVENT_TYPE,
|
|
||||||
SUBTYPE_BAD_API_KEY,
|
|
||||||
TYPE_DATA_UPDATE,
|
|
||||||
TYPE_ERROR,
|
|
||||||
)
|
|
||||||
from systembridgeconnector.exceptions import (
|
from systembridgeconnector.exceptions import (
|
||||||
AuthenticationException,
|
AuthenticationException,
|
||||||
ConnectionClosedException,
|
ConnectionClosedException,
|
||||||
ConnectionErrorException,
|
ConnectionErrorException,
|
||||||
)
|
)
|
||||||
|
from systembridgeconnector.models.response import Response
|
||||||
|
from systembridgeconnector.models.system import LastUpdated, System
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
from homeassistant.components import zeroconf
|
from homeassistant.components import zeroconf
|
||||||
@ -48,8 +41,8 @@ FIXTURE_ZEROCONF = zeroconf.ZeroconfServiceInfo(
|
|||||||
addresses=["1.1.1.1"],
|
addresses=["1.1.1.1"],
|
||||||
port=9170,
|
port=9170,
|
||||||
hostname="test-bridge.local.",
|
hostname="test-bridge.local.",
|
||||||
type="_system-bridge._udp.local.",
|
type="_system-bridge._tcp.local.",
|
||||||
name="System Bridge - test-bridge._system-bridge._udp.local.",
|
name="System Bridge - test-bridge._system-bridge._tcp.local.",
|
||||||
properties={
|
properties={
|
||||||
"address": "http://test-bridge:9170",
|
"address": "http://test-bridge:9170",
|
||||||
"fqdn": "test-bridge",
|
"fqdn": "test-bridge",
|
||||||
@ -66,34 +59,70 @@ FIXTURE_ZEROCONF_BAD = zeroconf.ZeroconfServiceInfo(
|
|||||||
addresses=["1.1.1.1"],
|
addresses=["1.1.1.1"],
|
||||||
port=9170,
|
port=9170,
|
||||||
hostname="test-bridge.local.",
|
hostname="test-bridge.local.",
|
||||||
type="_system-bridge._udp.local.",
|
type="_system-bridge._tcp.local.",
|
||||||
name="System Bridge - test-bridge._system-bridge._udp.local.",
|
name="System Bridge - test-bridge._system-bridge._tcp.local.",
|
||||||
properties={
|
properties={
|
||||||
"something": "bad",
|
"something": "bad",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
FIXTURE_DATA_SYSTEM = {
|
|
||||||
EVENT_TYPE: TYPE_DATA_UPDATE,
|
|
||||||
EVENT_MESSAGE: "Data changed",
|
|
||||||
EVENT_MODULE: "system",
|
|
||||||
EVENT_DATA: {
|
|
||||||
"uuid": FIXTURE_UUID,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
FIXTURE_DATA_SYSTEM_BAD = {
|
FIXTURE_SYSTEM = System(
|
||||||
EVENT_TYPE: TYPE_DATA_UPDATE,
|
id=FIXTURE_UUID,
|
||||||
EVENT_MESSAGE: "Data changed",
|
boot_time=1,
|
||||||
EVENT_MODULE: "system",
|
fqdn="",
|
||||||
EVENT_DATA: {},
|
hostname="1.1.1.1",
|
||||||
}
|
ip_address_4="1.1.1.1",
|
||||||
|
mac_address=FIXTURE_MAC_ADDRESS,
|
||||||
|
platform="",
|
||||||
|
platform_version="",
|
||||||
|
uptime=1,
|
||||||
|
uuid=FIXTURE_UUID,
|
||||||
|
version="",
|
||||||
|
version_latest="",
|
||||||
|
version_newer_available=False,
|
||||||
|
last_updated=LastUpdated(
|
||||||
|
boot_time=1,
|
||||||
|
fqdn=1,
|
||||||
|
hostname=1,
|
||||||
|
ip_address_4=1,
|
||||||
|
mac_address=1,
|
||||||
|
platform=1,
|
||||||
|
platform_version=1,
|
||||||
|
uptime=1,
|
||||||
|
uuid=1,
|
||||||
|
version=1,
|
||||||
|
version_latest=1,
|
||||||
|
version_newer_available=1,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
FIXTURE_DATA_AUTH_ERROR = {
|
FIXTURE_DATA_RESPONSE = Response(
|
||||||
EVENT_TYPE: TYPE_ERROR,
|
id="1234",
|
||||||
EVENT_SUBTYPE: SUBTYPE_BAD_API_KEY,
|
type=TYPE_DATA_UPDATE,
|
||||||
EVENT_MESSAGE: "Invalid api-key",
|
subtype=None,
|
||||||
}
|
message="Data received",
|
||||||
|
module=MODEL_SYSTEM,
|
||||||
|
data=FIXTURE_SYSTEM,
|
||||||
|
)
|
||||||
|
|
||||||
|
FIXTURE_DATA_RESPONSE_BAD = Response(
|
||||||
|
id="1234",
|
||||||
|
type=TYPE_DATA_UPDATE,
|
||||||
|
subtype=None,
|
||||||
|
message="Data received",
|
||||||
|
module=MODEL_SYSTEM,
|
||||||
|
data={},
|
||||||
|
)
|
||||||
|
|
||||||
|
FIXTURE_DATA_RESPONSE_BAD = Response(
|
||||||
|
id="1234",
|
||||||
|
type=TYPE_DATA_UPDATE,
|
||||||
|
subtype=None,
|
||||||
|
message="Data received",
|
||||||
|
module=MODEL_SYSTEM,
|
||||||
|
data={},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_show_user_form(hass: HomeAssistant) -> None:
|
async def test_show_user_form(hass: HomeAssistant) -> None:
|
||||||
@ -117,9 +146,11 @@ async def test_user_flow(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.system_bridge.config_flow.WebSocketClient.connect"
|
"homeassistant.components.system_bridge.config_flow.WebSocketClient.connect"
|
||||||
), patch("systembridgeconnector.websocket_client.WebSocketClient.get_data"), patch(
|
), patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.receive_message",
|
"systembridgeconnector.websocket_client.WebSocketClient.get_data",
|
||||||
return_value=FIXTURE_DATA_SYSTEM,
|
return_value=FIXTURE_DATA_RESPONSE,
|
||||||
|
), patch(
|
||||||
|
"systembridgeconnector.websocket_client.WebSocketClient.listen"
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.system_bridge.async_setup_entry",
|
"homeassistant.components.system_bridge.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
@ -167,11 +198,13 @@ async def test_form_connection_closed_cannot_connect(hass: HomeAssistant) -> Non
|
|||||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
assert result["errors"] is None
|
assert result["errors"] is None
|
||||||
|
|
||||||
with patch("systembridgeconnector.websocket_client.WebSocketClient.connect"), patch(
|
with patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.get_data"
|
"homeassistant.components.system_bridge.config_flow.WebSocketClient.connect"
|
||||||
), patch(
|
), patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.receive_message",
|
"systembridgeconnector.websocket_client.WebSocketClient.get_data",
|
||||||
side_effect=ConnectionClosedException,
|
side_effect=ConnectionClosedException,
|
||||||
|
), patch(
|
||||||
|
"systembridgeconnector.websocket_client.WebSocketClient.listen",
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], FIXTURE_USER_INPUT
|
result["flow_id"], FIXTURE_USER_INPUT
|
||||||
@ -192,11 +225,13 @@ async def test_form_timeout_cannot_connect(hass: HomeAssistant) -> None:
|
|||||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
assert result["errors"] is None
|
assert result["errors"] is None
|
||||||
|
|
||||||
with patch("systembridgeconnector.websocket_client.WebSocketClient.connect"), patch(
|
with patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.get_data"
|
"homeassistant.components.system_bridge.config_flow.WebSocketClient.connect"
|
||||||
), patch(
|
), patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.receive_message",
|
"systembridgeconnector.websocket_client.WebSocketClient.get_data",
|
||||||
side_effect=asyncio.TimeoutError,
|
side_effect=asyncio.TimeoutError,
|
||||||
|
), patch(
|
||||||
|
"systembridgeconnector.websocket_client.WebSocketClient.listen",
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], FIXTURE_USER_INPUT
|
result["flow_id"], FIXTURE_USER_INPUT
|
||||||
@ -217,11 +252,13 @@ async def test_form_invalid_auth(hass: HomeAssistant) -> None:
|
|||||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
assert result["errors"] is None
|
assert result["errors"] is None
|
||||||
|
|
||||||
with patch("systembridgeconnector.websocket_client.WebSocketClient.connect"), patch(
|
with patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.get_data"
|
"homeassistant.components.system_bridge.config_flow.WebSocketClient.connect"
|
||||||
), patch(
|
), patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.receive_message",
|
"systembridgeconnector.websocket_client.WebSocketClient.get_data",
|
||||||
side_effect=AuthenticationException,
|
side_effect=AuthenticationException,
|
||||||
|
), patch(
|
||||||
|
"systembridgeconnector.websocket_client.WebSocketClient.listen",
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], FIXTURE_USER_INPUT
|
result["flow_id"], FIXTURE_USER_INPUT
|
||||||
@ -242,11 +279,40 @@ async def test_form_uuid_error(hass: HomeAssistant) -> None:
|
|||||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
assert result["errors"] is None
|
assert result["errors"] is None
|
||||||
|
|
||||||
with patch("systembridgeconnector.websocket_client.WebSocketClient.connect"), patch(
|
with patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.get_data"
|
"homeassistant.components.system_bridge.config_flow.WebSocketClient.connect"
|
||||||
), patch(
|
), patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.receive_message",
|
"systembridgeconnector.websocket_client.WebSocketClient.get_data",
|
||||||
return_value=FIXTURE_DATA_SYSTEM_BAD,
|
side_effect=ValueError,
|
||||||
|
), patch(
|
||||||
|
"systembridgeconnector.websocket_client.WebSocketClient.listen",
|
||||||
|
):
|
||||||
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"], FIXTURE_USER_INPUT
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert result2["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
|
assert result2["step_id"] == "user"
|
||||||
|
assert result2["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_form_value_error(hass: HomeAssistant) -> None:
|
||||||
|
"""Test we handle error from bad value."""
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
|
assert result["errors"] is None
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.system_bridge.config_flow.WebSocketClient.connect"
|
||||||
|
), patch(
|
||||||
|
"systembridgeconnector.websocket_client.WebSocketClient.get_data",
|
||||||
|
return_value=FIXTURE_DATA_RESPONSE_BAD,
|
||||||
|
), patch(
|
||||||
|
"systembridgeconnector.websocket_client.WebSocketClient.listen",
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], FIXTURE_USER_INPUT
|
result["flow_id"], FIXTURE_USER_INPUT
|
||||||
@ -267,11 +333,13 @@ async def test_form_unknown_error(hass: HomeAssistant) -> None:
|
|||||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
assert result["errors"] is None
|
assert result["errors"] is None
|
||||||
|
|
||||||
with patch("systembridgeconnector.websocket_client.WebSocketClient.connect"), patch(
|
with patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.get_data"
|
"homeassistant.components.system_bridge.config_flow.WebSocketClient.connect"
|
||||||
), patch(
|
), patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.receive_message",
|
"systembridgeconnector.websocket_client.WebSocketClient.get_data",
|
||||||
side_effect=Exception,
|
side_effect=Exception,
|
||||||
|
), patch(
|
||||||
|
"systembridgeconnector.websocket_client.WebSocketClient.listen",
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], FIXTURE_USER_INPUT
|
result["flow_id"], FIXTURE_USER_INPUT
|
||||||
@ -292,11 +360,13 @@ async def test_reauth_authorization_error(hass: HomeAssistant) -> None:
|
|||||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
assert result["step_id"] == "authenticate"
|
assert result["step_id"] == "authenticate"
|
||||||
|
|
||||||
with patch("systembridgeconnector.websocket_client.WebSocketClient.connect"), patch(
|
with patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.get_data"
|
"homeassistant.components.system_bridge.config_flow.WebSocketClient.connect"
|
||||||
), patch(
|
), patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.receive_message",
|
"systembridgeconnector.websocket_client.WebSocketClient.get_data",
|
||||||
side_effect=AuthenticationException,
|
side_effect=AuthenticationException,
|
||||||
|
), patch(
|
||||||
|
"systembridgeconnector.websocket_client.WebSocketClient.listen",
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], FIXTURE_AUTH_INPUT
|
result["flow_id"], FIXTURE_AUTH_INPUT
|
||||||
@ -340,11 +410,13 @@ async def test_reauth_connection_closed_error(hass: HomeAssistant) -> None:
|
|||||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
assert result["step_id"] == "authenticate"
|
assert result["step_id"] == "authenticate"
|
||||||
|
|
||||||
with patch("systembridgeconnector.websocket_client.WebSocketClient.connect"), patch(
|
with patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.get_data"
|
"homeassistant.components.system_bridge.config_flow.WebSocketClient.connect"
|
||||||
), patch(
|
), patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.receive_message",
|
"systembridgeconnector.websocket_client.WebSocketClient.get_data",
|
||||||
side_effect=ConnectionClosedException,
|
side_effect=ConnectionClosedException,
|
||||||
|
), patch(
|
||||||
|
"systembridgeconnector.websocket_client.WebSocketClient.listen",
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], FIXTURE_AUTH_INPUT
|
result["flow_id"], FIXTURE_AUTH_INPUT
|
||||||
@ -370,11 +442,13 @@ async def test_reauth_flow(hass: HomeAssistant) -> None:
|
|||||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
assert result["step_id"] == "authenticate"
|
assert result["step_id"] == "authenticate"
|
||||||
|
|
||||||
with patch("systembridgeconnector.websocket_client.WebSocketClient.connect"), patch(
|
with patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.get_data"
|
"homeassistant.components.system_bridge.config_flow.WebSocketClient.connect"
|
||||||
), patch(
|
), patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.receive_message",
|
"systembridgeconnector.websocket_client.WebSocketClient.get_data",
|
||||||
return_value=FIXTURE_DATA_SYSTEM,
|
return_value=FIXTURE_DATA_RESPONSE,
|
||||||
|
), patch(
|
||||||
|
"systembridgeconnector.websocket_client.WebSocketClient.listen"
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.system_bridge.async_setup_entry",
|
"homeassistant.components.system_bridge.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
@ -402,11 +476,13 @@ async def test_zeroconf_flow(hass: HomeAssistant) -> None:
|
|||||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
assert not result["errors"]
|
assert not result["errors"]
|
||||||
|
|
||||||
with patch("systembridgeconnector.websocket_client.WebSocketClient.connect"), patch(
|
with patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.get_data"
|
"homeassistant.components.system_bridge.config_flow.WebSocketClient.connect"
|
||||||
), patch(
|
), patch(
|
||||||
"systembridgeconnector.websocket_client.WebSocketClient.receive_message",
|
"systembridgeconnector.websocket_client.WebSocketClient.get_data",
|
||||||
return_value=FIXTURE_DATA_SYSTEM,
|
return_value=FIXTURE_DATA_RESPONSE,
|
||||||
|
), patch(
|
||||||
|
"systembridgeconnector.websocket_client.WebSocketClient.listen"
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.system_bridge.async_setup_entry",
|
"homeassistant.components.system_bridge.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user