Esempio n. 1
0
 def __init__(self,controller,connection_details):
     self.controller = controller
 
     self.__host = connection_details['host']
     self.__tcp_port = connection_details['tcp_port']
     self.__username = connection_details['username']
     self.__pw = connection_details['password']
     self.__persistent_connection = connection_details['persistent_network']
     try:
         self.netio = netio230a.netio230a(self.__host, self.__username, self.__pw, True, self.__tcp_port)
         self.netio.enable_logging(open(configuration.LOG_FILE,'w'))
     except StandardError as error:
         print(str(error))
     except Exception as e:
         print(str(e))
     
     self.builder = gtk.Builder()
     self.builder.add_from_file(getAbsoluteFilepath(DEVICE_CONTROLLER_UI))
     
     self.window = self.builder.get_object("mainWindow")
     self.window.set_icon_from_file(getAbsoluteFilepath(PROGRAM_ICON))
     self.builder.get_object("link_button").set_uri('http://'+self.__host)
     
     self.updateLabels()
     self.updatePowerSocketStatus()
     self.builder.connect_signals(self)
     self.window.connect("window-state-event",self.handle_window_state_events)
     self.window.show()
     
     # a timer to update the UI automatically
     self.timer_id = gobject.timeout_add(1000, self.timer_tick) # use gobject.timeout_add_seconds() for longer periods
     self.timer_continue = True
     self.counter = 0
Esempio n. 2
0
 def test_valid_requests(self):
     netio = netio230a.netio230a("localhost", "admin", "admin", True, self.fake_server_port)
     version = netio.getFirmwareVersion()
     swDelay = netio.getSwitchDelay()
     power_sockets = netio.getAllPowerSockets()
     power_socket_1_status = netio.getPowerSocketSetup(0)
     deviceAlias = netio.getDeviceAlias()
     #watchdogSettings1 = netio.getWatchdogSettings(1)
     #networkSettings = netio.getNetworkSettings()
     #dnsServer = netio.getDnsServer()
     systemDiscoverable = netio.getSystemDiscoverableUsingTool()
Esempio n. 3
0
def main():
    try:
        netio = netio230a.netio230a(host, "admin", pw, True,tcp_port)
    except StandardError:
        print("could not connect")
        sys.exit(1)
    netio.setPowerSocketTempInterrupt(interruptPowerSocket)
    
    netio = None
    
    print("\n--------- successfully queried the Koukaam NETIO 230A ---------")
    print("temporarily interrupted power socket %s" % (interruptPowerSocket))
    print("--------------------------------------------------------------- \n")
Esempio n. 4
0
def main():
    try:
        netio = netio230a.netio230a(host, "admin", pw, True, tcp_port)
    except StandardError:
        print("could not connect")
        sys.exit(1)
    netio.reboot()
    
    netio = None
    
    print("\n--------- successfully queried the Koukaam NETIO 230A ---------")
    print("rebooting")
    print("---------------------------------------------------------------- \n")
Esempio n. 5
0
 def __init__(self,controller,connection_details):
     self.controller = controller
 
     self.__host = connection_details['host']
     self.__tcp_port = connection_details['tcp_port']
     self.__username = connection_details['username']
     self.__pw = connection_details['password']
     self.__persistent_connection = connection_details['persistent_network']
     try:
         self.netio = netio230a.netio230a(self.__host, self.__username, self.__pw, True, self.__tcp_port)
         self.netio.enable_logging(open(configuration.LOG_FILE,'w'))
     except StandardError, error:
         print(str(error))
Esempio n. 6
0
def main():
    try:
        netio = netio230a.netio230a(host, "admin", pw, True, tcp_port)
    except StandardError:
        print("could not connect")
        sys.exit(1)
    netio.setPowerSocketTempInterrupt(interruptPowerSocket)

    netio = None

    print("\n--------- successfully queried the Koukaam NETIO 230A ---------")
    print("temporarily interrupted power socket %s" % (interruptPowerSocket))
    print("--------------------------------------------------------------- \n")
Esempio n. 7
0
 def setup(self, app):
     ''' Make sure that other installed plugins don't affect the same
         keyword argument.'''
     for other in app.plugins:
         if not isinstance(other, Netio230aPlugin): continue
         if other.keyword == self.keyword:
             raise PluginError("Found another Netio230a plugin with "\
             "conflicting settings (non-unique keyword).")
     try:
         self.netio = netio230a.netio230a(self.host, self.username, self.password, True, self.tcp_port)
         self.netio.enable_logging(open(LOG_FILE,'w'))
     except Exception, e:
         raise PluginError("Could not connect to the NETIO230A with hostname %s (username: %s). Error: %s" % (self.host, self.username, e) )
