File: outlet_switch_link_pdu.lua

package info (click to toggle)
raritan-json-rpc-sdk 3.6.1%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 41,748 kB
  • sloc: cs: 162,629; perl: 85,818; python: 24,275; javascript: 5,937; makefile: 21
file content (42 lines) | stat: -rw-r--r-- 1,149 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
-- SPDX-License-Identifier: BSD-3-Clause
--
-- Copyright 2019 Raritan Inc. All rights reserved.

-- Switch the third outlet of the first link PDU

require "Pdu"

-- Create an HTTP agent for the link unit
local http_agent = agent.HttpAgent:getForLinkUnit(2)
assert(http_agent)

-- Create a proxy object using the HTTP agent and the well-known URI of
-- the root PDU instance
local pdu = pdumodel.Pdu:newRemote("/model/pdu/0", http_agent)

-- Get the third outlet; terminate if there is no such outlet
local out3 = pdu:getOutlets()[3]
assert(out3)

-- Get the initial outlet state
local state = out3:getState()
local powerstate = state.powerState
local lastchange = os.date("%c", state.lastPowerStateChange)

print("Initial state:")
print("  Power state: " .. state.powerState)
print("  Last change: " .. lastchange)
print()

if powerstate == pdumodel.Outlet.PowerState.PS_ON then
    print("Switching outlet OFF ...")
    powerstate = pdumodel.Outlet.PowerState.PS_OFF
else
    print("Switching outlet ON ...")
    powerstate = pdumodel.Outlet.PowerState.PS_ON
end

-- Toggle outlet power state
out3:setPowerState(powerstate)

print(" --- done ---")