Skip to content

Commit

Permalink
snmp: drop return values for power control methods
Browse files Browse the repository at this point in the history
Signed-off-by: Benny Zlotnik <[email protected]>
  • Loading branch information
bennyz committed Feb 6, 2025
1 parent 020a085 commit 0bb3e36
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
6 changes: 3 additions & 3 deletions docs/source/api-reference/drivers/snmp.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ Turn power off for the configured outlet.
Returns:
- str: Confirmation message
#### cycle(quiescent_period: int = 2)
#### cycle(wait: int = 2)
Power cycle the device with a configurable wait period between off and on states.
Parameters:
- quiescent_period: Time to wait in seconds between power off and power on
- wait: Time to wait in seconds between power off and power on
Returns:
- str: Confirmation message
Expand All @@ -66,7 +66,7 @@ Returns:
Power cycling a device:
```python
snmp_client.cycle(quiescent_period=3)
snmp_client.cycle(wait=3)
```

Basic power control:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@


class PowerClient(DriverClient):
def on(self) -> str:
return self.call("on")
def on(self):
self.call("on")

def off(self) -> str:
return self.call("off")
def off(self):
self.call("off")

def cycle(self, quiescent_period: int = 2) -> str:
def cycle(self, wait: int = 2):
"""Power cycle the device"""
self.logger.info("Starting power cycle sequence")
self.off()
self.logger.info(f"Waiting {quiescent_period} seconds...")
time.sleep(quiescent_period)
self.logger.info(f"Waiting {wait} seconds...")
time.sleep(wait)
self.on()
self.logger.info("Power cycle sequence complete")
return "Power cycled"

def read(self) -> Generator[PowerReading, None, None]:
for v in self.streamingcall("read"):
Expand All @@ -37,17 +36,19 @@ def base():
@base.command()
def on():
"""Power on"""
click.echo(self.on())
self.on()
click.echo("Powered on")

@base.command()
def off():
"""Power off"""
click.echo(self.off())
self.off()
click.echo("Powered off")

@base.command()
@click.option('--wait', '-w', default=2, help='Wait time in seconds between off and on')
def cycle(wait):
"""Power cycle"""
click.echo(self.cycle(wait))

click.echo(f"Power cycling with {wait} seconds wait time...")
self.cycle(wait)
return base
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

def test_client_mock_power():
with serve(MockPower()) as client:
assert client.on() == "ok"
assert client.off() == "ok"

assert list(client.read()) == [
PowerReading(voltage=0.0, current=0.0),
PowerReading(voltage=5.0, current=2.0),
Expand All @@ -16,9 +13,6 @@ def test_client_mock_power():

def test_client_sync_mock_power():
with serve(SyncMockPower()) as client:
assert client.on() == "ok"
assert client.off() == "ok"

assert list(client.read()) == [
PowerReading(voltage=0.0, current=0.0),
PowerReading(voltage=5.0, current=2.0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
class SNMPServerClient(PowerClient):
"""Client interface for SNMP Power Control"""

def on(self) -> str:
def on(self):
"""Turn power on"""
return self.call("on")
self.call("on")

def off(self) -> str:
def off(self):
"""Turn power off"""
return self.call("off")
self.call("off")

def cli(self):
@click.group()
Expand Down

0 comments on commit 0bb3e36

Please sign in to comment.