Esempio n. 8
0
def main():
    try:
        netio = netio230a.netio230a(host, "admin", pw, True, tcp_port)
    except StandardError:
        print("could not connect")
        sys.exit(1)
    systemTime = netio.getSystemTime()
    netio.setSystemTime(datetime.now()+timedelta(seconds=20))
    time.sleep(0.9) # we have to wait (the new time has to be set first, which takes approx. 0.75 seconds)
    newSystemTime = netio.getSystemTime()
    
    netio = None
    
    print("\n--------- successfully queried the Koukaam NETIO 230A ---------")
    print("system time: %s" % (systemTime))
    print("system time after update: %s" % (newSystemTime))
    print("--------------------------------------------------------------- \n")
def main():
    try:
        netio = netio230a.netio230a(host, "admin", pw, True, tcp_port)
    except StandardError:
        print("could not connect")
        sys.exit(1)
    power_before = netio.getPowerSocketList()
    netio.setPowerSocketPower(power_socket_to_change,power_on)
    power_after = netio.getPowerSocketList()
    
    netio = None
    
    print("\n--------- successfully queried the Koukaam NETIO 230A ---------")
    print("power status before change:  power socket 1: %s, power socket 2: %s, power socket 3: %s, power socket 4: %s" % (power_before[0],power_before[1],power_before[2],power_before[3] ))
    print("set power socket %s to: \"%s\"" % (power_socket_to_change,power_on))
    print("power status after change:  power socket 1: %s, power socket 2: %s, power socket 3: %s, power socket 4: %s" % (power_after[0],power_after[1],power_after[2],power_after[3] ))
    print("---------------------------------------------------------------- \n")
Esempio n. 10
0
def main():
    parser = argparse.ArgumentParser(description=__doc__, conflict_handler='resolve')
    parser.add_argument('--host', '-h', help="Hostname for the device (defaults to the first one found by the discovery in your LAN)")
    parser.add_argument('--port', '-p', type=int, default=1234, help="TCP port (defaults to 1234)")
    parser.add_argument('--username', '-u', default="admin", help="username to use for login (defaults to admin)")
    parser.add_argument('--password', '-w', help="password to use for login (will ask if left empty)")
    parser.add_argument('--socket', '-s', metavar="SOCKET#", help="socketnumber (1-4) to switch on/off", required=True)
    parser.add_argument("--on", action="store_true", help='switch on when --on set, off if omitted')
    args = parser.parse_args()

    if not args.host:
        netio230a_devices = netio230a.get_all_detected_devices()
        if len(netio230a_devices) == 0:
            parser.error("Please specify a host you want to connect to. Could not detect any automatically.")
        elif len(netio230a_devices) == 1:
            deviceName = netio230a_devices[0][0]
            ip = netio230a_devices[0][1]
            ip = "%s.%s.%s.%s" % (ip[0], ip[1], ip[2], ip[3])
            print("We discovered a single NETIO-230A device on the LAN: (%s,%s)" % (deviceName, ip))
            print("Selecting this one as host.")
            args.host = ip
        else:
            print(netio230a_devices)
            addresses = ", ".join([ ("%s: %d.%d.%d.%d" % (dev[0], dev[1][0], dev[1][1], dev[1][2], dev[1][3])) for dev in netio230a_devices])
            print(addresses)
            p.error("%d devices found (%s).\nPlease specify which one you want to connect to using the --host parameter." % (len(netio230a_devices), addresses) )

    if not args.password:
        args.password = input("Please give a password (user "+args.username+"): ")

    try:
        netio = netio230a.netio230a(args.host, args.username, args.password, True, args.port)
    except NameError as error:
        print("Could not connect. "+str(error))
        sys.exit(EXIT_FAILURE)
    try:
        netio.setPowerSocketPower(args.socket, int(args.on))
    except Exception as ne:
        print("Could not switch socket power. "+str(ne))

    netio = None

    print("\n--------- successfully interfaced the Koukaam NETIO 230A ---------")
    print("set socket %s to: \"%s\"" % (args.socket, int(args.on)))
    print("---------------------------------------------------------------- \n")
    sys.exit(EXIT_SUCCESS)
