diff --git a/supervisor/homeassistant/module.py b/supervisor/homeassistant/module.py index e5e3b8866..a7ba03f4a 100644 --- a/supervisor/homeassistant/module.py +++ b/supervisor/homeassistant/module.py @@ -18,13 +18,17 @@ from ..const import ( ATTR_PORT, ATTR_REFRESH_TOKEN, ATTR_SSL, + ATTR_TYPE, ATTR_UUID, ATTR_VERSION, ATTR_WAIT_BOOT, ATTR_WATCHDOG, FILE_HASSIO_HOMEASSISTANT, + BusEvent, ) from ..coresys import CoreSys, CoreSysAttributes +from ..hardware.const import PolicyGroup +from ..hardware.data import Device from ..utils.common import FileConfiguration from .api import HomeAssistantAPI from .core import HomeAssistantCore @@ -238,6 +242,9 @@ class HomeAssistant(FileConfiguration, CoreSysAttributes): """Prepare Home Assistant object.""" await asyncio.wait([self.secrets.load(), self.core.load()]) + # Register for events + self.sys_bus.register_event(BusEvent.HARDWARE_NEW_DEVICE, self._hardware_events) + def write_pulse(self): """Write asound config to file and return True on success.""" pulse_config = self.sys_plugins.audio.pulse_client( @@ -256,3 +263,20 @@ class HomeAssistant(FileConfiguration, CoreSysAttributes): _LOGGER.error("Home Assistant can't write pulse/client.config: %s", err) else: _LOGGER.info("Update pulse/client.config: %s", self.path_pulse) + + async def _hardware_events(self, device: Device) -> None: + """Process hardware requests.""" + if ( + not self.sys_hardware.policy.is_match_cgroup(PolicyGroup.UART, device) + or not self.version + or self.version < "2021.9.0" + ): + return + + configuration = await self.sys_homeassistant.websocket.async_send_command( + {ATTR_TYPE: "get_config"} + ) + if not configuration or "usb" not in configuration.get("components", []): + return + + self.sys_homeassistant.websocket.send_command({ATTR_TYPE: "usb/scan"})