Example #1
0
 def __init__(self, package_name):
     Database.__init__(self, package_name, None)
     self.timezone = None
     self.lat = None
     self.lng = None
     self.horizon = None
     self.sunset_offset_mins = None
     self.sunrise_offset_mins = None
     self.log_level = None
     self.open()
     self.load()
 def save(self):
     if self.config_changed:
         self.config_changed = False
         db = Database(self.package_name)
         db.open()
         db.save_config(self.config)
         db.close()
    def _add_from_config(self):
        """Attempt to add all configured devices."""
        database = Database('snapclient')
        if not database.open():
            return

        config = database.load_config()
        database.close()

        if not config or 'snapserver' not in config:
            return

        self.server_address = config['snapserver']
        print("===SNAPSERVER ADDRESS===", self.server_address)
        try:
            self.server = SnapServer(
                host=self.server_address,
                timeout=_TIMEOUT) if self.server is None else self.server
            servers = self.server.get_status(server=self.server_address)
            if "result" in servers:
                if "server" in servers["result"] and "groups" in servers[
                        "result"]["server"]:
                    for group in servers["result"]["server"]["groups"]:
                        for client in group["clients"]:
                            print("@@@@@@@@ CLIENT: ", client)
                            if self.pairing:
                                self._add_device(client)
        except (OSError, UnboundLocalError) as e:
            print('Failed to connect to {}: {}'.format(address, e))
            pass
Example #4
0
    def __init__(self, verbose=False):
        """
        Initialize the object.

        verbose -- whether or not to enable verbose logging
        """
        self.name = self.__class__.__name__
        Adapter.__init__(self,
                         'meross-adapter',
                         'meross-adapter',
                         verbose=verbose)

        self.manager = None
        self.pairing = False

        database = Database(self.package_name)
        if database.open():
            config = database.load_config()

            if 'username' in config and len(config['username']) > 0 and \
                    'password' in config and len(config['password']) > 0:
                self.manager = MerossManager(
                    meross_email=config['username'],
                    meross_password=config['password'])

                self.manager.register_event_handler(self.event_handler)
                self.manager.start()

            database.close()

        self.start_pairing()
Example #5
0
    def _add_from_config(self):
        """Attempt to add all configured devices."""
        database = Database('awox-mesh-light-adapter')
        if not database.open():
            return

        config = database.load_config()
        database.close()

        if not config or 'address' not in config:
            return
        try:
            self.DEBUG and print(config['address'])
            self.controller = AwoxMeshLight(config['address'], config['name'],
                                            config['password'])

            device = AwoxMeshLightDevice(self)
            self.handle_device_added(device)
            if self.DEBUG:
                print("awox_mesh_light_device created")
            self.devices[device.id].connected = True
            self.devices[device.id].connected_notify(True)

        except Exception as ex:
            print("error: Could not create awox_mesh_light_device: " + str(ex))
Example #6
0
    def __init__(self, verbose=False):
        """
        Initialize the object.

        verbose -- whether or not to enable verbose logging
        """
        self.name = self.__class__.__name__
        Adapter.__init__(self, 'tapo-adapter', 'tapo-adapter', verbose=verbose)

        self.username = None
        self.password = None
        self.addresses = []

        database = Database(self.package_name)
        if database.open():
            config = database.load_config()

            if 'username' in config and len(config['username']) > 0:
                self.username = config['username']

            if 'password' in config and len(config['password']) > 0:
                self.password = config['password']

            if 'addresses' in config:
                self.addresses = config['addresses']

            database.close()

        self.pairing = False
        self.start_pairing(_TIMEOUT)
Example #7
0
    def add_from_config(self):
        """Attempt to read config data."""
        try:
            database = Database(self.addon_name)
            if not database.open():
                print("Could not open settings database")
                return

            config = database.load_config()
            database.close()

        except Exception as ex:
            print("Error! Failed to open settings database: " + str(ex))

        if not config:
            print("Error loading config from database")
            return

        # Api token
        try:
            if 'Authorization token' in config:
                self.token = str(config['Authorization token'])
                print("-Authorization token is present in the config data.")
        except:
            print("Error loading api token from settings")

        if 'Debugging' in config:
            self.DEBUG = bool(config['Debugging'])
            if self.DEBUG:
                print("-Debugging preference was in config: " +
                      str(self.DEBUG))
