Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recover keyboard state after message sequence #4

Merged
merged 1 commit into from
Sep 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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