Correct linting errors and tests

remotes/origin/extra-event-options
Phil Howard 2020-03-25 11:08:10 +00:00
parent e5a18757ba
commit 9499f2e6ee
2 changed files with 8 additions and 5 deletions

View File

@ -12,7 +12,9 @@ class ValidList(list):
class PinConfig(config.ConfigValue):
tuple_pinconfig = namedtuple("PinConfig", ("event", "active", "bouncetime", "options"))
tuple_pinconfig = namedtuple(
"PinConfig", ("event", "active", "bouncetime", "options")
)
valid_events = ValidList(
["play_pause", "prev", "next", "volume_up", "volume_down"]
@ -31,7 +33,8 @@ class PinConfig(config.ConfigValue):
value = value.split(",")
if len(value) < 3: # At least Event, Active and Bouncetime settings required
# At least Event, Active and Bouncetime settings required
if len(value) < 3:
return None
event, active, bouncetime = value[0:3]
@ -64,6 +67,6 @@ class PinConfig(config.ConfigValue):
def serialize(self, value, display=False):
if value is None:
return ""
options = ",".join({f'{k}={v}' for k, v in value.options.items()})
value = f"{value.event},{value.active},{value.bouncetime}"
options = ",".join({f"{k}={v}" for k, v in value.options.items()})
value = f"{value.event},{value.active},{value.bouncetime},{options}"
return types.encode(value)

View File

@ -76,4 +76,4 @@ def test_pinconfig_serialize():
schema = ext.get_config_schema()
bcm1 = schema["bcm1"].deserialize("volume_up,active_low,30,steps=1")
assert bcm1.serialize() == "volume_up,active_low,30,steps=1"
assert schema["bcm1"].serialize(bcm1) == "volume_up,active_low,30,steps=1"