Example #8
0
    def add_from_config(self):
        """Attempt to add all configured devices."""
        try:
            database = Database(self.addon_name)
            if not database.open():
                print("Error. Could not open settings database")
                return

            config = database.load_config()
            database.close()

        except:
            print("Error. Failed to open settings database.")

        if not config:
            return

        if 'Debugging' in config:
            print("-Debugging was in config")
            self.DEBUG = bool(config['Debugging'])
            if self.DEBUG:
                print("Debugging enabled")

        if self.DEBUG:
            print(str(config))

        try:
            if 'Radio stations' in config:
                self.radio_stations = config['Radio stations']
                if self.DEBUG:
                    print("self.radio_stations was in config: " +
                          str(self.radio_stations))

        except Exception as ex:
            print("Error loading radio stations: " + str(ex))
    def __init__(self, verbose=False):
        """
        Initialize the object.

        verbose -- whether or not to enable verbose logging
        """
        self.name = self.__class__.__name__
        Adapter.__init__(self,
                         'etekcity-adapter',
                         'etekcity-adapter',
                         verbose=verbose)

        self.manager = None

        database = Database(self.package_name)
        if database.open():
            config = database.load_config()

            if 'username' in config and len(config['username']) > 0 and \
                    'password' in config and len(config['password']) > 0:
                self.manager = VeSync(config['username'], config['password'])
                self.manager.login()

            database.close()

        self.pairing = False
        self.start_pairing(_TIMEOUT)
    def add_from_config(self):
        """Attempt to read config data."""
        try:
            database = Database('privacy-manager')
            if not database.open():
                print("Could not open settings database")
                return
            
            config = database.load_config()
            database.close()
            
        except:
            print("Error! Failed to open settings database.")
        
        if not config:
            print("Error loading config from database")
            return
        
        if self.DEV:
            print(str(config))

        if 'Debugging' in config:
            self.DEBUG = bool(config['Debugging'])
            if self.DEBUG:
                print("-Debugging preference was in config: " + str(self.DEBUG))
    def start_pairing(self, timeout=None):
        """
        Start the pairing process.

        timeout -- Timeout in seconds at which to quit pairing
        """
        if self.pairing:
            return

        self.pairing = True

        database = Database('tide-calendar-adapter')
        if not database.open():
            return

        config = database.load_config()
        database.close()

        if not config or 'stations' not in config or 'unit' not in config:
            return

        unit = config['unit']

        for station in config['stations']:
            _id = 'tide-calendar-{}'.format(station)
            if _id not in self.devices:
                try:
                    device = TideCalendarDevice(self, _id, station, unit)
                except StationException as e:
                    print(e)
                else:
                    self.handle_device_added(device)

        self.pairing = False
Example #12
0
    def add_from_config(self):
        """Attempt to add all configured devices."""
        try:
            database = Database('p1-adapter')
            if not database.open():
                return

            config = database.load_config()
            database.close()
        except:
            print("Error! Failed to open settings database.")
            return

        if not config:
            print("Error loading config from database")
            return

        # Debug
        try:
            if 'Debugging' in config:
                self.DEBUG = bool(config['Debugging'])
                if self.DEBUG:
                    print("Debugging is set to: " + str(self.DEBUG))
            else:
                self.DEBUG = False
        except:
            print("Error loading debugging preference")

        # USB port from dropdown
        try:
            if 'USB port' in config:
                if str(config['USB port']) == 'USB port 1':
                    self.usb_port = self.initial_serial_devices[0]
                if str(config['USB port']) == 'USB port 2':
                    self.usb_port = self.initial_serial_devices[1]
                if str(config['USB port']) == 'USB port 3':
                    self.usb_port = self.initial_serial_devices[2]
                if str(config['USB port']) == 'USB port 4':
                    self.usb_port = self.initial_serial_devices[3]
        except Exception as ex:
            print("Error with USB port selection: " + str(ex))

        # Custom USB port command. Overrides dropdown selection.
        try:
            if 'Custom USB port command' in config:
                if str(config['Custom USB port command']) != "":
                    self.usb_override = True
                    self.usb_port = str(config['Custom USB port command'])
                else:
                    print("Custom USB port command was empty")

        except Exception as ex:
            print("Error setting custom USB port command:" + str(ex))

        print("selected USB port: " + str(self.usb_port))
