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 api_mock(self, caplog): self.mock_api_call = patch('pyvesync_v2.helpers.Helpers.call_api') self.mock_api = self.mock_api_call.start() self.mock_api.create_autospect() self.mock_api.return_value.ok = True self.vesync_obj = VeSync('*****@*****.**', 'pass') self.vesync_obj.enabled = True self.vesync_obj.login = True self.vesync_obj.token = 'sample_tk' self.vesync_obj.account_id = 'sample_actid' caplog.set_level(logging.DEBUG) yield self.mock_api_call.stop()
def api_mock(self, caplog): """Mock call_api() and initialize VeSync object.""" self.mock_api_call = patch.object(pyvesync_v2.helpers.Helpers, 'call_api') self.mock_api = self.mock_api_call.start() self.mock_api.create_autospect() self.mock_api.return_value.ok = True self.vesync_obj = VeSync('*****@*****.**', 'pass') self.vesync_obj.enabled = True self.vesync_obj.login = True self.vesync_obj.tk = 'sample_tk' self.vesync_obj.account_id = 'sample_actid' caplog.set_level(logging.DEBUG) yield self.mock_api_call.stop()
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())
from pyvesync_v2 import VeSync import os import mailer import time import datetime power_threshold = 30 # in Watts sleeptime_seconds = 600 vsync_email = '*****@*****.**' vesync_password = os.environ[ 'vesyncPassword'] # added as -e option on docker start. sg_password = os.environ['sendgridKey'] # added as -e option on docker start. logfile = 'rad_wagon_battery.log' manager = VeSync(vsync_email, vesync_password, time_zone='US/Pacific') manager.login() manager.update() manager.energy_update_interval = 60 my_switch = manager.outlets[0] mail_from_larry = mailer.Sendgrid(sg_password, 'Larry Weinhouse', '*****@*****.**') def poll_outlet(my_switch): try: manager.update_energy() my_switch.update() volts = my_switch.voltage power = my_switch.power