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

Fix KeyError when sceneId is missing #114

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions pywizlight/bulb.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ def get_scene(self) -> Optional[str]:
"""Get the current scene name."""
if "schdPsetId" in self.pilotResult: # rhythm
return SCENES[1000]
if "sceneId" not in self.pilotResult:
return None
return SCENES.get(self.pilotResult["sceneId"])

def get_cold_white(self) -> Optional[int]:
Expand Down
12 changes: 12 additions & 0 deletions pywizlight/tests/test_bulb.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ async def test_PilotBuilder_scene(correct_bulb: wizlight) -> None:
state = await correct_bulb.updateState()

assert state and state.get_scene() == SCENES[1]
state.pilotResult["schdPsetId"] = True
assert state.get_scene() == SCENES[1000]


@pytest.mark.asyncio
async def test_PilotBuilder_scene_empty(correct_bulb: wizlight) -> None:
"""Test scene with no scene set."""
state = await correct_bulb.updateState()
assert state is not None
if "sceneId" in state.pilotResult:
del state.pilotResult["sceneId"]
assert state and state.get_scene() is None


@pytest.mark.asyncio
Expand Down