forked from drath/libratbag
device: switch the capabilities to an enum
Strings can suffer from locale issues, the official recommendation for DBus APIs is to use enums here. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
@@ -77,9 +77,17 @@ def find_button(r, args):
|
||||
def show_device(r, args):
|
||||
d = find_device(r, args)
|
||||
|
||||
|
||||
caps = { RatbagdDevice.CAP_SWITCHABLE_RESOLUTION : "switchable-resolution",
|
||||
RatbagdDevice.CAP_SWITCHABLE_PROFILE : "switchable-profile",
|
||||
RatbagdDevice.CAP_BUTTON_KEY : "button-keys",
|
||||
RatbagdDevice.CAP_BUTTON_MACROS : "button-macros",
|
||||
RatbagdDevice.CAP_DEFAULT_PROFILE : "default-profile" }
|
||||
capabilities = [caps[c] for c in d.capabilities]
|
||||
|
||||
print("{} - {}".format(d.id, d.description))
|
||||
print(" SVG: {}".format(d.svg))
|
||||
print(" Capabilities: {}".format(", ".join(d.capabilities)))
|
||||
print(" Capabilities: {}".format(", ".join(capabilities)))
|
||||
print("Number of Profiles: {}".format(len(d.profiles)))
|
||||
active = -1
|
||||
for i, p in enumerate(d.profiles):
|
||||
|
||||
@@ -76,6 +76,12 @@ class Ratbagd(_RatbagdDBus):
|
||||
return self._devices
|
||||
|
||||
class RatbagdDevice(_RatbagdDBus):
|
||||
CAP_SWITCHABLE_RESOLUTION = 1
|
||||
CAP_SWITCHABLE_PROFILE = 2
|
||||
CAP_BUTTON_KEY = 3
|
||||
CAP_BUTTON_MACROS = 4
|
||||
CAP_DEFAULT_PROFILE = 5
|
||||
|
||||
"""
|
||||
Represents a ratbagd device.
|
||||
"""
|
||||
@@ -93,16 +99,7 @@ class RatbagdDevice(_RatbagdDBus):
|
||||
self._profiles = [RatbagdProfile(objpath) for objpath in result]
|
||||
self._active_profile = self.dbus_property("ActiveProfile")
|
||||
|
||||
caps = [ "switchable-resolution",
|
||||
"switchable-profile",
|
||||
"button-keys",
|
||||
"button-macros",
|
||||
"default-profile"]
|
||||
self._caps = []
|
||||
for c in caps:
|
||||
cname = "Cap" + "".join([n.capitalize() for n in c.split("-")])
|
||||
if self.dbus_property(cname):
|
||||
self._caps.append(c)
|
||||
self._caps = self.dbus_property("Capabilities")
|
||||
|
||||
@property
|
||||
def profiles(self):
|
||||
@@ -154,14 +151,10 @@ class RatbagdDevice(_RatbagdDBus):
|
||||
@property
|
||||
def capabilities(self):
|
||||
"""
|
||||
Return the capabilities of this device as a list of identifier strings.
|
||||
Return the capabilities of this device as an array.
|
||||
Capabilities not present on the device are not in the list. Thus use
|
||||
if "capability" is in deivce.caps:
|
||||
if "capability" is in device.caps:
|
||||
do something
|
||||
|
||||
Capabilities supported: "switchable-resolution",
|
||||
"switchable-profile", "button-keys", "button-macros",
|
||||
"default-profile"
|
||||
"""
|
||||
return self._caps
|
||||
|
||||
|
||||
Reference in New Issue
Block a user