Fixed preset name expansion for remote presets

This commit is contained in:
Shy 2017-03-13 14:09:38 +01:00
parent 3f9da0e663
commit 47e9811a96

View file

@ -378,9 +378,6 @@ class Kitchenlight:
return self.pacman() return self.pacman()
if mode == "sine": if mode == "sine":
return self.sine() return self.sine()
# Evil strobo harms the Kitchenlight
#if mode == "strobo":
# return self.strobo()
if mode == "text": if mode == "text":
return self.text(*opts) return self.text(*opts)
if mode == "flood": if mode == "flood":
@ -492,8 +489,6 @@ class Kitchenlight:
v[0:4] = int(8).to_bytes(4, "little") v[0:4] = int(8).to_bytes(4, "little")
v[4:8] = int(delay).to_bytes(4, "little") v[4:8] = int(delay).to_bytes(4, "little")
v[8:8 + len(text)] = text v[8:8 + len(text)] = text
#for i in range(len(text)):
# v[i+8:i+9] = int(text[i]).to_bytes(1, "little")
v[len(d) - 1:len(d)] = bytes(1) v[len(d) - 1:len(d)] = bytes(1)
self._switch(d) self._switch(d)
@ -785,8 +780,21 @@ class RemotePresets:
<rooms> must be a list of rooms to consider. <rooms> must be a list of rooms to consider.
<available> must be a dict as returned by query_available().""" <available> must be a dict as returned by query_available()."""
# We need to take care to match only presets which are available for # We need to take care to match only presets which are available for
# every room # every room specified
# Strip every "global" out of the room list. We take special care of
# global later on.
while "global" in rooms:
rooms.remove("global")
matchtable = {} matchtable = {}
if "global" not in rooms:
for preset in available["global"]:
# Candidate?
if preset == name or preset.find(name) == 0:
# Presets in "global" are available everywhere
matchtable[preset] = len(rooms)
for room in rooms: for room in rooms:
for preset in available[room]: for preset in available[room]:
# Candidate? # Candidate?
@ -796,12 +804,14 @@ class RemotePresets:
else: else:
matchtable[preset] = 1 matchtable[preset] = 1
# First check if there is an exact match # First check if there is an exact match in all rooms
if name in matchtable.keys() and matchtable[name] == len(rooms): if name in matchtable.keys() and matchtable[name] >= len(rooms):
return name return name
# Return first preset available in all rooms # Return first preset available in all rooms
for match in matchtable.keys(): for match in matchtable.keys():
if matchtable[match] == len(rooms): if matchtable[match] >= len(rooms):
return match
elif match in available["global"]:
return match return match
# Fallback # Fallback
return name return name