Prepare refactoring of NotificationFlag
Ensure behavior stays the same. Related #2273
This commit is contained in:
parent
5f5c7cdcce
commit
571cdb5f2d
|
@ -14,6 +14,8 @@
|
|||
## You should have received a copy of the GNU General Public License along
|
||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import IntEnum
|
||||
|
||||
from .common import NamedInts
|
||||
|
@ -89,6 +91,16 @@ NOTIFICATION_FLAG = NamedInts(
|
|||
)
|
||||
|
||||
|
||||
def flags_to_str(flag_bits: int | None, fallback: str) -> str:
|
||||
flag_names = []
|
||||
if flag_bits is not None:
|
||||
if flag_bits == 0:
|
||||
flag_names = (fallback,)
|
||||
else:
|
||||
flag_names = list(NOTIFICATION_FLAG.flag_names(flag_bits))
|
||||
return f"\n{' ':15}".join(flag_names)
|
||||
|
||||
|
||||
class ErrorCode(IntEnum):
|
||||
INVALID_SUB_ID_COMMAND = 0x01
|
||||
INVALID_ADDRESS = 0x02
|
||||
|
|
|
@ -551,10 +551,8 @@ def _update_details(button):
|
|||
|
||||
flag_bits = device.notification_flags
|
||||
if flag_bits is not None:
|
||||
flag_names = (
|
||||
(f"({_('none')})",) if flag_bits == 0 else hidpp10_constants.NOTIFICATION_FLAG.flag_names(flag_bits)
|
||||
)
|
||||
yield _("Notifications"), f"\n{' ':15}".join(flag_names)
|
||||
flag_names = hidpp10_constants.flags_to_names(flag_bits, fallback=f"({_('none')})")
|
||||
yield _("Notifications"), flag_names
|
||||
|
||||
def _set_details(text):
|
||||
_details._text.set_markup(text)
|
||||
|
|
|
@ -274,6 +274,25 @@ def test_set_notification_flags_bad(mocker):
|
|||
assert result is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"flag_bits, expected_names",
|
||||
[
|
||||
(None, ""),
|
||||
(0x0, "none"),
|
||||
(0x009020, "multi touch\n unknown:008020"),
|
||||
(0x080000, "mouse extra buttons"),
|
||||
(
|
||||
0x080000 + 0x000400,
|
||||
("link quality\n mouse extra buttons"),
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_notification_flag_str(flag_bits, expected_names):
|
||||
flag_names = hidpp10_constants.flags_to_str(flag_bits, fallback="none")
|
||||
|
||||
assert flag_names == expected_names
|
||||
|
||||
|
||||
def test_get_device_features():
|
||||
result = _hidpp10.get_device_features(device_standard)
|
||||
|
||||
|
|
Loading…
Reference in New Issue