def __init__(self, verbose=False): self.name = self.__class__.__name__ Adapter.__init__(self, 'switchmate-adapter', 'switchmate-adapter', verbose=verbose) self.start_pairing(_TIMEOUT)
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()
def __init__(self, verbose=False): """ Initialize the object. verbose -- whether or not to enable verbose logging """ #print("initialising adapter from class") self.pairing = False self.addon_name = 'display-toggle' self.DEBUG = True self.name = self.__class__.__name__ Adapter.__init__(self, self.addon_name, self.addon_name, verbose=verbose) self.addon_path = os.path.join(os.path.expanduser('~'), '.mozilla-iot', 'addons', self.addon_name) #self.persistence_file_path = os.path.join(os.path.expanduser('~'), '.mozilla-iot', 'data', self.addon_name,'persistence.json') try: self.display_toggle = DisplayToggleDevice(self) self.handle_device_added(self.display_toggle) if self.DEBUG: print("display_toggle device created") except Exception as ex: print("Could not create display_toggle device: " + 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, '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)
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 __init__(self, api_handler, verbose=False): """ Initialize the object. verbose -- whether or not to enable verbose logging """ self.api_handler = api_handler self.name = self.api_handler.addon_name #self.__class__.__name__ #print("adapter name = " + self.name) self.adapter_name = self.api_handler.addon_name #'PrivacyManager-adapter' Adapter.__init__(self, self.adapter_name, self.adapter_name, verbose=verbose) self.DEBUG = self.api_handler.DEBUG try: # Create the thing privacy_manager_device = PrivacyManagerDevice( self, api_handler, "privacy_manager", "Privacy Manager", "OnOffSwitch") self.handle_device_added(privacy_manager_device) self.devices['privacy_manager'].connected = True self.devices['privacy_manager'].connected_notify(True) self.thing = self.get_device("privacy_manager") print("adapter: self.ready?: " + str(self.ready)) except Exception as ex: print("Error during privacy manager adapter init: " + str(ex))
def __init__(self, verbose=False): """ Initialize the object. verbose -- whether or not to enable verbose logging """ #print("initialising adapter from class") self.pairing = False self.addon_name = 'display-toggle' self.DEBUG = True self.name = self.__class__.__name__ Adapter.__init__(self, self.addon_name, self.addon_name, verbose=verbose) self.addon_path = os.path.join(self.user_profile['addonsDir'], self.addon_name) #self.persistence_file_path = os.path.join(self.user_profile['dataDir'], self.addon_name,'persistence.json') try: self.display_toggle = DisplayToggleDevice(self) self.handle_device_added(self.display_toggle) if self.DEBUG: print("display_toggle device created") except Exception as ex: print("Could not create display_toggle device: " + str(ex)) # Make sure the display is on initially. self.set_power_state(1)
def __init__(self, verbose): self.name = self.__class__.__name__ Adapter.__init__(self, 'virtual-python-things-adapter', 'virtual-python-things-adapter', verbose=verbose) self.pairing = False self.start_pairing(_TIMEOUT)
def __init__(self, verbose=False): self.name = self.__class__.__name__ Adapter.__init__(self, 'arduino-adapter', 'arduino-adapter', verbose=verbose) self.pairing = False self.start_pairing(_TIMEOUT)
def __init__(self, verbose=False): """ verbose -- enable verbose logging """ self.name = self.__class__.__name__ Adapter.__init__(self, 'date-time-adapter', 'date-time-adapter', verbose=verbose) self._config = Config(self.package_name) self.start_pairing(1)
def __init__(self, verbose=False): """ Initialize the object. verbose -- whether or not to enable verbose logging """ self.name = self.__class__.__name__ Adapter.__init__(self, ADAPTER_NAME, ADAPTER_NAME, verbose=verbose) self.pairing = False self.add_from_config() self.start_pairing(_PAIRING_TIMEOUT)
def __init__(self, verbose=False): """ Initialize the object. verbose -- whether or not to enable verbose logging """ self.name = self.__class__.__name__ Adapter.__init__(self, 'lifx-adapter', 'lifx-adapter', verbose=verbose) self.pairing = False self.start_pairing(_TIMEOUT)
def __init__(self, verbose=False): self.name = self.__class__.__name__ Adapter.__init__(self, 'arduino-adapter', 'arduino-adapter', verbose=verbose) self.handle_device_added(ArduinoDigitalOutput(self, "RED_LED1", "192.168.1.95", 3)) self.handle_device_added(ArduinoDigitalOutput(self, "BLUE_LED1", "192.168.1.95", 5)) self.handle_device_added(ArduinoDigitalInput(self, "BUTTON1", "192.168.1.95", 3)) self.handle_device_added(ArduinoDigitalOutput(self, "RED_LED2", "192.168.1.90", 3)) self.handle_device_added(ArduinoDigitalOutput(self, "BLUE_LED2", "192.168.1.90", 5)) self.handle_device_added(ArduinoDigitalInput(self, "BUTTON2", "192.168.1.90", 3))
def __init__(self, api_handler, verbose=False): """ Initialize the object. verbose -- whether or not to enable verbose logging """ self.api_handler = api_handler self.name = self.api_handler.addon_name #self.__class__.__name__ #print("adapter name = " + self.name) self.adapter_name = self.api_handler.addon_name #'Highlights-adapter' Adapter.__init__(self, self.adapter_name, self.adapter_name, verbose=verbose) self.DEBUG = self.api_handler.DEBUG
def __init__(self, verbose=True): """ Initialize the object. verbose -- whether or not to enable verbose logging """ self.name = self.__class__.__name__ Adapter.__init__(self, 'snapclient', 'snapclient', verbose=verbose) self.server_address = "" self.server = None self.pairing = False self.start_pairing(_TIMEOUT)
def __init__(self, verbose=False): """ verbose -- enable verbose logging """ self.name = self.__class__.__name__ Adapter.__init__(self, 'zigbee-conbee-adapter', 'zigbee-conbee-adapter', verbose=verbose) self._config = Config(self.package_name) self.conbee_url = self._config.conbee_url() self.rest = DeconzRestApi(self.conbee_url) self.ws = None self.device_mapping = {} # Map between ligt/sensor and device logging.info('init ConBeeAdapter') self.start_pairing(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, 'speed-test-adapter', 'speed-test-adapter', verbose=verbose) self.pairing = False self.provider = None self.poll_interval = None self.server_id = None self.load_config()
def __init__(self, config, verbose=False): """ Initialize the object. config -- current user configuration verbose -- whether or not to enable verbose logging """ self.name = self.__class__.__name__ Adapter.__init__(self, 'bt-presence-adapter', 'bt-presence-adapter', verbose=verbose) self.pairing = False self.config = config for d in self.configured_devices(): self.create_device(d['name'], d['addr'], d['type'])
def __init__(self, verbose=False): """ Initialize the object. verbose -- whether or not to enable verbose logging """ self.pairing = False self.addon_name = 'sense-hat' self.DEBUG = True self.name = self.__class__.__name__ self.URL = 'https://github.com/rzr/sense-hat-webthing' Adapter.__init__(self, self.addon_name, self.addon_name, verbose=verbose) try: self.controller = SenseHat() device = SenseHatDevice(self) self.handle_device_added(device) if self.DEBUG: print("sense_hat_device created") self.devices[device.id].connected = True self.devices[device.id].connected_notify(True) imu_device = SenseHatImuDevice(self) self.handle_device_added(imu_device) if self.DEBUG: print("sense_hat_imu_device created") self.devices[imu_device.id].connected = True self.devices[imu_device.id].connected_notify(True) lightDevice = SenseHatLightDevice(self) self.handle_device_added(lightDevice) if self.DEBUG: print("sense_hat_light_device created") self.devices[lightDevice.id].connected = True self.devices[lightDevice.id].connected_notify(True) except Exception as ex: print("error: Could not create sense_hat_device: " + str(ex))
def __init__(self, verbose=False): """ Initialize the object. verbose -- whether or not to enable verbose logging """ self.pairing = False self.addon_name = 'awox-mesh-light' self.DEBUG = False self.name = self.__class__.__name__ self.URL = 'https://github.com/rzr/awox-mesh-light-webthing' Adapter.__init__(self, self.addon_name, self.addon_name, verbose=verbose) try: self._add_from_config() except Exception as ex: print("error: Could not create awox_mesh_light_device: " + 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, '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()
def __init__(self, verbose=True): """ Initialize the object. verbose -- whether or not to enable verbose logging """ print("Initialising adapter from class") self.pairing = False self.name = self.__class__.__name__ Adapter.__init__(self, 'network-presence-detection-adapter', 'network-presence-detection-adapter', verbose=verbose) print("Adapter ID = " + self.get_id()) self.DEBUG = False #True self.memory_in_weeks = 10 # How many weeks a device will be remembered as a possible device. self.time_window = 60 # How many minutes should a device be away before we concider it away? self.arping = False # Does the user also want to try using arping? self.add_from_config( ) # Here we get data from the settings in the Gateway interface. self.own_ip = 'unknown' # We scan only scan if the device itself has an IP address. self.ip_range = { } # we remember which IP addresses had a device. This makes them extra interesting, and they will get extra attention during scans. self.deep_scan_frequency = 10 # once every 10 scans we do a deep scan. self.scan_count = 0 # Used by the deep scan system. self.filename = None for path in _CONFIG_PATHS: if os.path.isdir(path): self.filename = os.path.join( path, 'network-presence-detection-adapter-devices.json') self.should_save = False # make sure the file exists: if self.filename: try: with open(self.filename) as file_object: printDebug("Loading json..", self.DEBUG) try: self.previously_found = json.load(file_object) except: printDebug("Empty json file", self.DEBUG) self.previously_found = {} printDebug( "Previously found items: = " + str(self.previously_found), self.DEBUG) except (IOError, ValueError): self.previously_found = {} print("Failed to load JSON file, generating new one.") with open(self.filename, 'w') as f: f.write('{}') else: self.previously_found = {} # Remove devices that have not been seen in a long time self.prune() # Present all devices to the gateway for key in self.previously_found: self._add_device(str(key), str(self.previously_found[key]['name']), str('...')) # Adding the device #_id = 'presence-{}'.format(key) self.devices[key].add_boolean_child('recently1', "Recently spotted", False) self.devices[key].add_integer_child('minutes_ago', "Minutes ago last seen", 99999) # Start the thread that updates the 'minutes ago' countdown on all lastseen properties. #t = threading.Thread(target=self.update_minutes_ago) #t.daemon = True #t.start() # We continuously scan for new devices, in an endless loop. The 255 addresses are split into a few chunks, and each chunk is given to a separate thread. self.own_ip = get_ip() if valid_ip(self.own_ip): while True: #def split_processing(items, num_splits=4): old_previous_found_count = len(self.previously_found) thread_count = 5 split_size = 51 threads = [] for i in range(thread_count): # determine the indices of the list this thread will handle start = i * split_size printDebug("thread start = " + str(start), self.DEBUG) # special case on the last chunk to account for uneven splits end = 255 if i + 1 == thread_count else (i + 1) * split_size printDebug("thread end = " + str(end), self.DEBUG) # Create the thread threads.append( threading.Thread(target=self.scan, args=(start, end))) threads[-1].daemon = True threads[-1].start() # start the thread we just created # Wait for all threads to finish for t in threads: t.join() printDebug("All threads are done", self.DEBUG) # If new devices were found, save the JSON file. if len(self.previously_found) > old_previous_found_count: self.save_to_json() self.update_the_rest()
def __init__(self, verbose=False): """ Initialize the object. verbose -- whether or not to enable verbose logging """ #print("initialising adapter from class") self.pairing = False self.addon_name = 'internet-radio' self.DEBUG = True self.name = self.__class__.__name__ Adapter.__init__(self, self.addon_name, self.addon_name, verbose=verbose) # Setup persistence #for path in _CONFIG_PATHS: # if os.path.isdir(path): # self.persistence_file_path = os.path.join( # path, # 'internet-radio-persistence.json' # ) # print("self.persistence_file_path is now: " + str(self.persistence_file_path)) self.addon_path = os.path.join(self.user_profile['addonsDir'], self.addon_name) #self.persistence_file_path = os.path.join(os.path.expanduser('~'), '.mozilla-iot', 'data', self.addon_name,'persistence.json') self.persistence_file_path = os.path.join(self.user_profile['dataDir'], self.addon_name, 'persistence.json') self.running = True self.audio_output_options = [] # Get audio output options if sys.platform != 'darwin': self.audio_controls = get_audio_controls() print(self.audio_controls) # create list of human readable audio-only output options for Shairport-sync for option in self.audio_controls: self.audio_output_options.append(option['human_device_name']) # LOAD CONFIG self.current_stream_url = None self.radio_stations = [] self.radio_stations_names_list = [] try: self.add_from_config() except Exception as ex: print("Error loading config: " + str(ex)) # Create list of radio station names for the radio thing. for station in self.radio_stations: if self.DEBUG: print("Adding station: " + str(station)) #print("adding station: " + str(station['name'])) self.radio_stations_names_list.append(str(station['name'])) # Get persistent data try: with open(self.persistence_file_path) as f: self.persistent_data = json.load(f) try: if 'audio_output' not in self.persistent_data: if self.DEBUG: print( "audio output was not in persistent data, adding it now." ) if len(self.audio_output_options) > 0: self.persistent_data['audio_output'] = str( self.audio_controls[0]['human_device_name']) else: self.persistent_data['audio_output'] = "" except: print("Error fixing audio output in persistent data") if self.DEBUG: print("Persistence data was loaded succesfully.") except: print( "Could not load persistent data (if you just installed the add-on then this is normal)" ) if len(self.audio_output_options) > 0: self.persistent_data = { 'power': False, 'station': self.radio_stations_names_list[0], 'volume': 100, 'audio_output': str(self.audio_controls[0]['human_device_name']) } else: self.persistent_data = { 'power': False, 'station': self.radio_stations_names_list[0], 'volume': 100, 'audio_output': "" } # Create the radio device try: internet_radio_device = InternetRadioDevice( self, self.radio_stations_names_list, self.audio_output_options) self.handle_device_added(internet_radio_device) if self.DEBUG: print("internet_radio_device created") self.devices['internet-radio'].connected = True self.devices['internet-radio'].connected_notify(True) except Exception as ex: print("Could not create internet_radio_device: " + str(ex)) self.player = None # Restore volume #try: # self.set_audio_volume(self.persistent_data['volume']) #except Exception as ex: # print("Could not restore radio station: " + str(ex)) # Restore station try: if self.persistent_data['station'] != None: if self.DEBUG: print( "Setting radio station to the one found in persistence data: " + str(self.persistent_data['station'])) self.set_radio_station(self.persistent_data['station']) else: if self.DEBUG: print("No radio station was set in persistence data") except Exception as ex: print( "couldn't set the radio station name to what it was before: " + str(ex)) # Restore power try: self.set_radio_state(bool(self.persistent_data['power'])) except Exception as ex: print("Could not restore radio station: " + str(ex))
def __init__(self, verbose=True): """ Initialize the object. verbose -- whether or not to enable verbose logging """ print("Starting Candleappstore addon") #print(str( os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lib') )) self.pairing = False self.ready = False self.DEBUG = False self.DEV = False self.addon_name = 'candleappstore' self.name = self.__class__.__name__ # CandleappstoreAdapter #print("self.name = " + str(self.name)) Adapter.__init__(self, self.addon_name, self.addon_name, verbose=verbose) #print("Adapter ID = " + self.get_id()) #os.environ["LD_LIBRARY_PATH"] = os.path.join(self.user_profile['addonsDir'],self.addon_name,'snips') # Get initial audio_output options #self.audio_controls = get_audio_controls() #print("audio controls: " + str(self.audio_controls)) self.developer = False self.running = True self.app_store_url = 'https://www.candlesmarthome.com/appstore/' self.exhibit_mode = False if os.path.isfile('/boot/exhibit_mode.txt'): self.exhibit_mode = True # Uninstall self.keep_data_on_uninstall = False self.disable_uninstall = False if os.path.isfile('/boot/disable_uninstall.txt'): self.disable_uninstall = True #print("os.uname() = " + str(os.uname())) # Some paths #print("self.user_profile:") #print(str(self.user_profile)) self.addon_path = os.path.join(self.user_profile['addonsDir'], self.addon_name) self.data_dir_path = os.path.join(self.user_profile['dataDir'], self.addon_name) # Make sure the data directory exists try: if not os.path.isdir(self.data_dir_path): os.mkdir( self.data_dir_path ) print("data directory did not exist, created it now") except Exception as ex: print("Error: could not make sure data dir exists: " + str(ex)) # Get persistent data try: self.persistence_file_path = os.path.join(self.data_dir_path, 'persistence.json') if self.DEBUG: print("self.persistence_file_path = " + str(self.persistence_file_path)) except: try: print("setting persistence file path failed, will try older method.") self.persistence_file_path = os.path.join(os.path.expanduser('~'), '.webthings', 'data', 'candleappstore','persistence.json') except: print("Double error making persistence file path") self.persistence_file_path = "/home/pi/.webthings/data/candleappstore/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 Exception as ex: first_run = True print("Could not load persistent data (if you just installed the add-on then this is normal): " + str(ex)) try: unique_id = generate_random_string(4) self.persistent_data = { 'unique_id':unique_id, 'addons':{} } except Exception as ex: print("Error creating initial persistence variable: " + str(ex)) #time.sleep(3) # give the network some more time to settle #self.mac = get_own_mac("wlan0") #self.hostname = get_own_hostname() #print("self.hostname = " + str(self.hostname)) #self.mac_zero = self.mac.replace(self.mac[len(self.mac)-1], '0') #print("mac = " + str(self.mac)) #print("mac_zero = " + str(self.mac_zero)) try: if 'unique_id' not in self.persistent_data: # to remember what the main candleappstore server is, for satellites. if self.DEBUG: print("unique_id was not in persistent data, adding it now.") self.persistent_data['unique_id'] = generate_random_string(20) self.save_persistent_data() if 'addons' not in self.persistent_data: if self.DEBUG: print("addons was not in persistent data, adding it now.") self.persistent_data['addons'] = {} if 'permissions' not in self.persistent_data: self.persistent_data['permissions'] = {} except Exception as ex: print("Error fixing missing values in persistent data: " + str(ex)) # LOAD CONFIG try: self.add_from_config() except Exception as ex: print("Error loading config: " + str(ex)) #self.ssid = self.candleappstore_name + " " + self.persistent_data['unique_id'] + "_nomap" #print("ssid = " + str(self.ssid)) # # Create UI # # Even if the user doesn't want to see a UI, it may be the case that the HTML is still loaded somewhere. So the API should be available regardless. try: self.api_handler = CandleappstoreAPIHandler(self, verbose=True) #self.manager_proxy.add_api_handler(self.api_handler) if self.DEBUG: print("Extension API handler initiated") except Exception as e: print("Failed to start API handler (this only works on gateway version 0.10 or higher). Error: " + str(e)) # create or remove developer.txt from /boot if self.developer: os.system('sudo touch /boot/developer.txt') os.system('sudo systemctl start rsyslog.service') else: if os.path.isfile('/boot/developer.txt'): os.system('sudo rm /boot/developer.txt') print("end of candle app store adapter init") self.ready = True
def __init__(self, verbose=False): """ Initialize the object. verbose -- whether or not to enable verbose logging """ #print("Initialising adapter from class") self.addon_name = 'network-presence-detection-adapter' self.name = self.__class__.__name__ Adapter.__init__(self, self.addon_name, self.addon_name, verbose=verbose) #print("Adapter ID = " + self.get_id()) #print("self.user_profile['baseDir'] = " + self.user_profile['baseDir']) self.DEBUG = True #self.memory_in_weeks = 10 # How many weeks a device will be remembered as a possible device. self.time_window = 10 # How many minutes should a device be away before we consider it away? self.own_ip = None # We scan only scan if the device itself has an IP address. self.add_from_config() # Here we get data from the settings in the Gateway interface. #self.DEBUG = False try: if self.own_ip == None: self.own_ip = get_ip() except: print("Could not get actual own IP address") self.should_brute_force_scan = True self.busy_doing_brute_force_scan = False self.last_brute_force_scan_time = 0 # Allows the add-on to start a brute force scan right away. self.seconds_between_brute_force_scans = 1800 #1800 # 30 minutes self.running = True self.saved_devices = [] self.addon_path = os.path.join(self.user_profile['addonsDir'], self.addon_name) self.persistence_file_path = os.path.join(self.user_profile['dataDir'], self.addon_name,'persistence.json') if self.DEBUG: print("self.persistence_file_path = " + str(self.persistence_file_path)) self.should_save = False try: with open(self.persistence_file_path) as file_object: #print("Loading json..") try: self.previously_found = json.load(file_object) except: #print("Empty json file") self.previously_found = {} #print("Previously found items: = " + str(self.previously_found)) except (IOError, ValueError): self.previously_found = {} print("Failed to load JSON file, generating new one.") try: with open(self.persistence_file_path, 'w') as f: f.write('{}') except Exception as ex: print("failed to create empty persistence file: " + str(ex)) self.previous_found_devices_length = len(self.previously_found) # Reset all the lastseen data from the persistence file, since it could be out of date. for key in self.previously_found: try: if 'lastseen' in self.previously_found[key]: self.previously_found[key]['lastseen'] = None except Exception as ex: print("Error setting lastseen of previously_found devices from persistence to None: " + str(ex)) # First scan time.sleep(2) # wait a bit before doing the quick scan. The gateway will pre-populate based on the 'handle-device-saved' method. self.arpa_scan() # get initial list of devices from arp -a if self.DEBUG: print("Starting the continous scan clock") try: t = threading.Thread(target=self.clock) t.daemon = True t.start() except: print("Error starting the continous light scan thread") #done = self.brute_force_scan() if self.DEBUG: print("Starting the periodic brute force scan thread") try: b = threading.Thread(target=self.brute_force_scan) b.daemon = True b.start() except: print("Error starting the brute force scan thread") while self.running: time.sleep(1)
def __init__(self, verbose=False): """ Initialize the object. verbose -- whether or not to enable verbose logging """ print("Initialising Xiaomi Miflora adapter") self.pairing = False self.name = self.__class__.__name__ Adapter.__init__(self, 'xiaomi-miflora', 'xiaomi-miflora', verbose=verbose) #print("Adapter ID = " + self.get_id()) for path in _CONFIG_PATHS: if os.path.isdir(path): self.persistence_file_path = os.path.join( path, 'xiaomi-miflora-persistence.json') self.add_on_path = os.path.join(os.path.expanduser('~'), '.mozilla-iot', 'addons', 'xiaomi-miflora') #print("self.add_on_path = " + str(self.add_on_path)) #self.metric = True #self.temperature_unit = 'degree celsius' self.DEBUG = False self.initial_scan_done = False self.running = True self.macs = set() self.stragglers = set() self.busy = False # Whether a poll is already in progress. self.last_update_all_time = 0 # When the last full polling of all devices was done self.last_scan_time = 0 # When the last full scan for new devices was done self.polling_interval_seconds = 24 * 60 * 60 # By default the add-on polls every 24 hours. # Load settings try: self.add_from_config() except Exception as ex: print( "Error loading config (and initialising BluetoothMiflora library?): " + str(ex)) # Do an initial scan to populate the devices done = self.start_scan() # Start the clock that checks if a new full poll should be performed. 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=True): """ Initialize the object. verbose -- whether or not to enable verbose logging """ print("initialising adapter from class") self.addon_name = 'airport' self.name = self.__class__.__name__ Adapter.__init__(self, self.addon_name, self.addon_name, verbose=verbose) #print("Adapter ID = " + self.get_id()) self.pairing = False self.DEBUG = True self.running = True self.audio = False self.video = False self.rpiplay_debug = "" self.addon_path = os.path.join(self.user_profile['addonsDir'], self.addon_name) self.persistence_file_path = os.path.join(self.user_profile['dataDir'], self.addon_name,'persistence.json') # Get resolution of display # Get audio controls self.audio_controls = get_audio_controls() print(str(self.audio_controls)) # Get persistent data try: with open(self.persistence_file_path) as f: self.persistent_data = json.load(f) if self.DEBUG: print("Persistent data was loaded succesfully.") except: print("Could not load persistent data (if you just installed the add-on then this is normal)") self.persistent_data = {'audio_output': str(self.audio_controls[0]['human_device_name']) ,'video_audio_output':'analog'} print("persistent data: " + str(self.persistent_data)) # SHAIRPORT self.shairport_path = os.path.join(self.addon_path, 'shairport', 'shairport') self.shairport_library_path = os.path.join(self.addon_path, 'shairport') self.shairport_default_conf_path = os.path.join(self.addon_path, 'shairport', 'shairport_default.conf') #self.shairport_conf_path = os.path.join(self.addon_path, 'shairport', 'shairport.conf') self.shairport_conf_path = os.path.join(self.user_profile['addonsDir'], self.addon_name,'shairport.conf') self.shairport_start_command = "LD_LIBRARY_PATH='" + self.shairport_library_path + "' " + self.shairport_path + " -j -c " + self.shairport_conf_path print("self.shairport_conf_path = " + self.shairport_conf_path) # RPIPLAY self.video_audio_output_options = ['off','analog','hdmi'] self.rpiplay_path = os.path.join(self.addon_path, 'rpiplay', 'rpiplay') self.rpiplay_library_path = os.path.join(self.addon_path, 'rpiplay') # Get hostname try: self.hostname = str(socket.gethostname()) self.hostname = self.hostname.title() except: print("failed to get hostname") self.hostname = 'Candle' # Get configuration try: self.add_from_config() except Exception as ex: print("Error loading config: " + str(ex)) # create list of human readable audio-only output options for Shairport-sync self.audio_output_options = [] for option in self.audio_controls: self.audio_output_options.append( option['human_device_name'] ) # Start streaming servers if self.audio: print("Enabling Shairport-sync airplay audio receiver") self.set_audio_output(self.persistent_data['audio_output']) if self.video: print("Enabling RPiPlay airplay video receiver") self.screen_width = run_command('cat /sys/class/graphics/fb0/virtual_size | cut -d, -f1') self.screen_height = run_command('cat /sys/class/graphics/fb0/virtual_size | cut -d, -f2') if self.screen_width.startswith('Error'): print("Error getting display size") self.screen_width = 1920 self.screen_height = 1080 print("Detected display size:") print(self.screen_width) print(self.screen_height) self.set_video_audio_output(str(self.persistent_data['video_audio_output'])) # Create Airport device try: #airport_device = AirportDevice(self, self.audio_output_options, self.video_audio_output_options) airport_device = AirportDevice(self, self.audio_output_options, self.video_audio_output_options) #print(str(airport_device)); self.handle_device_added( airport_device ) #if self.DEBUG: print("airport device created") except Exception as ex: print("Could not create airport device: " + str(ex)) print("End of Airport adapter init process")
def __init__(self, verbose=True): """ Initialize the object. verbose -- whether or not to enable verbose logging """ print("Initialising P1 adapter") self.pairing = False self.name = self.__class__.__name__ self.addon_name = 'p1-adapter' Adapter.__init__(self, 'p1-adapter', 'p1-adapter', verbose=verbose) #print("Adapter ID = " + self.get_id()) self.addon_path = os.path.join(self.user_profile['addonsDir'], self.addon_name) self.DEBUG = True self.first_request_done = False self.initial_serial_devices = [] self.running = True self.usb_override = False self.usb_port = "/dev/ttyUSB0" self.previous_consumed_total = None self.previous_produced_total = None self.previous_gas_total = None try: self.scan_usb_ports() except: print("Error during scan of usb ports") try: self.add_from_config() except Exception as ex: print("Error loading config (and initialising PyP1 library?): " + str(ex)) # If only one USB serial device is available, we pick that one anyway, regardless of what the user has selected in the config. try: if len(self.initial_serial_devices ) == 1 and self.usb_override == False: self.usb_port = self.initial_serial_devices[0] print("only one Serial USB device found, selecting that one.") except Exception as ex: print("Error with auto selection of USB port: " + str(ex)) try: print("Attempting to start P1 connection with USB port: " + self.usb_port) self.meter = SmartMeter(self.usb_port) #print("self.meter is now: " + str(self.meter)) try: # Create the p1 device, and if succesful, start the internal clock try: p1_device = P1Device(self) self.handle_device_added(p1_device) self.devices['p1-device'].connected = True self.devices['p1-device'].connected_notify(True) self.thing = self.get_device("p1-device") # Start the 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") except Exception as ex: print("Could not create p1_device: " + str(ex)) except Exception as ex: print("Error starting p1 meter: " + str(ex)) except Exception as ex: print("Error loading serial: " + str(ex)) print("End of P1 adapter init process")