Example #13
0
 def add_from_config(self):
     """Attempt to add all configured devices."""
     database = Database(self.package_name)
     if database.open():
         config = database.load_config()
         if not config or 'Token' not in config or 'IPaddress' not in config:
             return
         if (config['Token'] is not '') and (config['IPaddress'] is not ''):
             self._add_device(config['DeviceType'], config['IPaddress'],
                              config['Token'])
             #print("add"+ str(config['DeviceType'])+ str(config['Token']))
         database.close()
    def add_from_config(self):
        """Attempt to add all configured devices."""

        try:
            database = Database(self.addon_name)

            if not database.open():
                return

            config = database.load_config()
            database.close()

            if not config or 'Time window' not in config:
                print("Error: required variables not found in config database. Check the addon's settings.")
                return

            try:
                self.DEBUG = bool(config['Debugging']) # The variable is clamped: it is forced to be between 1 and 50.
            except:
                print("No debugging preference was found in the settings")
            
            
            # Target IP
            # Can be used to override normal behaviour (which is to scan the controller's neighbours), and target a very different group of IP addresses.
            if 'Target IP' in config:
                try:
                    if str(config['Target IP']) != "":
                        potential_ip = str(config['Target IP'])
                        if valid_ip(potential_ip):
                            self.own_ip = potential_ip
                            print("A target IP was in settings")
                        else:
                            print("This addon does not understand '" + str(potential_ip) + "' as a valid IP address. Go to the add-on settings page to fix this. For now, the addon will try to detect and use the system's IP address as a base instead.")
                except:
                    print("Error handling Target IP setting")
            else:
                if self.DEBUG:
                    print("No target IP address was available in the settings data")


            if 'Time window' in config:
                try:
                    self.time_window = clamp(int(config['Time window']), 1, 10800) # In minutes. 'Grace period' could also be a good name.
                    print("Time window value from settings page: " + str(self.time_window))
                except:
                    print("No time window preference was found in the settings. Will use default.")
            
                

        except:
            print("Error getting config data from database. Check the add-on's settings page for any issues.")
Example #15
0
    def add_from_config(self):
        """get user configuration."""
        try:
            database = Database('airport')
            if not database.open():
                return

            config = database.load_config()
            database.close()
        except:
            print("Error! Failed to open settings database.")

        if not config:
            print("Error loading config from database")
            return
        
        
        # Debugging
        try:
            if 'Debugging' in config:
                self.DEBUG = bool(config['Debugging'])
                self.rpiplay_debug = " -vv"
                if self.DEBUG:
                    print("Debugging is set to: " + str(self.DEBUG))
            else:
                self.DEBUG = False
                
        except:
            print("Error loading debugging preference")
            
        
        # Audio (for Shairport)
        try:
            if 'Audio' in config:
                self.audio = bool(config['Audio'])
            else:
                print("Audio was not in config")
        except Exception as ex:
            print("Audio config error:" + str(ex))

        
        # Video (for RpiPlay)
        try:
            if 'Video' in config:
                self.video = bool(config['Video'])
            else:
                print("Video was not in config")
        except Exception as ex:
            print("Video config error:" + str(ex))
    def _add_from_config(self):
        """Attempt to add all configured devices."""

        database = Database('buspro-adapter')
        if not database.open():
            return

        config = database.load_config()
        database.close()

        if not config or 'addresses' not in config:
            return

        ip = config["ip"]
        port = config["ip"]
        gateway_address_send_receive = ((ip, port), ('', port))
        self.gateway = Buspro(gateway_address_send_receive)

        for address in config['addresses']:

            try:
                if address["type"] == "Colour Light":
                    dev = BusproLight(self,
                                      address["subnet_id"],
                                      address["ip"],
                                      address["port"],
                                      is_color=True)
                    self.handle_device_added(dev)

                if address["type"] == "Dimmer":
                    dev = BusproLight(self,
                                      address["subnet_id"],
                                      address["ip"],
                                      address["port"],
                                      is_dimmable=True)
                    self.handle_device_added(dev)

                if address["type"] == "Light":
                    dev = BusproLight(self, address["subnet_id"],
                                      address["ip"], address["port"])
                    self.handle_device_added(dev)

            except (OSError, UnboundLocalError) as e:
                print('Failed to connect to {}: {}'.format(address, e))
                continue
