Skip to content

Commit

Permalink
Test key_is_down
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHag committed Oct 13, 2024
1 parent 15659a1 commit e9bbc55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/logitech_receiver/diversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1478,15 +1478,15 @@ def data(self):
)


def key_is_down(key):
def key_is_down(key: NamedInt) -> bool:
"""Checks if given key is pressed or not."""
if key == CONTROL.MR:
return mr_key_down
elif CONTROL.M1 <= key <= CONTROL.M8:
return bool(m_keys_down & (0x01 << (key - CONTROL.M1)))
elif CONTROL.G1 <= key <= CONTROL.G32:
return bool(g_keys_down & (0x01 << (key - CONTROL.G1)))
else:
return key in keys_down
return key in keys_down


def evaluate_rules(feature, notification: HIDPPNotification, device):
Expand Down
6 changes: 6 additions & 0 deletions tests/logitech_receiver/test_diversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,9 @@ def test_diversion_rule():
assert isinstance(key, diversion.Key)
key = component.components[1]
assert isinstance(key, diversion.KeyPress)


def test_key_is_down():
result = diversion.key_is_down(key=diversion.CONTROL.G2)

assert result is False

0 comments on commit e9bbc55

Please sign in to comment.