Fixed various mypy problems (#642)

pull/641/head
Tobi 1 year ago committed by GitHub
parent de0dd8af8e
commit b325598268
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -286,7 +286,11 @@ def _input_combination_from_string(combination_string: str) -> InputCombination:
for event_str in combination_string.split("+"):
type_, code, analog_threshold = event_str.split(",")
configs.append(
{"type": type_, "code": code, "analog_threshold": analog_threshold}
{
"type": int(type_),
"code": int(code),
"analog_threshold": int(analog_threshold),
}
)
return InputCombination(configs)

@ -433,7 +433,7 @@ class Daemon:
for group_key, _ in autoload_presets:
self._autoload(group_key)
def start_injecting(self, group_key: str, preset: str) -> bool:
def start_injecting(self, group_key: str, preset_name: str) -> bool:
"""Start injecting the preset for the device.
Returns True on success. If an injection is already ongoing for
@ -443,7 +443,7 @@ class Daemon:
----------
group_key
The unique key of the group
preset
preset_name
The name of the preset
"""
logger.info('Request to start injecting for "%s"', group_key)
@ -467,7 +467,7 @@ class Daemon:
self.config_dir,
"presets",
sanitize_path_component(group.name),
f"{preset}.json",
f"{preset_name}.json",
)
# Path to a dump of the xkb mappings, to provide more human

@ -938,22 +938,26 @@ class OutputAxisSelector:
self._message_broker.subscribe(MessageType.mapping, self._on_mapping_message)
self._message_broker.subscribe(MessageType.uinputs, self._on_uinputs_message)
def _set_model(self, target: str):
def _set_model(self, target: Optional[str]):
if target == self._current_target:
return
capabilities = self._uinputs.get(target) or defaultdict(list)
types_codes = [
(EV_ABS, code) for code, absinfo in capabilities.get(EV_ABS) or ()
]
types_codes.extend((EV_REL, code) for code in capabilities.get(EV_REL) or ())
self.model.clear()
self.model.append(["None, None", _("No Axis")])
for type_, code in types_codes:
key_name = get_evdev_constant_name(type_, code)
if isinstance(key_name, list):
key_name = key_name[0]
self.model.append([f"{type_}, {code}", key_name])
if target is not None:
capabilities = self._uinputs.get(target) or defaultdict(list)
types_codes = [
(EV_ABS, code) for code, absinfo in capabilities.get(EV_ABS) or ()
]
types_codes.extend(
(EV_REL, code) for code in capabilities.get(EV_REL) or ()
)
for type_, code in types_codes:
key_name = get_evdev_constant_name(type_, code)
if isinstance(key_name, list):
key_name = key_name[0]
self.model.append([f"{type_}, {code}", key_name])
self._current_target = target

@ -803,8 +803,7 @@ class Controller:
try:
analog_input = tuple(
filter(lambda i: i.defines_analog_input, mapping.input_combination)
)
analog_input = analog_input[0]
)[0]
except IndexError:
changes["output_type"] = None
changes["output_code"] = None

@ -224,7 +224,7 @@ class DataManager:
self._config.set_autoload_preset(
self.active_group.key, self.active_preset.name
)
elif self.get_autoload:
elif self.get_autoload():
self._config.set_autoload_preset(self.active_group.key, None)
self.publish_preset()

@ -79,10 +79,8 @@ class ReaderClient:
self.group: Optional[_Group] = None
self._recording_generator: Optional[RecordingGenerator] = None
self._results_pipe = None
self._commands_pipe = None
self._results_pipe, self._commands_pipe = self.connect()
self.connect()
self.attach_to_events()
self._read_timeout = GLib.timeout_add(30, self._read)
@ -124,8 +122,9 @@ class ReaderClient:
def connect(self):
"""Connect to the reader-service."""
self._results_pipe = Pipe(get_pipe_paths()[0])
self._commands_pipe = Pipe(get_pipe_paths()[1])
results_pipe = Pipe(get_pipe_paths()[0])
commands_pipe = Pipe(get_pipe_paths()[1])
return results_pipe, commands_pipe
def attach_to_events(self):
"""Connect listeners to event_reader."""
@ -252,7 +251,7 @@ class ReaderClient:
)
)
def set_group(self, group: _Group):
def set_group(self, group: Optional[_Group]):
"""Set the group for which input events should be read later."""
# TODO load the active_group from the controller instead?
self.group = group

@ -63,6 +63,7 @@ class AbsToAbsHandler(MappingHandler):
self._output_axis = (mapping.output_type, mapping.output_code)
target_uinput = global_uinputs.get_uinput(mapping.target_uinput)
assert target_uinput is not None
abs_capabilities = target_uinput.capabilities(absinfo=True)[EV_ABS]
self._target_absinfo = dict(abs_capabilities)[mapping.output_code]

@ -50,6 +50,7 @@ class MacroHandler(MappingHandler):
):
super().__init__(combination, mapping)
self._active = False
assert self.mapping.output_symbol is not None
self._macro = parse(self.mapping.output_symbol, context, mapping)
def __str__(self):

@ -88,6 +88,7 @@ class RelToAbsHandler(MappingHandler):
self._output_axis = (mapping.output_type, mapping.output_code)
target_uinput = global_uinputs.get_uinput(mapping.target_uinput)
assert target_uinput is not None
abs_capabilities = target_uinput.capabilities(absinfo=True)[EV_ABS]
self._target_absinfo = dict(abs_capabilities)[mapping.output_code]
@ -161,7 +162,6 @@ class RelToAbsHandler(MappingHandler):
self,
event: InputEvent,
source: evdev.InputDevice,
forward_to: evdev.UInput = None,
suppress: bool = False,
) -> bool:
self._observe_rate(event)

@ -95,6 +95,8 @@ class RelToRelHandler(MappingHandler):
) -> None:
super().__init__(combination, mapping)
assert self.mapping.output_code is not None
# find the input event we are supposed to map. If the input combination is
# BTN_A + REL_X + BTN_B, then use the value of REL_X for the transformation
input_config = combination.find_analog_input_config(type_=EV_REL)
@ -133,7 +135,6 @@ class RelToRelHandler(MappingHandler):
self,
event: InputEvent,
source: evdev.InputDevice,
forward_to: evdev.UInput = None,
suppress: bool = False,
) -> bool:
if not self._should_map(event):

@ -224,7 +224,7 @@ class InputEvent:
type_: Optional[int] = None,
code: Optional[int] = None,
value: Optional[int] = None,
actions: Tuple[EventActions, ...] = None,
actions: Optional[Tuple[EventActions, ...]] = None,
origin_hash: Optional[str] = None,
) -> InputEvent:
"""Return a new modified event."""

@ -21,13 +21,11 @@
from __future__ import annotations
import os
import sys
import shutil
import time
import asyncio
import psutil
from pickle import UnpicklingError
from unittest.mock import patch
# don't import anything from input_remapper gloablly here, because some files execute
# code when imported, which can screw up patches. I wish we had a dependency injection

@ -113,7 +113,7 @@ class MacroTestBase(unittest.IsolatedAsyncioTestCase):
# this still might cause race conditions and the test to fail
await asyncio.sleep(0)
if macro.is_holding:
if macro.is_holding():
macro.release_trigger()

Loading…
Cancel
Save