Coverage for integrations / remote_desktop / peripheral_backends / base.py: 76.2%

21 statements  

« prev     ^ index     » next       coverage.py v7.14.0, created at 2026-05-12 04:49 +0000

1""" 

2Base class for peripheral forwarding backends. 

3 

4Each backend handles a specific peripheral type (USB, Bluetooth, Gamepad). 

5Backends detect available peripherals, forward them over HARTOS transport, 

6and handle cleanup on disconnect. 

7""" 

8 

9from abc import ABC, abstractmethod 

10from typing import List 

11 

12from integrations.remote_desktop.peripheral_bridge import PeripheralInfo 

13 

14 

15class PeripheralBackend(ABC): 

16 """Abstract base for peripheral forwarding backends.""" 

17 

18 @abstractmethod 

19 def discover(self) -> List[PeripheralInfo]: 

20 """Discover connected peripherals of this type.""" 

21 ... 

22 

23 @abstractmethod 

24 def forward(self, peripheral: PeripheralInfo, transport) -> bool: 

25 """Start forwarding a peripheral over the transport. 

26 

27 Args: 

28 peripheral: The peripheral to forward. 

29 transport: TransportChannel to send events on. 

30 

31 Returns: 

32 True if forwarding started successfully. 

33 """ 

34 ... 

35 

36 @abstractmethod 

37 def stop(self, peripheral_id: str) -> bool: 

38 """Stop forwarding a specific peripheral.""" 

39 ... 

40 

41 @property 

42 @abstractmethod 

43 def available(self) -> bool: 

44 """Whether this backend's system dependencies are available.""" 

45 ... 

46 

47 @property 

48 @abstractmethod 

49 def peripheral_type_name(self) -> str: 

50 """The peripheral type this backend handles (e.g., 'usb', 'bluetooth').""" 

51 ...