def __init__(self, adapter, verbose=False): """Initialize the object.""" #print("INSIDE API HANDLER INIT") self.adapter = adapter #self.addon_name = 'hootspot-handler' self.DEBUG = self.adapter.DEBUG # Intiate extension addon API handler try: manifest_fname = os.path.join( os.path.dirname(__file__), '..', 'manifest.json' ) with open(manifest_fname, 'rt') as f: manifest = json.load(f) #print("manifest id in hotspot handler: " + str(manifest['id'])) APIHandler.__init__(self, manifest['id']) self.manager_proxy.add_api_handler(self) if self.DEBUG: print("self.manager_proxy = " + str(self.manager_proxy)) print("Created new API HANDLER: " + str(manifest['id'])) except Exception as e: print("Failed to init UX extension API handler: " + str(e))
def __init__(self, verbose=False): """Initialize the object.""" #print("INSIDE API HANDLER INIT") self.addon_name = 'privacy-manager' self.server = 'http://127.0.0.1:8080' self.DEV = False self.DEBUG = False self.things = [] # Holds all the things, updated via the API. Used to display a nicer thing name instead of the technical internal ID. self.data_types_lookup_table = {} try: manifest_fname = os.path.join( os.path.dirname(__file__), '..', 'manifest.json' ) with open(manifest_fname, 'rt') as f: manifest = json.load(f) APIHandler.__init__(self, manifest['id']) self.manager_proxy.add_api_handler(self) # LOAD CONFIG try: self.add_from_config() except Exception as ex: print("Error loading config: " + str(ex)) if self.DEBUG: print("self.manager_proxy = " + str(self.manager_proxy)) print("Created new API HANDLER: " + str(manifest['id'])) except Exception as e: print("Failed to init UX extension API handler: " + str(e)) try: #self.addon_path = os.path.join(os.path.expanduser('~'), '.webthings', 'addons', 'privacy-manager') self.addon_path = os.path.join(self.user_profile['addonsDir'], self.addon_name) self.log_dir_path = os.path.join(self.user_profile['baseDir'], 'log') self.log_db_path = os.path.join(self.log_dir_path, 'logs.sqlite3') except Exception as e: print("Failed to further init UX extension API handler: " + str(e)) # Respond to gateway version try: if self.DEBUG: print(self.gateway_version) except: print("self.gateway_version did not exist") while(True): sleep(1)
def __init__(self, verbose=False): """Initialize the object.""" print("INSIDE API HANDLER INIT") try: manifest_fname = os.path.join(os.path.dirname(__file__), '..', 'manifest.json') #self.adapter = adapter #print("ext: self.adapter = " + str(self.adapter)) with open(manifest_fname, 'rt') as f: manifest = json.load(f) APIHandler.__init__(self, manifest['id']) self.manager_proxy.add_api_handler(self) self.DEBUG = True print("self.manager_proxy = " + str(self.manager_proxy)) print("Created new API HANDLER: " + str(manifest['id'])) except Exception as e: print("Failed to init UX extension API handler: " + str(e))
def __init__(self, verbose=False): """Initialize the object.""" #print("INSIDE API HANDLER INIT") self.addon_name = 'followers' self.running = True self.server = 'http://127.0.0.1:8080' self.DEBUG = False self.things = [ ] # Holds all the things, updated via the API. Used to display a nicer thing name instead of the technical internal ID. self.data_types_lookup_table = {} self.token = None # LOAD CONFIG try: self.add_from_config() except Exception as ex: print("Error loading config: " + str(ex)) #self.DEBUG = True # Paths # Get persistent data try: self.persistence_file_path = os.path.join( self.user_profile['dataDir'], self.addon_name, 'persistence.json') except: try: print( "setting persistence file path failed, will try older method." ) self.persistence_file_path = os.path.join( os.path.expanduser('~'), '.mozilla-iot', 'data', self.addon_name, 'persistence.json') except: print("Double error making persistence file path") self.persistence_file_path = "/home/pi/.mozilla/data/" + self.addon_name + "/persistence.json" if self.DEBUG: print("Current working directory: " + str(os.getcwd())) first_run = False try: with open(self.persistence_file_path) as f: self.persistent_data = json.load(f) if self.DEBUG: print("Persistence data was loaded succesfully.") except: first_run = True print( "Could not load persistent data (if you just installed the add-on then this is normal)" ) self.persistent_data = {'items': []} print("self.persistent_data is now: " + str(self.persistent_data)) # Is there user profile data? #try: # print(str(self.user_profile)) #except: # print("no user profile data") # Intiate extension addon API handler try: manifest_fname = os.path.join(os.path.dirname(__file__), '..', 'manifest.json') with open(manifest_fname, 'rt') as f: manifest = json.load(f) APIHandler.__init__(self, manifest['id']) self.manager_proxy.add_api_handler(self) if self.DEBUG: print("self.manager_proxy = " + str(self.manager_proxy)) print("Created new API HANDLER: " + str(manifest['id'])) except Exception as e: print("Failed to init UX extension API handler: " + str(e)) # Respond to gateway version try: if self.DEBUG: print(self.gateway_version) except: print("self.gateway_version did not exist") #while(True): # sleep(1) # Start the internal clock print("Starting the internal clock") try: if self.token != None: t = threading.Thread(target=self.clock) t.daemon = True t.start() except: print("Error starting the clock thread")
def __init__(self, verbose=False): """Initialize the object.""" #print("INSIDE API HANDLER INIT") self.addon_name = 'photo-frame' self.server = 'http://127.0.0.1:8080' self.DEV = True self.DEBUG = True self.things = [ ] # Holds all the things, updated via the API. Used to display a nicer thing name instead of the technical internal ID. self.data_types_lookup_table = {} self.interval = 30 self.contain = 1 self.clock = False #os.environ["DISPLAY"] = ":0.0" try: manifest_fname = os.path.join(os.path.dirname(__file__), '..', 'manifest.json') with open(manifest_fname, 'rt') as f: manifest = json.load(f) APIHandler.__init__(self, manifest['id']) self.manager_proxy.add_api_handler(self) # LOAD CONFIG try: self.add_from_config() except Exception as ex: print("Error loading config: " + str(ex)) if self.DEBUG: print("self.manager_proxy = " + str(self.manager_proxy)) print("Created new API HANDLER: " + str(manifest['id'])) except Exception as e: print("Failed to init UX extension API handler: " + str(e)) try: self.addon_path = os.path.join(self.user_profile['addonsDir'], self.addon_name) #self.persistence_file_folder = os.path.join(self.user_profile['configDir']) self.photos_dir_path = os.path.join(self.addon_path, 'photos') except Exception as e: print("Failed to make paths: " + str(e)) try: if not os.path.isdir(self.photos_dir_path): os.mkdir(self.photos_dir_path) except: print("Error making photos directory") # Respond to gateway version try: if self.DEBUG: print("Gateway version: " + self.gateway_version) except: if self.DEBUG: print("self.gateway_version did not exist") #self.keyboard = Controller() while (True): sleep(1)
def __init__(self, verbose=False): """Initialize the object.""" #print("INSIDE API HANDLER INIT") self.addon_name = 'highlights' self.running = True self.server = 'http://127.0.0.1:8080' self.DEV = True self.DEBUG = False self.things = [] # Holds all the things, updated via the API. Used to display a nicer thing name instead of the technical internal ID. self.data_types_lookup_table = {} self.token = None # LOAD CONFIG try: self.add_from_config() except Exception as ex: print("Error loading config: " + str(ex)) # Get complete things dictionary via API try: self.things = self.api_get("/things") #print("Did the things API call. Self.things is now:") #print(str(self.things)) except Exception as ex: print("Error getting updated things data via API: " + str(ex)) # Temporary moving of persistence files try: old_location = os.path.join(os.path.expanduser('~'), '.mozilla-iot.old', 'data', self.addon_name,'persistence.json') new_location = os.path.join(os.path.expanduser('~'), '.webthings', 'data', self.addon_name,'persistence.json') if os.path.isfile(old_location) and not os.path.isfile(new_location): print("moving persistence file to new location: " + str(new_location)) os.rename(old_location, new_location) except Exception as ex: print("Error copying old persistence file to new location: " + str(ex)) # Paths # Get persistent data try: #print("self.user_profile['dataDir'] = " + str(self.user_profile)) self.persistence_file_path = os.path.join(self.user_profile['dataDir'], self.addon_name, 'persistence.json') except: try: if self.DEBUG: print("setting persistence file path failed, will try older method.") self.persistence_file_path = os.path.join(os.path.expanduser('~'), '.webthings', 'data', self.addon_name,'persistence.json') except: if self.DEBUG: print("Double error making persistence file path") self.persistence_file_path = "/home/pi/.webthings/data/" + self.addon_name + "/persistence.json" if self.DEBUG: print("Current working directory: " + str(os.getcwd())) first_run = False try: with open(self.persistence_file_path) as f: self.persistent_data = json.load(f) if self.DEBUG: print("Persistence data was loaded succesfully.") except: first_run = True print("Could not load persistent data (if you just installed the add-on then this is normal)") self.persistent_data = {'items':[]} if self.DEBUG: print("Highlights self.persistent_data is now: " + str(self.persistent_data)) try: self.adapter = HighlightsAdapter(self,verbose=False) #self.manager_proxy.add_api_handler(self.extension) #print("ADAPTER created") except Exception as e: print("Failed to start ADAPTER. Error: " + str(e)) # Is there user profile data? #try: # print(str(self.user_profile)) #except: # print("no user profile data") # Intiate extension addon API handler try: manifest_fname = os.path.join( os.path.dirname(__file__), '..', 'manifest.json' ) with open(manifest_fname, 'rt') as f: manifest = json.load(f) APIHandler.__init__(self, manifest['id']) self.manager_proxy.add_api_handler(self) if self.DEBUG: print("self.manager_proxy = " + str(self.manager_proxy)) print("Created new API HANDLER: " + str(manifest['id'])) except Exception as e: print("Failed to init UX extension API handler: " + str(e)) # Respond to gateway version try: if self.DEBUG: print(self.gateway_version) except: print("self.gateway_version did not exist") # Start the internal clock if self.DEBUG: print("Starting the internal clock") try: t = threading.Thread(target=self.clock) t.daemon = True t.start() except: print("Error starting the clock thread")
def __init__(self, verbose=False): """Initialize the object.""" #print("INSIDE API HANDLER INIT") self.addon_name = 'bluetoothpairing' self.running = True self.server = 'http://127.0.0.1:8080' self.DEBUG = False self.things = [] # Holds all the things, updated via the API. Used to display a nicer thing name instead of the technical internal ID. self.data_types_lookup_table = {} self.token = None self.bl = None # LOAD CONFIG try: self.add_from_config() except Exception as ex: print("Error loading config: " + str(ex)) self.DEBUG = True first_run = False try: with open(self.persistence_file_path) as f: self.persistent_data = json.load(f) if self.DEBUG: print("Persistence data was loaded succesfully.") except: first_run = True print("Could not load persistent data (if you just installed the add-on then this is normal)") self.persistent_data = {'items':[]} if self.DEBUG: print("Bluetoothpairing self.persistent_data is now: " + str(self.persistent_data)) #try: #self.adapter = BluetoothpairingAdapter(self,verbose=False) #self.manager_proxy.add_api_handler(self.extension) #print("ADAPTER created") #except Exception as e: # print("Failed to start ADAPTER. Error: " + str(e)) # Is there user profile data? #try: # print(str(self.user_profile)) #except: # print("no user profile data") # Intiate extension addon API handler try: manifest_fname = os.path.join( os.path.dirname(__file__), '..', 'manifest.json' ) with open(manifest_fname, 'rt') as f: manifest = json.load(f) APIHandler.__init__(self, manifest['id']) self.manager_proxy.add_api_handler(self) if self.DEBUG: print("self.manager_proxy = " + str(self.manager_proxy)) print("Created new API HANDLER: " + str(manifest['id'])) except Exception as e: print("Failed to init UX extension API handler: " + str(e)) # Respond to gateway version try: if self.DEBUG: print("Mozilla Gateway version: " + str(self.gateway_version)) except: print("self.gateway_version did not exist") # Start the internal clock #print("Starting the internal clock") #try: # t = threading.Thread(target=self.clock) # t.daemon = True # t.start() #except: # print("Error starting the clock thread") print("bl") try: self.bl = Bluetoothctl() self.bl.make_agent() if self.DEBUG: print("bluetooth seems ok: " + str(self.gateway_version)) except Exception as ex: print("Error initialising bluetooth object: " + str(ex))