Esempio n. 11
0
 def __init__(self, controller, host, username, password, tcp_port):
     self.controller = controller
     self.time = 0
     self.timer = e32.Ao_timer()
     # List items for all listboxes
     self.socket_list = [u"Power Socket 1", u"Power Socket 2", u"Power Socket 3", u"Power Socket 4"]
     # Custom listbox related items, global or within class
     self.list_box = None       # Listbox
     self.e = []          # Entries: list items with icons
     self.icon_on = None   # Icon for selected checkbox
     self.icon_off = None  # Icon for non-selected checkbox
     
     try:
         self.netio = netio230a.netio230a(host, username, password, True, tcp_port)
     except Exception, error:
         self.netio=None
         self.controller.displayUnrecoverableError(u"Connection failed:\n"+str(error))
         return
Esempio n. 12
0
def main():
    try:
        netio = netio230a.netio230a(host, "admin", pw, True, tcp_port)
    except StandardError:
        print("could not connect")
        sys.exit(1)
    systemTime = netio.getSystemTime()
    netio.setSystemTime(datetime.now() + timedelta(seconds=20))
    time.sleep(
        0.9
    )  # we have to wait (the new time has to be set first, which takes approx. 0.75 seconds)
    newSystemTime = netio.getSystemTime()

    netio = None

    print("\n--------- successfully queried the Koukaam NETIO 230A ---------")
    print("system time: %s" % (systemTime))
    print("system time after update: %s" % (newSystemTime))
    print("--------------------------------------------------------------- \n")
def main():
    try:
        netio = netio230a.netio230a(host, "admin", pw, True, tcp_port)
    except StandardError:
        print("could not connect")
        sys.exit(1)
    version = netio.getFirmwareVersion()
    swDelay = netio.getSwitchDelay()
    power_sockets = netio.getAllPowerSockets()
    power_socket_1_status = netio.getPowerSocketSetup(0)
    deviceAlias = netio.getDeviceAlias()
    watchdogSettings1 = netio.getWatchdogSettings(1)
    networkSettings = netio.getNetworkSettings()
    dnsServer = netio.getDnsServer()
    systemDiscoverable = netio.getSystemDiscoverableUsingTool()
    sntpSettings = netio.getSntpSettings()
    systemTime = netio.getSystemTime()
    systemUptime = netio.getSystemUptime()
    timezoneOffset = netio.getSystemTimezone()
    
    netio = None
    
    # print response
    print "\n--------- successfully queried the Koukaam NETIO 230A ---------"
    print "power status:  power socket 1: %s, power socket 2: %s, power socket 3: %s, power socket 4: %s" % (power_sockets[0].getPowerOn(),power_sockets[1].getPowerOn(),power_sockets[2].getPowerOn(),power_sockets[3].getPowerOn())
    print "power on after power loss:  power socket 1: %s, power socket 2: %s, power socket 3: %s, power socket 4: %s" % (power_sockets[0].getPowerOnAfterPowerLoss(),power_sockets[1].getPowerOnAfterPowerLoss(),power_sockets[2].getPowerOnAfterPowerLoss(),power_sockets[3].getPowerOnAfterPowerLoss())
    print "power socket names:  power socket 1: \"%s\", power socket2: \"%s\", power socket 3: \"%s\", power socket 4: \"%s\"" % (power_sockets[0].getName(),power_sockets[1].getName(),power_sockets[2].getName(),power_sockets[3].getName())
    print "manual mode:  power socket 1: %s, power socket 2: %s, power socket 3: %s, power socket 4: %s" % (power_sockets[0].getManualMode(),power_sockets[1].getManualMode(),power_sockets[2].getManualMode(),power_sockets[3].getManualMode())
    print "interrupt delay:  power socket 1: %s seconds, power socket 2: %s seconds, power socket 3: %s seconds, power socket 4: %s seconds" % (power_sockets[0].getInterruptDelay(),power_sockets[1].getInterruptDelay(),power_sockets[2].getInterruptDelay(),power_sockets[3].getInterruptDelay())
    print "Firmware Version: %s" % (version)
    print "switch delay: %s seconds" % (swDelay)
    print "status of power socket 1: %s" % (power_socket_1_status)
    print "device alias: %s" % (deviceAlias)
    print "watchdog settings for power socket 1: %s" % (watchdogSettings1)
    print "network settings: %s" % (networkSettings)
    print "system discoverable: %s" % (systemDiscoverable)
    print "DNS server: %s" % (dnsServer)
    print "SNTP settings: %s" % (sntpSettings)
    print "system time: %s" % (systemTime)
    print "system uptime: %s" % (systemUptime)
    print "timezone offset: %s hours" % (timezoneOffset)
    
    print "---------------------------------------------------------------- \n"
