Skip to content

Commit

Permalink
Update systembridgeconnector to 3.4.4 (home-assistant#75362)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
  • Loading branch information
timmo001 and MartinHjelmare authored Aug 15, 2022
1 parent c93d9d9 commit 64898af
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 94 deletions.
18 changes: 14 additions & 4 deletions homeassistant/components/system_bridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
ConnectionClosedException,
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
import voluptuous as vol

Expand Down Expand Up @@ -149,29 +153,35 @@ async def handle_open_path(call: ServiceCall) -> None:
coordinator: SystemBridgeDataUpdateCoordinator = hass.data[DOMAIN][
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:
"""Handle the open url service call."""
_LOGGER.info("Open: %s", call.data)
coordinator: SystemBridgeDataUpdateCoordinator = hass.data[DOMAIN][
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:
"""Handle the send_keypress service call."""
coordinator: SystemBridgeDataUpdateCoordinator = hass.data[DOMAIN][
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:
"""Handle the send_keypress service call."""
coordinator: SystemBridgeDataUpdateCoordinator = hass.data[DOMAIN][
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(
DOMAIN,
Expand Down
32 changes: 14 additions & 18 deletions homeassistant/components/system_bridge/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from typing import Any

import async_timeout
from systembridgeconnector.const import EVENT_MODULE, EVENT_TYPE, TYPE_DATA_UPDATE
from systembridgeconnector.exceptions import (
AuthenticationException,
ConnectionClosedException,
ConnectionErrorException,
)
from systembridgeconnector.models.get_data import GetData
from systembridgeconnector.models.system import System
from systembridgeconnector.websocket_client import WebSocketClient
import voluptuous as vol

Expand All @@ -38,7 +39,7 @@
)


async def validate_input(
async def _validate_input(
hass: HomeAssistant,
data: dict[str, Any],
) -> dict[str, str]:
Expand All @@ -56,15 +57,12 @@ async def validate_input(
try:
async with async_timeout.timeout(30):
await websocket_client.connect(session=async_get_clientsession(hass))
await websocket_client.get_data(["system"])
while True:
message = await websocket_client.receive_message()
_LOGGER.debug("Message: %s", message)
if (
message[EVENT_TYPE] == TYPE_DATA_UPDATE
and message[EVENT_MODULE] == "system"
):
break
hass.async_create_task(websocket_client.listen())
response = await websocket_client.get_data(GetData(modules=["system"]))
_LOGGER.debug("Got response: %s", response.json())
if response.data is None or not isinstance(response.data, System):
raise CannotConnect("No data received")
system: System = response.data
except AuthenticationException as exception:
_LOGGER.warning(
"Authentication error when connecting to %s: %s", data[CONF_HOST], exception
Expand All @@ -81,14 +79,12 @@ async def validate_input(
except asyncio.TimeoutError as exception:
_LOGGER.warning("Timed out connecting to %s: %s", data[CONF_HOST], exception)
raise CannotConnect from exception
except ValueError as exception:
raise CannotConnect from exception

_LOGGER.debug("%s Message: %s", TYPE_DATA_UPDATE, message)

if "uuid" not in message["data"]:
error = "No UUID in result!"
raise CannotConnect(error)
_LOGGER.debug("Got System data: %s", system.json())

return {"hostname": host, "uuid": message["data"]["uuid"]}
return {"hostname": host, "uuid": system.uuid}


async def _async_get_info(
Expand All @@ -98,7 +94,7 @@ async def _async_get_info(
errors = {}

try:
info = await validate_input(hass, user_input)
info = await _validate_input(hass, user_input)
except CannotConnect:
errors["base"] = "cannot_connect"
except InvalidAuth:
Expand Down
13 changes: 10 additions & 3 deletions homeassistant/components/system_bridge/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections.abc import Callable
from datetime import timedelta
import logging
from typing import Any

import async_timeout
from pydantic import BaseModel # pylint: disable=no-name-in-module
Expand All @@ -17,8 +18,10 @@
from systembridgeconnector.models.cpu import Cpu
from systembridgeconnector.models.disk import Disk
from systembridgeconnector.models.display import Display
from systembridgeconnector.models.get_data import GetData
from systembridgeconnector.models.gpu import Gpu
from systembridgeconnector.models.memory import Memory
from systembridgeconnector.models.register_data_listener import RegisterDataListener
from systembridgeconnector.models.system import System
from systembridgeconnector.websocket_client import WebSocketClient

Expand Down Expand Up @@ -93,12 +96,14 @@ async def async_get_data(
if not self.websocket_client.connected:
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(
self,
module_name: str,
module,
module: Any,
) -> None:
"""Handle data from the WebSocket client."""
self.logger.debug("Set new data for: %s", module_name)
Expand Down Expand Up @@ -174,7 +179,9 @@ async def _setup_websocket(self) -> None:

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.async_update_listeners()
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/system_bridge/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "System Bridge",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/system_bridge",
"requirements": ["systembridgeconnector==3.3.2"],
"requirements": ["systembridgeconnector==3.4.4"],
"codeowners": ["@timmo001"],
"zeroconf": ["_system-bridge._tcp.local."],
"after_dependencies": ["zeroconf"],
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@ swisshydrodata==0.1.0
synology-srm==0.2.0

# homeassistant.components.system_bridge
systembridgeconnector==3.3.2
systembridgeconnector==3.4.4

# homeassistant.components.tailscale
tailscale==0.2.0
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ sunwatcher==0.2.1
surepy==0.7.2

# homeassistant.components.system_bridge
systembridgeconnector==3.3.2
systembridgeconnector==3.4.4

# homeassistant.components.tailscale
tailscale==0.2.0
Expand Down
Loading

0 comments on commit 64898af

Please sign in to comment.