def __init__(self, ip_address, outlet, username, password): """Instance initialization.""" PowerDevice.__init__(self, ip_address, username, password) self.switch = dlipower.PowerSwitch(hostname=ip_address, userid=username, password=password) self.outlet = outlet
def test_powerswitch_user_password(self): r = dlipower.PowerSwitch(userid='foo', password='******', hostname='goober.com', cycletime=10) self.assertEqual(r.userid, 'foo') self.assertEqual(r.password, 'bar') self.assertEqual(r.hostname, 'goober.com') self.assertIsInstance(r.cycletime, float) self.assertEqual(r.cycletime, 10.0)
def setup_platform( hass: HomeAssistant, config: ConfigType, add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Find and return DIN III Relay switch.""" host = config[CONF_HOST] controller_name = config[CONF_NAME] user = config[CONF_USERNAME] pswd = config[CONF_PASSWORD] tout = config[CONF_TIMEOUT] cycl = config[CONF_CYCLETIME] power_switch = dlipower.PowerSwitch(hostname=host, userid=user, password=pswd, timeout=tout, cycletime=cycl) if not power_switch.verify(): _LOGGER.error("Could not connect to DIN III Relay") return entities: list[DINRelay] = [] parent_device = DINRelayDevice(power_switch) entities.extend( DINRelay(controller_name, parent_device, outlet) for outlet in power_switch[0:]) add_entities(entities)
def setup_platform(hass, config, add_devices, discovery_info=None): """Find and return DIN III Relay switch.""" import dlipower host = config.get(CONF_HOST) controllername = config.get(CONF_NAME) user = config.get(CONF_USERNAME) pswd = config.get(CONF_PASSWORD) tout = config.get(CONF_TIMEOUT) cycl = config.get(CONF_CYCLETIME) power_switch = dlipower.PowerSwitch(hostname=host, userid=user, password=pswd, timeout=tout, cycletime=cycl) if not power_switch.verify(): _LOGGER.error('Could not connect to DIN III Relay') return False devices = [] parent_device = DINRelayDevice(power_switch) devices.extend( DINRelay(controllername, device.outlet_number, parent_device) for device in power_switch) add_devices(devices)
def setup_platform(hass, config, add_entities, discovery_info=None): """Find and return DIN III Relay switch.""" host = config.get(CONF_HOST) controller_name = config.get(CONF_NAME) user = config.get(CONF_USERNAME) pswd = config.get(CONF_PASSWORD) tout = config.get(CONF_TIMEOUT) cycl = config.get(CONF_CYCLETIME) power_switch = dlipower.PowerSwitch( hostname=host, userid=user, password=pswd, timeout=tout, cycletime=cycl ) if not power_switch.verify(): _LOGGER.error("Could not connect to DIN III Relay") return False outlets = [] parent_device = DINRelayDevice(power_switch) outlets.extend( DINRelay(controller_name, parent_device, outlet) for outlet in power_switch[0:] ) add_entities(outlets)
def __init__(self, hostname, user, password): self.hostname = hostname self.user = user self.password = password self.power_switch = dlipower.PowerSwitch(hostname=self.hostname, userid=self.user, password=self.password)
def __init__(self, ip_address: str, outlet: str, username: str, password: str): """Instance initialization.""" super().__init__(ip_address, username, password, outlet=outlet) self.switch = dlipower.PowerSwitch(hostname=ip_address, userid=username, password=password)
def _lookup_power_interface(self, interface_name: str) -> Union[dict, None]: """ Looks up a power interface by power interface name. """ power_iface = None if interface_name in self._power_interfaces: power_iface = self._power_interfaces[interface_name] else: lscape = self.landscape interface_config = self._power_config[interface_name] powerType = interface_config["powerType"] if powerType == "DliPowerSwitch": model = interface_config["model"] host = interface_config["host"] credential_name = interface_config["credential"] credobj = lscape.lookup_credential(credential_name) power_iface = dlipower.PowerSwitch(userid=credobj.username, password=credobj.password, hostname=host) self._power_interfaces[interface_name] = power_iface else: errmsg = "Un-Support power interface type={}.".format( powerType) raise AKitConfigurationError(errmsg) from None return power_iface
def __init__(self, ip_address, outlet, username, password): PowerDevice.__init__(self, ip_address, username, password) self.switch = dlipower.PowerSwitch(hostname=ip_address, userid=username, password=password) self.outlet = outlet
def setStateAsync(endpoint,username,password,outlet,name,state): wps = dlipower.PowerSwitch(hostname=endpoint.replace('http://',''), userid=username, password=password) wps[outlet].name = name if state == True: print('turning outlet {} on'.format(str(outlet))) wps[outlet].on() else: print('turning outlet {} off'.format(str(outlet))) wps[outlet].off()
def __init__(self, power_switch_ip, power_switch_user, power_switch_password): self.switch_access = {"hostname": power_switch_ip, "userid": power_switch_user, "password": power_switch_password} log.i('Connecting to a DLI PowerSwitch at {}'.format(power_switch_ip)) self.switch = dlipower.PowerSwitch(hostname=power_switch_ip, userid=power_switch_user, password=power_switch_password) self.get_switch() log.i('Connected.')
def __init__(self): self.pSuccess = False self._switch = dlipower.PowerSwitch(hostname="192.168.0.100", userid="admin", password='******') self.pSuccess = self._switch.verify() for i in range(1, 8): self._switch.off(i) self._switch.on(i) self.jobManager = JobManager(self._switch) self.device_map = {} self.devices = []
def __init__(self): self.switch = dlipower.PowerSwitch(hostname='192.168.1.100', userid='COSGC', password='******') if self.switch.verify(): logger.log.info("Switch is responding") else: logger.log.critical(dlipower.DLIPowerException) sys.exit() self.rotator_controller = self.switch[0] self.lna_rotator_interface = self.switch[1] self.transceiver = self.switch[2]
def getStateAsync(): power = PowerSwitch.objects.all()[0] endpoint = power.endpoint.replace('http://','') username = power.username password = power.password wps = dlipower.PowerSwitch(hostname=endpoint, userid=username, password=password) switches = PowerOutlet.objects.all() for switch in switches: state = str(wps[switch.outlet].state) if "ON" in state: switch.state = True else: switch.state = False switch.save()
def __init__(self, config, logger): super(DLiPowerSwitch, self).__init__(config, logger) ip = config["power_switch_ip"] user = config["power_switch_user"] password = config["power_switch_password"] self._switch_access = {"hostname": ip, "userid": user, "password": password} self._logger = logger try: self._checkTimeout('10') response = os.system("ping -c 1 " + ip) powerSwitch = dlipower.PowerSwitch(hostname = ip, userid = user, password = password) except Exception as e: self._logger.error(str(e))
def __init__(self, host, username, password): """ Note: This may require allowing plaintext password sign in on the power switch, which can be configure in the device's control panel. """ super(PduDevice, self).__init__(host, username, password) self.power_switch = dlipower.PowerSwitch(hostname=host, userid=username, password=password) # Connection is made at command execution, this verifies the device # can be reached before continuing. if not self.power_switch.statuslist(): raise pdu.PduError( 'Failed to connect get WebPowerSwitch status. Incorrect host, ' 'userid, or password?') else: self.log.info('Connected to WebPowerSwitch (%s).' % host)
from ola.ClientWrapper import ClientWrapper from projectorLib import Projector import time import dlipower inUniverse = 1 inAddr = 509 ps1 = dlipower.PowerSwitch(hostname="172.16.50.120", userid="admin", password="******") curState = [None, None, None, None] def rxData(data): global curState newState = [None, None, None, None] for i in range(len(curState)): newState[i] = (data[inAddr - 1 + i] > 127) if newState[i] != curState[i]: curState[i] = newState[i] if curState[i]: ps1.on(i + 1) else: ps1.off(i + 1) print("New ps {} state = {}".format(i, curState))
def setUp(self): """ Set up the mock objects to do our unit tests """ my_opener = urllib2.build_opener(MyHTTPHandler) urllib2.install_opener(my_opener) self.p = dlipower.PowerSwitch(hostname='lpc.digital-loggers.com')
def get_switch(self): if not self.switch: self.switch = dlipower.PowerSwitch(**self.switch_access) if not self.switch.verify(): log.i("Could not connect to the power switch.") return self.switch
def _getSwitch(self): switch = dlipower.PowerSwitch(**self._switch_access) if not switch.verify(): self._logger.info("Could not connect to the power switch.") return None return switch
""" Created on 29 mai 2013 :author: lbavois """ from time import sleep import dlipower as dli if __name__ == '__main__': # Set up the PowerSwitch with default parameters present in default config file path # CONFIG_FILE = os.path.expanduser('~/.dlipower.conf') switch = dli.PowerSwitch("admin", "1234", "192.168.0.100", 20, 3, 3) # Verify we can talk to the switch if not switch.verify(): print("ERROR : Can't talk to the switch") else: print("SUCCESS : Can talk to the switch") loop_number = 1 while True: print("START TEST LOOP NUMBER = " + str(loop_number)) # Get status for all outlet on the power supply switch.printstatus()
def setUp(self): """ Set up the mock objects to do our unit tests """ self.p = dlipower.PowerSwitch(hostname='lpc.digital-loggers.com')
def main(argv): server = "192.168.0.100" command = "NONE" passWd = "1234" switchArray = list() user = "******" cycleDelay = 10 linkedToggle = True resultArray = list() backupConfig = False loadConfig = False switchNameArray = list() VerboseOutput = True try: opts, args = getopt.getopt(argv, shortOpts, longOpts) except getopt.GetoptError: usage() sys.exit(2) # Process args for opt, arg in opts: if opt == '-h': usage() sys.exit() # NOTE: Config is stored in clear text elif opt in ("-b", "--backup"): print( "\n\nWARNING: Configuration is saved in clear text and includes the password!\n\n" ) backupConfig = True # FIXME - TODO load configuration elif opt in ("-o", "--config"): LoadConfig = True elif opt in ("-s", "--server"): server = arg elif opt in ("-n", "--number"): switchArray.append(arg) elif opt in ("-m", "--name"): switchNameArray.append(arg) elif opt in ("-c", "--command"): command = arg elif opt in ("-p", "--password"): passWd = arg elif opt in ("-u", "--user"): user = arg elif opt in ("-d", "--delay"): cycleDelay = arg elif opt in ("-l", "--nolink"): linkedToggle = False if (validCommand(command) == False): usage() sys.exit(1) # Report settings (rather verbose for now) if (VerboseOutput == True): print('Switch Host is: ', server) for s in switchArray: print('SwitchNo is: ' + s) print('Command is: ', command) print('Cycle Delay is: ', cycleDelay) print('Connecting to a DLI PowerSwitch at ' + server) # Connect to switch and try to handle an exception try: switch = dlipower.PowerSwitch(hostname=server, userid=user, password=passWd) # Yep - cannot find an exception routine that helps find a failed connection... # So... here are some attempts that cannot seem to prevent a Traceback from a failed connect # Probably my error/problem except dlipower.ValueError: print("Exception connecting to switch") sys.exit(0xff) if (switch.verify() == False): print("Exception connecting to switch") sys.exit(0xff) # Process commands if (command.lower() == "toggle"): for s in switchArray: result = switch.status(s) if (result == 'ON'): print("Toggling Switch: " + s + " from: " + result + " to: OFF") switch.off(s) elif (result == 'OFF'): for s in switchArray: print("Toggling Switch: " + s + " from: " + result + " to: ON") switch.on(s) elif (command.lower() == "rename"): # Simple sequentially rename - meh easy to understand - first switch number passed as an argument gets the first name passed. Then the second and ... i = 0 for s in switchNameArray: sName = switchArray[i] tName = switchNameArray[i] print("SNA: " + tName) print("Naming Switch: " + sName + " to: " + s) switch[int(sName) - 1].name = tName i = i + 1 elif (command.lower() == "status"): for s in switchArray: result = switch.status(s) print("Switch: " + s + " is [" + result + "]") elif (command.lower() == "cycle"): if ( linkedToggle == False ): # Toggle ALL the requested switches (inverse of present state), pause, then toggle them back to last state for s in switchArray: result = switch.status(s) print("Switch: " + s + " is [" + result + "]") if (result == 'ON'): print(" turning it off...") switch.off(s) print("Waiting: " + str(cycleDelay) + " seconds") time.sleep(float(cycleDelay)) print(" turning it on...") switch.on(s) if (result == 'OFF'): print(" turning it on...") switch.on(s) print("Waiting: " + str(cycleDelay) + " seconds") time.sleep(float(cycleDelay)) print(" turning it off...") switch.off(s) else: # This is the default path - toggle the requested switches(inverse of present state), wait a bit, toggle them back to last state i = 0 for s in switchArray: # get the state of all the requested switches resultArray.append(switch.status(s)) for s in switchArray: # now toggle each print("Switch: " + s + " is [" + resultArray[i] + "]") if (resultArray[i] == 'ON'): print(" turning it off...") switch.off(s) if (resultArray[i] == 'OFF'): print(" turning it on...") switch.on(s) i = i + 1 print("Waiting: " + str(cycleDelay) + " seconds") time.sleep(float(cycleDelay)) # wait i = 0 for s in switchArray: # now toggle back if (resultArray[i] == 'ON'): print(" turning " + s + ": back ON") switch.on(s) if (resultArray[i] == 'OFF'): print(" turning " + s + ": back OFF") switch.off(s) i = i + 1 elif (command.lower() == "on"): for s in switchArray: print("Turning Switch: " + s + " to: ON") switch.on(s) elif (command.lower() == "off"): for s in switchArray: print("Turning Switch: " + s + " to: OFF") switch.off(s) else: usage() sys.exit(1) print('The current status of the powerswitch is:') print(switch) if (backupConfig == True): switch.save_configuration()
import dlipower print("Connecting to a DLI PowerSwitch at lpc.digital-loggers.com") switch = dlipower.PowerSwitch(hostname="lpc.digital-loggers.com", userid="admin") print("Turning off the first outlet") switch.off(1) print("The powerstate of the first outlet is currently", switch[0].state)