add audio and bluetooth commands, remove paramiko exception in config flow

This commit is contained in:
Mathieu Broillet 2024-08-26 19:01:32 +02:00
parent bc16d06ac6
commit 3fc5fb948f
Signed by: mathieu
GPG Key ID: A08E484FE95074C1
4 changed files with 15 additions and 9 deletions

View File

@ -16,7 +16,7 @@ from homeassistant.core import HomeAssistant, ServiceCall
from .const import DOMAIN, SERVICE_SEND_MAGIC_PACKET, SERVICE_CHANGE_MONITORS_CONFIG from .const import DOMAIN, SERVICE_SEND_MAGIC_PACKET, SERVICE_CHANGE_MONITORS_CONFIG
_LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
WAKE_ON_LAN_SEND_MAGIC_PACKET_SCHEMA = vol.Schema({ WAKE_ON_LAN_SEND_MAGIC_PACKET_SCHEMA = vol.Schema({
vol.Required(CONF_MAC): cv.string, vol.Required(CONF_MAC): cv.string,
@ -40,7 +40,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
if broadcast_port is not None: if broadcast_port is not None:
service_kwargs["port"] = broadcast_port service_kwargs["port"] = broadcast_port
_LOGGER.info( LOGGER.info(
"Sending magic packet to MAC %s (broadcast: %s, port: %s)", "Sending magic packet to MAC %s (broadcast: %s, port: %s)",
mac_address, mac_address,
broadcast_address, broadcast_address,

View File

@ -7,7 +7,6 @@ from typing import Any
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries, exceptions from homeassistant import config_entries, exceptions
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from paramiko.ssh_exception import AuthenticationException
from .computer import Computer from .computer import Computer
from .const import DOMAIN from .const import DOMAIN
@ -54,7 +53,7 @@ class Hub:
_LOGGER.info("Testing connection to %s", self._host) _LOGGER.info("Testing connection to %s", self._host)
return True return True
except AuthenticationException: except Exception:
return False return False
@ -86,7 +85,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
try: try:
info = await validate_input(self.hass, user_input) info = await validate_input(self.hass, user_input)
return self.async_create_entry(title=info["title"], data=user_input) return self.async_create_entry(title=info["title"], data=user_input)
except (AuthenticationException, CannotConnect, InvalidHost) as ex: except (CannotConnect, InvalidHost) as ex:
errors["base"] = str(ex) errors["base"] = str(ex)
except Exception as ex: # pylint: disable=broad-except except Exception as ex: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception: %s", ex) _LOGGER.exception("Unexpected exception: %s", ex)

View File

@ -43,5 +43,15 @@ ACTIONS = {
}, },
"get_monitors_config": { "get_monitors_config": {
"linux": ["gnome-monitor-config list"] "linux": ["gnome-monitor-config list"]
},
"get_speakers": {
"linux": ["pactl list sinks"]
},
"get_microphones": {
"linux": ["pactl list sources"]
},
"get_bluetooth_devices": {
"exit": False,
"linux": ["bluetoothctl info"]
} }
} }

View File

@ -3,7 +3,6 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
import logging
from typing import Any from typing import Any
import voluptuous as vol import voluptuous as vol
@ -31,8 +30,6 @@ from .const import SERVICE_RESTART_TO_WINDOWS_FROM_LINUX, SERVICE_PUT_COMPUTER_T
SERVICE_START_COMPUTER_TO_WINDOWS, SERVICE_RESTART_COMPUTER, SERVICE_RESTART_TO_LINUX_FROM_WINDOWS, \ SERVICE_START_COMPUTER_TO_WINDOWS, SERVICE_RESTART_COMPUTER, SERVICE_RESTART_TO_LINUX_FROM_WINDOWS, \
SERVICE_CHANGE_MONITORS_CONFIG, SERVICE_STEAM_BIG_PICTURE, SERVICE_CHANGE_AUDIO_CONFIG, SERVICE_DEBUG_INFO, DOMAIN SERVICE_CHANGE_MONITORS_CONFIG, SERVICE_STEAM_BIG_PICTURE, SERVICE_CHANGE_AUDIO_CONFIG, SERVICE_DEBUG_INFO, DOMAIN
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, hass: HomeAssistant,
@ -225,6 +222,6 @@ class ComputerSwitch(SwitchEntity):
"operating_system_version": self.computer.get_operating_system_version(), "operating_system_version": self.computer.get_operating_system_version(),
"mac_address": self.computer.mac, "mac_address": self.computer.mac,
"ip_address": self.computer.host, "ip_address": self.computer.host,
"connected_devices": self.computer.get_bluetooth_devices(as_str=True), "connected_devices": self.computer.get_bluetooth_devices(return_as_string=True),
} }