Skip to content

Commit

Permalink
Update input device checks (#81)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel McKnight <[email protected]>
  • Loading branch information
NeonDaniel and NeonDaniel authored Apr 11, 2023
1 parent 13cc44b commit 5e38575
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
7 changes: 1 addition & 6 deletions ovos_utils/device_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self) -> None:
if not find_executable("libinput") and not find_executable("xinput"):
LOG.warning("Could not find libinput, input device detection will be inaccurate")

# ToDo: add support for discovring the input device based of a connected
# ToDo: add support for discovering the input device based of a connected
# monitors, currently linux only supports input listing directly from the
# system
def _build_linput_devices_list(self):
Expand Down Expand Up @@ -138,8 +138,3 @@ def can_use_touch_mouse():

def can_use_keyboard():
return InputDeviceHelper().can_use_keyboard()


if __name__ == "__main__":

can_use_touch_mouse()
63 changes: 63 additions & 0 deletions test/unittests/test_device_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import unittest
from unittest import mock
from unittest.mock import Mock


class TestDeviceInput(unittest.TestCase):
def test_input_device_helper(self):
# TODO
pass

@mock.patch('distutils.spawn.find_executable')
def test_can_use_touch_mouse(self, find_exec):
from ovos_utils.device_input import InputDeviceHelper
find_exec.return_value = True
dev_input = InputDeviceHelper()

dev_input._build_linput_devices_list = Mock()
dev_input._build_xinput_devices_list = Mock()

dev_input.libinput_devices_list = [{'Device': 'Mock',
'Capabilities': ['mouse']},
{'Device': "Mock 1",
'Capabilities': ['touch']}
]
self.assertTrue(dev_input.can_use_touch_mouse())

dev_input.libinput_devices_list.pop()
self.assertTrue(dev_input.can_use_touch_mouse())
dev_input.libinput_devices_list.pop()
self.assertFalse(dev_input.can_use_touch_mouse())
dev_input.xinput_devices_list = [{'Device': 'xinput',
'Capabilities': ['tablet']
}]
self.assertTrue(dev_input.can_use_touch_mouse())
dev_input.xinput_devices_list.pop()
self.assertFalse(dev_input.can_use_touch_mouse())

@mock.patch('distutils.spawn.find_executable')
def test_can_use_keyboard(self, find_exec):
from ovos_utils.device_input import InputDeviceHelper
find_exec.return_value = True
dev_input = InputDeviceHelper()

dev_input._build_linput_devices_list = Mock()
dev_input._build_xinput_devices_list = Mock()

dev_input.libinput_devices_list = [{'Device': 'Mock',
'Capabilities': ['keyboard']},
{'Device': "Mock 1",
'Capabilities': ['touch']}
]
self.assertTrue(dev_input.can_use_keyboard())

dev_input.libinput_devices_list.pop()
self.assertTrue(dev_input.can_use_keyboard())
dev_input.libinput_devices_list.pop()
self.assertFalse(dev_input.can_use_keyboard())
dev_input.xinput_devices_list = [{'Device': 'xinput',
'Capabilities': ['keyboard']
}]
self.assertTrue(dev_input.can_use_keyboard())
dev_input.xinput_devices_list.pop()
self.assertFalse(dev_input.can_use_keyboard())

0 comments on commit 5e38575

Please sign in to comment.