Esempio n. 14
0
def main():
    #p = optparse.OptionParser(usage="usage: %prog [options] -i[source] -o[target]",add_help_option=False)
    p = optparse.OptionParser(usage="usage: %prog [--host HOST] [--port PORT] [--username USERNAME] [--password PASSWORD] -s SOCKET [--on]",add_help_option=False)
    
    p.add_option('-?', action="store_true", help="show this help message and exit", dest="show_help")
    p.add_option('--host', '-h', default=NOT_SET, help="Hostname for the device (defaults to the first one found by the discovery in your LAN)")
    p.add_option('--port', '-p', default="1234", help="TCP port (defaults to 1234)")
    p.add_option('--username', '-u', default="admin", help="username to use for login (defaults to admin)")
    p.add_option('--password', '-w', default="", help="password to use for login (will ask if left empty)")
    p.add_option('--socket', '-s', default=NOT_SET, metavar="SOCKET#", help="socketnumber (1-4) to switch on/off")
    p.add_option("--on", action="store_true", dest="switchOn", help='switch on when --on set, off if omitted')
    
    options, arguments = p.parse_args()
    
    if options.host == NOT_SET and options.socket == NOT_SET:
        options.show_help = True
    
    if options.show_help:
        p.print_help()
        sys.exit(1)
    
    if options.switchOn == None:
        options.switchOn = False
    
    if options.host is NOT_SET:
        netio230a_devices = netio230a.get_all_detected_devices()
        if len(netio230a_devices) == 0:
            p.error("Please specify a host you want to connect to")      
        elif len(netio230a_devices) == 1:
            deviceName = netio230a_devices[0][0]
            ip = netio230a_devices[0][1]
            ip = "%s.%s.%s.%s" % (ip[0], ip[1], ip[2], ip[3])
            print "We discovered a single NETIO-230A device on the LAN: (%s,%s)" % (deviceName, ip)
            print "Selecting this one as host."
            options.host = ip
        else:
            print netio230a_devices
            addresses = ", ".join([ ("%s: %d.%d.%d.%d" % (dev[0], dev[1][0], dev[1][1], dev[1][2], dev[1][3])) for dev in netio230a_devices])
            print addresses
            p.error("%d devices found (%s).\nPlease specify which one you want to connect to using the --host parameter." % (len(netio230a_devices), addresses) )
    
    if options.socket is "not set":
        p.error("Please specify the socket you want to switch.")
    
    try:
        options.port = int(options.port)
    except StandardError:
        p.error("Please specify the TCP port to connect to as an integer value.")
    
    try:
        options.socket = int(options.socket)
    except StandardError:
        p.error("Please specify the socket to switch as an integer value.")
    
    if len(options.password) == 0:
        options.password = raw_input("Please give a password (user "+options.username+"): ")
    
    try:
        netio = netio230a.netio230a(options.host, options.username, options.password, True, options.port)
    except NameError, error:
        print("Could not connect. "+str(error))
        sys.exit(EXIT_FAILURE)
Esempio n. 15
0
 def connect_clicked(self, button, *args):
     host = ''
     stored_connection = False
     for arg in args:
         if type(arg)==gtk.TreeView:
             (model, treeiter) = arg.get_selection().get_selected()
             host = model.get_value(treeiter,1)
             parent_iter = model.iter_parent(treeiter)
             # compare the text (of the 1st col) of the parent node with the text of the recently_iter node
             try:
                 if model.get_value(self.recently_iter,0) == model.get_value(parent_iter,0):
                     stored_connection = True
                     tcp_port = model.get_value(treeiter,2)
                     username = model.get_value(treeiter,3)
                     password = model.get_value(treeiter,4)
                     store_password = False if password=='' else True
             except:
                 # we don't have recently used devices yet...
                 pass
             if host == '':
                 return
             #dlg = gtk.Dialog(title='Ein Dialog',
             #    parent=self.window,
             #    buttons=(gtk.STOCK_CANCEL,
             #             gtk.RESPONSE_REJECT,
             #             gtk.STOCK_OK,
             #             gtk.RESPONSE_OK))
             #result = dlg.run()
             #if result == gtk.RESPONSE_OK:
             #    print 'Mach mal!'
             #else:
             #    print 'Lieber nicht.'
             #dlg.destroy()
     if stored_connection:
         self.dl = ConnectionDetailDialog(host, username, password, tcp_port, stored_connection, store_password)
     else:
         self.dl = ConnectionDetailDialog(host)
     self.controller.deny_quit = True
     result = self.dl.run()
     self.controller.deny_quit = False
     while result == 1:
         data = self.dl.getData()
         try:
             netio = netio230a.netio230a(data['host'], data['username'], data['password'], True, data['tcp_port'])
             netio.enable_logging(open(configuration.LOG_FILE,'w'))
             devicename = netio.getDeviceAlias()
             netio.disconnect()
             netio = None
             break
         except StandardError, error:
             print(str(error))
             netio = None
             continue_abort = gtk.MessageDialog(parent=self.dl.dialog, flags=gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK_CANCEL, message_format="Connection failed. \n\n"+str(error)+"\n\nChange connection details and try again?")
             response = continue_abort.run()
             continue_abort.destroy()
             if response == gtk.RESPONSE_OK:
                 self.controller.deny_quit = True
                 result = self.dl.run()
                 self.controller.deny_quit = False
             else:
                 result = 0
                 break