Example #17
0
    def add_from_config(self):
        """Attempt to add all configured devices."""
        try:
            database = Database('xiaomi-miflora')
            if not database.open():
                return

            config = database.load_config()
            database.close()
        except:
            print("Error! Failed to open settings database.")

        if not config:
            print("Error loading config from database")
            return

        # Debug
        try:
            if 'Debugging' in config:
                self.DEBUG = bool(config['Debugging'])
                if self.DEBUG:
                    print("-Debug preference is present in the config data.")
        except Exception as ex:
            print("Debug preference error:" + str(ex))

        # Polling interval
        try:
            if 'Polling interval' in config:
                if self.DEBUG:
                    print(
                        "-Polling interval preference is present in the config data."
                    )
                if int(config['Polling interval']) != 0:
                    self.polling_interval_seconds = int(
                        config['Polling interval']) * 60 * 60
            else:
                if self.DEBUG:
                    print(
                        "-Polling interval was not in config, will stay with default of 24h."
                    )
        except Exception as ex:
            print("Polling interval preference error:" + str(ex))

        return
Example #18
0
    def add_from_config(self):
        """Attempt to add all configured devices."""
        try:
            database = Database(self.addon_name)
            if not database.open():
                print("Could not open settings database")
                return

            config = database.load_config()
            database.close()

        except:
            print("Error! Failed to open settings database.")

        if not config:
            print("Error loading config from database")
            return

        if self.DEV:
            print(str(config))

        if 'Debugging' in config:
            self.DEBUG = bool(config['Debugging'])
            if self.DEBUG:
                print("-Debugging preference was in config: " +
                      str(self.DEBUG))

        if 'Interval' in config:
            self.interval = int(config['Interval'])
            if self.DEBUG:
                print("-Interval preference was in config: " +
                      str(self.interval))

        if 'Contain' in config:
            self.contain = bool(config['Contain'])
            if self.DEBUG:
                print("-Contain photo preference was in config: " +
                      str(self.contain))

        if 'Clock' in config:
            self.clock = int(config['Clock'])
            if self.DEBUG:
                print("-Clock preference was in config: " + str(self.clock))
Example #19
0
    def add_from_config(self):
        """Attempt to add all configured devices."""

        try:
            database = Database('network-presence-detection-adapter')

            if not database.open():
                return

            config = database.load_config()
            database.close()

            if not config or 'Memory' not in config or 'Time window' not in config:
                print("Required variables not found in config database?")
                return

            self.memory_in_weeks = clamp(
                int(config['Memory']), 1, 50
            )  # The variable is clamped: it is forced to be between 1 and 50.
            self.time_window = clamp(
                int(config['Time window']), 1,
                1380)  # 'Grace period' could also be a good name.
            print("Memory value from settings page: " +
                  str(self.memory_in_weeks))
            print("Time window value from settings page: " +
                  str(self.time_window))

            if 'Arping' in config:
                self.arping = config['Arping']  # boolean.

            if 'Default IP address' in config:
                self.defaultIpAddress = config['Default IP address']  #string

            if 'Default subnet mask' in config:
                self.defaultSubnetMask = config['Default subnet mask']  #string

            if 'Debug messages' in config:
                self.DEBUG = config['Debug messages']  # boolean

            print("Config loaded ok")

        except:
            print("Error getting config data from database")
Example #20
0
    def _add_from_config(self):
        """Attempt to add all configured devices."""
        database = Database('aztech-adapter')
        if not database.open():
            return

        config = database.load_config()
        database.close()

        if not config or 'addresses' not in config:
            return

        for address in config['addresses']:
            try:
                dev = Discover.discover_single(address)
            except (OSError, UnboundLocalError) as e:
                print('Failed to connect to {}: {}'.format(address, e))
                continue

            if dev:
                self._add_device(dev)
    def add_from_config(self):
        """Attempt to add all previously configured devices."""
        database = Database(ADAPTER_NAME)

        if not database.open():
            return

        config = database.load_config()
        database.close()

        for address in config['addresses']:
            try:
                # Try to reconnect with the existing device
                # dev = find_device()
                pass
            except (OSError, UnboundLocalError) as e:
                print('Failed to connect to {}: {}'.format(address, e))
                continue

            if dev:
                self._add_device(dev)
Example #22
0
    def load_config(self):
        """Load config from database and create device."""
        database = Database('speed-test-adapter')
        if not database.open():
            return

        config = database.load_config()
        database.close()

        if not config or \
                'provider' not in config or \
                'pollInterval' not in config:
            return

        self.provider = config['provider']
        self.poll_interval = config['pollInterval']

        if 'server' in config and \
                type(config['serverID']) is int and \
                config['serverID'] != 0:
            self.server_id = config['serverID']

        self.start_pairing()
