| 1 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 |
|
| 3 |
import logging |
| 4 |
import re |
| 5 |
import subprocess |
| 6 |
|
| 7 |
from odoo.addons.iot_drivers.interface import Interface |
| 8 |
|
| 9 |
_logger = logging.getLogger(__name__) |
| 10 |
|
| 11 |
|
| 12 |
class DisplayInterface(Interface): |
| 13 |
_loop_delay = 3 |
| 14 |
connection_type = 'display' |
| 15 |
|
| 16 |
def get_devices(self): |
| 17 |
randr_result = subprocess.run(['wlr-randr'], capture_output=True, text=True, check=False) |
| 18 |
if randr_result.returncode != 0: |
| 19 |
return {} |
| 20 |
displays = re.findall(r"\((HDMI-A-\d)\)", randr_result.stdout) |
| 21 |
return { |
| 22 |
monitor: self._add_device(monitor, x_screen) |
| 23 |
for x_screen, monitor in enumerate(displays) |
| 24 |
} |
| 25 |
|
| 26 |
@classmethod |
| 27 |
def _add_device(cls, display_identifier, x_screen): |
| 28 |
"""Creates a display_device dict. |
| 29 |
|
| 30 |
:param display_identifier: the identifier of the display |
| 31 |
:param x_screen: the x screen number |
| 32 |
:return: the display device dict |
| 33 |
""" |
| 34 |
|
| 35 |
return { |
| 36 |
'identifier': display_identifier, |
| 37 |
'name': 'Display - ' + display_identifier, |
| 38 |
'x_screen': str(x_screen), |
| 39 |
} |