Esempio n. 1
0
class pdu(utils):
    """ Power Distribution Manager """
    def __init__(
        self,
        pduip="192.168.86.10",
        outlet=1,
        pdu_type="cyberpower",
        username="******",
        password="******",
        yamlfilename=None,
        board_name=None,
    ):
        self.pduip = pduip
        self.outlet = outlet
        self.pdu_type = pdu_type
        self.username = username
        self.password = password
        self.update_defaults_from_yaml(yamlfilename,
                                       __class__.__name__,
                                       board_name=board_name)

        if self.pdu_type == "cyberpower":
            if not self.pduip:
                raise Exception("pduip must be set for cyberpower config")
            self.pdu_dev = cpdu.CyberPowerPdu(self.pduip)
        elif self.pdu_type == "vesync":
            if not self.username:
                raise Exception("username must be set for vesync config")
            if not self.password:
                raise Exception("password must be set for vesync config")
            self.pdu_dev = VeSync(self.username, self.password)
            self.pdu_dev.login()
            self.pdu_dev.update()
        else:
            raise Exception("Unknown PDU type")

    def power_cycle_board(self):
        """ Power Cycle Board: OFF, wait 5 seconds, ON
        """
        if self.pdu_type == "cyberpower":
            self.pdu_dev.set_outlet_on(self.outlet, False)
        elif self.pdu_type == "vesync":
            self.pdu_dev.outlets[self.outlet].turn_off()
        time.sleep(5)
        if self.pdu_type == "cyberpower":
            self.pdu_dev.set_outlet_on(self.outlet, True)
        elif self.pdu_type == "vesync":
            self.pdu_dev.outlets[self.outlet].turn_on()
Esempio n. 2
0
from pyvesync_v2 import VeSync
import os

USER = os.getenv('VESYNC_USER')
PASSWORD= os.getenv('VESYNC_PASSWORD')

manager = VeSync(USER, PASSWORD, "America/New_York")
manager.login()

# Get/Update Devices from server - populate device lists
manager.update()

# Display outlet device information
for device in manager.outlets:
    print(device.display_json())