Esempio n. 16
0
 def test_connect_to_fake_server(self):
     netio = netio230a.netio230a("localhost", "admin", "admin", True, self.fake_server_port)
Esempio n. 17
0
def main():
    try:
        netio = netio230a.netio230a(host, "admin", pw, True, tcp_port)
    except StandardError:
        print("could not connect")
        sys.exit(1)
    version = netio.getFirmwareVersion()
    swDelay = netio.getSwitchDelay()
    power_sockets = netio.getAllPowerSockets()
    power_socket_1_status = netio.getPowerSocketSetup(0)
    deviceAlias = netio.getDeviceAlias()
    watchdogSettings1 = netio.getWatchdogSettings(1)
    networkSettings = netio.getNetworkSettings()
    dnsServer = netio.getDnsServer()
    systemDiscoverable = netio.getSystemDiscoverableUsingTool()
    sntpSettings = netio.getSntpSettings()
    systemTime = netio.getSystemTime()
    systemUptime = netio.getSystemUptime()
    timezoneOffset = netio.getSystemTimezone()

    netio = None

    print("\n--------- successfully queried the Koukaam NETIO 230A ---------")
    print(
        "power status:  power socket 1: %s, power socket 2: %s, power socket 3: %s, power socket 4: %s"
        % (power_sockets[0].getPowerOn(), power_sockets[1].getPowerOn(),
           power_sockets[2].getPowerOn(), power_sockets[3].getPowerOn()))
    print(
        "power on after power loss:  power socket 1: %s, power socket 2: %s, power socket 3: %s, power socket 4: %s"
        % (power_sockets[0].getPowerOnAfterPowerLoss(),
           power_sockets[1].getPowerOnAfterPowerLoss(),
           power_sockets[2].getPowerOnAfterPowerLoss(),
           power_sockets[3].getPowerOnAfterPowerLoss()))
    print(
        "power socket names:  power socket 1: \"%s\", power socket2: \"%s\", power socket 3: \"%s\", power socket 4: \"%s\""
        % (power_sockets[0].getName(), power_sockets[1].getName(),
           power_sockets[2].getName(), power_sockets[3].getName()))
    print(
        "manual mode:  power socket 1: %s, power socket 2: %s, power socket 3: %s, power socket 4: %s"
        % (power_sockets[0].getManualMode(), power_sockets[1].getManualMode(),
           power_sockets[2].getManualMode(), power_sockets[3].getManualMode()))
    print(
        "interrupt delay:  power socket 1: %s seconds, power socket 2: %s seconds, power socket 3: %s seconds, power socket 4: %s seconds"
        % (power_sockets[0].getInterruptDelay(),
           power_sockets[1].getInterruptDelay(),
           power_sockets[2].getInterruptDelay(),
           power_sockets[3].getInterruptDelay()))
    print("Firmware Version: %s" % (version))
    print("switch delay: %s seconds" % (swDelay))
    print("status of power socket 1: %s" % (power_socket_1_status))
    print("device alias: %s" % (deviceAlias))
    print("watchdog settings for power socket 1: %s" % (watchdogSettings1))
    print("network settings: %s" % (networkSettings))
    print("system discoverable: %s" % (systemDiscoverable))
    print("DNS server: %s" % (dnsServer))
    print("SNTP settings: %s" % (sntpSettings))
    print("system time: %s" % (systemTime))
    print("system uptime: %s" % (systemUptime))
    print("timezone offset: %s hours" % (timezoneOffset))

    print(
        "---------------------------------------------------------------- \n")