Skip to content
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
43 changes: 43 additions & 0 deletions ring_doorbell/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
RingDoorBell,
RingEvent,
RingGeneric,
RingStickUpCam,
RingOther,
RingCapability,
)
from ring_doorbell.const import (
CLI_TOKEN_FILE,
Expand Down Expand Up @@ -384,6 +386,47 @@ async def motion_detection(ctx, ring: Ring, device_name, turn_on, turn_off):
return None


@cli.command()
@pass_ring
@click.pass_context
@click.argument("enable", type=click.BOOL, default=None, required=False)
@click.option(
"--device-name",
"-dn",
required=True,
default=None,
help="Name of the ring device",
)
async def light(ctx, ring: Ring, device_name, enable):
"""Get and change the light state of a device."""
device = ring.get_device_by_name(device_name)

if not device:
echo(
f"No device with name {device_name} found."
+ " List of found device names (kind) is:"
)
return await ctx.invoke(list_command)
if not device.has_capability(RingCapability.LIGHT):
echo(f"{device!s} does not have a light")
return None
device = cast(RingStickUpCam, device)
state = "on" if device.light else "off"
if enable is None:
echo(f"{device!s} light is {state}")
return None
is_on = device.light
if (enable and is_on) or (not enable and not is_on):
echo(f"{device!s} light is already {state}")
return None

await device.async_set_light(enable)
await ring.async_update_devices()
state = "on" if device.light else "off"
echo(f"{device!s} light set to {state}")
return None


@cli.command()
@click.option(
"--device-name",
Expand Down
11 changes: 11 additions & 0 deletions ring_doorbell/stickup_cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ async def async_set_lights(self, state: str) -> None:
url = LIGHTS_ENDPOINT.format(self.device_api_id, state)
await self._ring.async_query(url, method="PUT")

@property
def light(self) -> bool:
"""Return lights status."""
return self._attrs.get("led_status", "") == "on"

async def async_set_light(self, value: bool) -> None: # noqa: FBT001
"""Control the lights."""
state = "on" if value else "off"
url = LIGHTS_ENDPOINT.format(self.device_api_id, state)
await self._ring.async_query(url, method="PUT")

@property
def siren(self) -> int:
"""Return siren status."""
Expand Down