Example #23
0
    def __init__(self, verbose=False):
        """
        Initialize the object.

        verbose -- whether or not to enable verbose logging
        """
        self.name = self.__class__.__name__
        Adapter.__init__(self,
                         'dht22-adapter',
                         'dht22-adapter',
                         verbose=verbose)

        database = Database('dht22-adapter')
        if not database.open():
            return

        self.config = database.load_config()
        database.close()

        if not self.config:
            return

        self.start_pairing()
Example #24
0
    def _add_from_config(self):
        """Attempt to add all configured devices."""
        database = Database('magichome-adapter')
        if not database.open():
            return

        config = database.load_config()
        database.close()

        if not config or 'addresses' not in config:
            return

        for address in config['addresses']:
            try:
                sock = socket.socket(
                    socket.AF_INET,  # Internet
                    socket.SOCK_DGRAM  # UDP
                )
                sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
                sock.settimeout(2)  # seconds - in reality << 1 is needed

                # connect to network
                sock.sendto('HF-A11ASSISTHREAD'.encode('ascii'),
                            (address, 48899))
                data, addr = sock.recvfrom(1024)
                data = data.decode('ascii')
                socketip, socketmac, socketmodel = data.split(',')
                dev = dict()
                dev['ipaddr'] = socketip
                dev['id'] = socketmac
                dev['model'] = socketmodel
            except (OSError, UnboundLocalError) as e:
                print('Failed to connect to {}: {}'.format(address, e))
                continue

            if dev:
                self._add_device(dev)
 def __init__(self, package_name):
     Database.__init__(self, package_name, None)
     self.temp_unit_celsius = True
     self.log_level = None
     self.open()
     self.load()
 def load(self):
     self.config_changed = False
     db = Database(self.package_name)
     db.open()
     self.config = db.load_config()
     db.close()
    def add_from_config(self):
        """Attempt to add all configured devices."""
        
        store_updated_settings = False
        
        try:
            database = Database('candleappstore')
            if not database.open():
                print("Could not open settings database")
                return
            
            config = database.load_config()
            database.close()
            
        except:
            print("Error! Failed to open settings database.")
        
        if not config:
            print("Error loading config from database")
            return
        
        #print(str(config))

        if 'Debugging' in config:
            print("-Debugging was in config")
            self.DEBUG = bool(config['Debugging'])
            if self.DEBUG:
                print("Debugging enabled")        


        if 'Keep addon data when uninstalling' in config:
            if self.DEBUG:
                print("-Keep addon data when uninstalling preference was in config: " + str(config['Keep addon data when uninstalling']))
            self.keep_data_on_uninstall = bool(config['Keep addon data when uninstalling'])
        


        if 'Show developer options' in config:
            if self.DEBUG:
                print("-Developer preference was in config: " + str(config['Show developer options']))
            self.developer = bool(config['Show developer options'])  
        
        
        # Currently not used anymore. Settings are now stored in persistence.json where possible.
        try:
            # Store the settings that were changed by the add-on.
            if store_updated_settings:
                if self.DEBUG:
                    print("Storing overridden settings")

                database = Database('candleappstore')
                if not database.open():
                    print("Error, could not open settings database to store modified settings")
                    #return
                else:
                    database.save_config(config)
                    database.close()
                    if self.DEBUG:
                        print("Stored overridden preferences into the database")
        except Exception as ex:
            print("Error! Failed to store overridden settings in database: " + str(ex))
        
        
        
        # Candleappstore name
        try:
            if 'Candleappstore name' in config:
                if self.DEBUG:
                    print("-Candleappstore name is present in the config data.")
                self.candleappstore_name = str(config['Candleappstore name'])
        except Exception as ex:
            print("Error loading candleappstore name from config: " + str(ex))
        
        
        
        # Candleappstore password
        try:
            if 'Candleappstore password' in config:
                if self.DEBUG:
                    print("-Candleappstore password is present in the config data.")
                self.candleappstore_password = str(config['Candleappstore password'])
        except Exception as ex:
            print("Error loading candleappstore password from config: " + str(ex))
        

        # Api token
        try:
            if 'Authorization token' in config:
                if str(config['Authorization token']) != "":
                    self.token = str(config['Authorization token'])
                    self.persistent_data['token'] = str(config['Authorization token'])
                    if self.DEBUG:
                        print("-Authorization token is present in the config data.")
        except Exception as ex:
            print("Error loading api token from settings: " + str(ex))