Skip to content

Commit

Permalink
Merge pull request #137 from bdraco/fix_close_cli
Browse files Browse the repository at this point in the history
Ensure cli closes the bulb out
  • Loading branch information
sbidy committed Feb 21, 2022
2 parents f7fad08 + 18a83cc commit b474f6e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pywizlight/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ async def turn_on(ip: str, k: int, brightness: int) -> None:
await bulb.turn_on(PilotBuilder(colortemp=k, brightness=brightness))
else:
click.echo("Error - values are not correct. Type --help for help.")
await bulb.async_close()


@main.command("set-state")
Expand All @@ -93,6 +94,7 @@ async def set_state(ip: str, k: int, brightness: int) -> None:
await bulb.set_state(PilotBuilder(colortemp=k, brightness=brightness))
else:
click.echo("Error - values are not correct. Type --help for help.")
await bulb.async_close()


@main.command("off")
Expand All @@ -103,6 +105,7 @@ async def turn_off(ip: str) -> None:
click.echo(f"Turning off {ip}")
bulb = wizlight(ip)
await bulb.turn_off()
await bulb.async_close()


@main.command("state")
Expand All @@ -111,11 +114,13 @@ async def turn_off(ip: str) -> None:
async def state(ip: str) -> None:
"""Get the current state of a given bulb."""
click.echo(f"Get the state from {ip}")
bulb_state = await wizlight(ip).updateState()
bulb = wizlight(ip)
bulb_state = await bulb.updateState()
if bulb_state:
click.echo(bulb_state.pilotResult)
else:
click.echo("Did not get state from bulb")
await bulb.async_close()


if __name__ == "__main__":
Expand Down

0 comments on commit b474f6e

Please sign in to comment.