def save_configuration(self, duration, speed): """ Save board configuration Args: duration (float): message duration (cycling time) speed (slow|normal|fast): message scrolling speed Raises: InvalidParameter, MissingParameter """ if duration is None: raise MissingParameter(u'Duration parameter is missing') if duration < 5 or duration > 60: raise InvalidParameter( u'Duration value must be between 5 and 60 seconds') if speed is None or len(speed) == 0: raise MissingParameter(u'Speed parameter is missing') if speed not in self.SPEEDS: raise InvalidParameter(u'Speed value is not valid') #save config self._update_config({u'duration': float(duration), u'speed': speed}) #update board configuration self.board.set_scroll_speed(self.SPEEDS[speed]) #stop current task if self.__display_task: self.__display_task.stop() #and restart new one self.__display_task = BackgroundTask(self.__display_message, self.logger, float(duration)) self.__display_task.start()
def set_provider(self, provider_id, apikey): """ Set speechtotext provider Args: provider_id (int): provider id apikey (string): provider apikey Return: bool: True if action succeed """ if provider_id is None: raise MissingParameter(u'Parameter provider is missing') if not self.__check_provider(provider_id): raise InvalidParameter(u'Specified provider is not valid. Please check list of supported provider.') if apikey is None or len(apikey.strip())==0: raise MissingParameter(u'Parameter apikey is missing') #save config config = self._get_config() #need to convert provider id to string because json does not support int as map/dict key provider_id_str = str(provider_id) providersapikeys = self._get_config_field(u'providerapikeys') providersapikeys[provider_id_str] = apikey config = { u'providerid': provider_id_str, u'providerapikeys': providersapikeys } if not self._update_config(config): return False #restart speech recognition task self.__restart_speech_recognition_task() return True
def set_config(self, userkey, apikey): """ Set configuration Params: userkey (string): user key apikey: user apikey Returns: bool: True if config saved successfully """ if userkey is None or len(userkey) == 0: raise MissingParameter(u'Userkey parameter is missing') if apikey is None or len(apikey) == 0: raise MissingParameter(u'Apikey parameter is missing') #test config try: self.test(userkey, apikey) except CommandInfo as e: #info received but not used here self.logger.info(u'Test returns info: %s' % unicode(e)) except Exception as e: raise CommandError(unicode(e)) #save config return self._update_config({u'userkey': userkey, u'apikey': apikey})
def _check_and_get_config(self, provider, server, port, login, password, tls, ssl, sender): """ Check and get valid configuration """ #check parameters if provider in ('gmail', 'yahoo'): if login is None or len(login) == 0: raise MissingParameter(u'Parameter "login" is missing') if password is None or len(password) == 0: raise MissingParameter(u'Parameter "password" is missing') else: if server is None or len(server) == 0: raise MissingParameter(u'Parameter "server" is missing') #force some parameters if necessary if provider in self.PROVIDERS: self.logger.debug(u'Force parameters to configured provider') server = self.PROVIDERS[provider][u'server'] port = self.PROVIDERS[provider][u'port'] tls = self.PROVIDERS[provider][u'tls'] ssl = self.PROVIDERS[provider][u'ssl'] sender = login self.logger.debug( 'Updated parameters: provider=%s server=%s port=%s login=%s password=%s tls=%s ssl=%s sender=%s' % (provider, server, port, login, password, tls, ssl, sender)) return (provider, server, port, login, password, tls, ssl, sender)
def set_credentials(self, username, password, phone_numbers): """ Set BulkSms credentials Args: username (string): username password (string): password phone_numbers (string): phone numbers (coma separated if many) Returns: bool: True if credentials saved successfully """ if username is None or len(username)==0: raise MissingParameter(u'Username parameter is missing') if password is None or len(password)==0: raise MissingParameter(u'Password parameter is missing') if phone_numbers is None or len(phone_numbers)==0: raise MissingParameter(u'Phone_numbers parameter is missing') if phone_numbers.strip().find(u' ')!=-1 or phone_numbers.strip().find(u';')!=-1: raise InvalidParameter(u'Phone numbers must be separated by coma (,)') #try to get credits credits = self.get_credits(username, password) return self._update_config({ u'username': username, u'password': password, u'phone_numbers': phone_numbers, u'credits': credits })
def add_leds_profile(self, name, repeat, actions): """ Add leds profile Args: name (string): profile name repeat (int): repeat value (see REPEAT_XXX) actions (list): list of actions (see ACTION_XXX) Returns: bool: True if led profile added successfully Raises: InvalidParameter: if invalid function parameter is specified MissingParameter: if function parameter is missing """ #check params if name is None or len(name) == 0: raise MissingParameter(u'Parameter name is missing') if repeat is None: raise MissingParameter(u'Parameter repeat is missing') if repeat not in (self.REPEAT_NONE, self.REPEAT_1, self.REPEAT_2, self.REPEAT_3, self.REPEAT_4, self.REPEAT_5, self.REPEAT_INF): raise InvalidParameter( u'Parameter repeat is not valid. See available values') if actions is None: raise MissingParameter(u'Parameter actions is missing') if len(actions) == 0: raise InvalidParameter( u'You must add at least one action in leds profile') #check name leds_profiles = self._get_config_field(u'leds_profiles') for profile in leds_profiles: if profile[u'name'] == name: raise InvalidParameter( u'Profile with same name already exists') #append new profile leds_profiles.append({ u'name': name, u'repeat': repeat, u'uuid': str(uuid.uuid4()), u'actions': actions, u'default': False }) #save config if not self._set_config_field(u'leds_profiles', leds_profiles): raise CommandError(u'Unable to save leds profile') return True
def set_credentials(self, userid, apikey): """ Set FreemobileSms credentials Params: userid: userid (string) apikey: apikey (string) Returns: bool: True if credentials saved successfully """ if userid is None or len(userid) == 0: raise MissingParameter(u'Userid parameter is missing') if apikey is None or len(apikey) == 0: raise MissingParameter(u'Apikey parameter is missing') #test credentials if not self.test(userid, apikey): raise CommandError(u'Unable to send test') #save config return self._update_config({u'userid': userid, u'apikey': apikey})
def test_leds_profile(self, profile_uuid): """ Test specified leds profile (play once) Args: profile_uuid (string): leds profile uuid Raises: CommandError: if error occured during command execution MissingParameter: if function parameter is missing """ #check parameters if self.__leds_profile_task is not None: raise CommandError( u'Leds profile is running. Please wait until end of it.') if profile_uuid is None or len(profile_uuid) == 0: raise MissingParameter(u'Parameter profile_uuid is missing') #get profile selected_profile = None for profile in self._get_config_field(u'leds_profiles'): if profile[u'uuid'] == profile_uuid: #profile found, stop statement selected_profile = profile break #check profile if selected_profile is None: self.logger.error(u'Unable to test leds profile with uuid %s' % profile_uuid) raise CommandError(u'Unable to test leds profile') #play profile self.__leds_profile_task = LedsProfileTask( self, selected_profile, self.__leds_profile_task_terminated) self.__leds_profile_task.enable_test() self.__leds_profile_task.start()
def remove_leds_profile(self, profile_uuid): """ Remove specified leds profile Args: profile_uuid (string): leds profile uuid """ #check parameters if self.__leds_profile_task is not None: raise CommandError( u'Leds profile is running. Please wait until end of it.') if profile_uuid is None or len(profile_uuid) == 0: raise MissingParameter(u'Parameter profile_uuid is missing') if profile_uuid.isdigit(): raise InvalidParameter(u'You can\'t delete default leds profiles') #get profile found = False leds_profiles = self._get_config_field(u'leds_profiles') for profile in leds_profiles: if profile[u'uuid'] == profile_uuid: #profile found, remove it found = True leds_profiles.remove(profile) break #check found if not found: self.logger.error(u'Unable to remove profile with uuid %s' % profile_uuid) raise CommandError(u'Unable to remove profile') #save config if not self._set_config_field(u'leds_profiles', leds_profiles): raise CommandError(u'Unable to save config') return True