Skip to content

Commit

Permalink
Recover keyboard state after message sequence (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaskivskyi committed Sep 17, 2022
1 parent e5233cb commit b81ca13
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion aiochroma/aiochroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ class AIOChroma:
"""AIOChroma class"""

def __init__(
self, host: str, targets: list["str"], layout: str, session: aiohttp.ClientSession | None = None
self,
host: str,
targets: list["str"],
layout: str,
session: aiohttp.ClientSession | None = None,
):
"""Initialize AIOChroma module"""

Expand Down Expand Up @@ -256,6 +260,14 @@ async def async_keyboard_sequence(
) -> None:
"""Send a key sequence"""

_LOGGER.debug(
f"Starting `keyboard_seqyence` with message=`{message}`, color=`{color}`, background=`{background}`, brightness=`{brightness}`, tail=`{tail}`, repeats=`{repeats}`, spacing=`{spacing}`, sleep=`{sleep}`"
)

# Get previous keyboard state
was = self._state["keyboard"].copy()
_LOGGER.debug(f"Previous keyboard state: {was}")

# Parse the message
keys = await self.async_parse_message(message)

Expand Down Expand Up @@ -316,6 +328,15 @@ async def async_keyboard_sequence(

el += 1

# Recover previous state
_LOGGER.debug(f"Recovering keyboard state: {was}")
if was["state"]:
await self.async_effect_color(
target="keyboard", color=was["color"], brightness=was["brightness"]
)
else:
await self.async_effect_none(target="keyboard")

### <-- KEYBOARD

### ACTIONS -->
Expand Down

0 comments on commit b81ca13

Please sign in to comment.