Esempio n. 1
0
    def __init__(self):
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except:
            self.config = None

        self.start_blocking()
Esempio n. 2
0
 def __init__(self, mp3_only=False, wake_word=True):
     # get the configuration if needed
     '''
     try:
         self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
     except :
         self.config = None
     '''
     # print("In __init__ of Template")
     try:
         self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
     except Exception:
         self.config = None
     self.image_up = False
     self.introduction = True
     self.wake_word = wake_word
     self.tables = {}
     self.mp3_only = mp3_only
     self.intents = {
         "Explain": ["Components"],
         "Purpose": ["Components", "People"],
         "Availability": ["Location"],
         "hello": [],
         "bye": [],
         "none": []
     }
     self._get_tables()
Esempio n. 3
0
    def __init__(self):

        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except:
            self.config = None
            print "[Error] No config.ini file found! Please check.."
            sys.exit(1)

        self.mqtt_host = self.config.get('secret', {
            "mqtt_host": "localhost"
        }).get('mqtt_host', 'localhost')
        self.mqtt_port = self.config.get('secret', {
            "mqtt_port": "1883"
        }).get('mqtt_port', '1883')
        self.mqtt_addr = "{}:{}".format(self.mqtt_host, self.mqtt_port)

        self.site_id = self.config.get('secret', {
            "site_id": "default"
        }).get('site_id', 'default')
        self.if_fahrenheit = self.config.get('secret', {
            "if_fahrenheit": "false"
        }).get('if_fahrenheit', "false")
        self.bus = smbus2.SMBus(1)
        self.start_blocking()
 def __init__(self):
     print("Loading HomeManager")
     try:
         self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
     except:
         self.config = None
         print("[Warning] No config file")
     self.autho = self.config['secret']['http_api_token']
     self.header = {
         'Authorization': self.autho,
         "Content-Type": "application/json",
     }
     self.intent_processor = IntentProcessor()
     # Manage the calls to the Hass API
     self.steward = SnipsHomeManager(self.autho, self.header)
     self.last_question = None
     self.contexts = {
         "arrive_home": False,
         "at_home": False,
         "leaving_home": False,
         "out_home": False
     }
     self.questions = {
         "lights on": "do you want the lights on",
         "light_color": "what color do you want the lights",
         "light_brightness": "how bright do you want the light",
         "tv_on": "do you want the tv on"
     }
     # start listening to MQTT
     self.start_blocking()
    def __init__(self):
        # get the configuration if needed
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except :
            self.config = None

        # start listening to MQTT
        self.start_blocking()
    def __init__(self):
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except Exception:
            self.config = None

        self.start_blocking()
        self.last_type = 6
        self.last_number = 1
Esempio n. 7
0
    def __init__(self):
        # get the configuration if needed
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except Exception:
            self.config = None

        self.joke_service = JokeFileService()
        # start listening to MQTT
        self.start_blocking()
    def __init__(self):
        # get the configuration if needed
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
            self.mqtt_address = self.config.get("secret").get("mqtt")
        except:
            self.config = None
            self.mqtt_address = MQTT_ADDR

        # start listening to MQTT
        self.start_blocking()
    def __init__(self):
        # get the configuration
        try:
            global databaseurl
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
            databaseurl = self.config.get("secret").get("database")
        except:
            self.config = None

        # start listening to MQTT
        self.start_blocking()
Esempio n. 10
0
    def __init__(self, debug = False):

        self.debug = debug
        self.enable_confirmation = False

        # parameters

        self.mqtt_host = None
        self.mqtt_user = None
        self.mqtt_pass = None

        self.hass_host = None
        self.hass_token = None
        
        # read config.ini (HASS host + token)

        try:
            self.config = SnipsConfigParser.read_configuration_file("config.ini")
        except Exception as e:
          print("Failed to read config.ini ({})".format(e))
          self.config = None

        try:
          self.read_toml()
        except Exception as e:
          print("Failed to read /etc/snips.toml ({})".format(e))

        if 'hass_token' in self.config['secret']:
          self.hass_token = self.config['secret']['hass_token']
        elif 'HASSIO_TOKEN' in eviron:
          self.hass_token = environ['HASSIO_TOKEN']
        if 'hass_host' in self.config['global']:
          self.hass_host = self.config['global']['hass_host']
        elif self.hass_token is not None and 'HASSIO_TOKEN' in eviron:
            self.hass_host = 'http://hassio/homeassistant/api'
        self.hass_headers = { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.hass_token }

        if 'confirmation_success' in self.config['global']:
          self.confirmation_success = self.config['global']['confirmation_success']
        else:
          self.confirmation_success = "Bestätige"

        if 'confirmation_failure' in self.config['global']:
          self.confirmation_failure = self.config['global']['confirmation_failure']
        else:
          self.confirmation_failure = "Ausführung nicht möglich"

        if 'enable_confirmation' in self.config['global'] and self.config['global']['enable_confirmation'] == "True":
          self.enable_confirmation = True

        if self.debug:
          print("Connecting to {}@{} ...".format(self.mqtt_user, self.mqtt_host))

        self.start()
Esempio n. 11
0
    def __init__(self):
        # get the configuration if needed
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except:
            self.config = None

        self.base_api_url = "http://{0}:{1}/api/v1/commands/?cmd=".format(self.config["global"]["host"],
                                                                          self.config["global"]["port"])

        # start listening to MQTT
        self.start_blocking()
    def __init__(self):
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
            self.apiHandler = Api(
                self.config.get("secret").get("username"),
                self.config.get("secret").get("password"),
                self.config.get("global").get("backend_api"))
        except Exception:
            self.config = None

        self.numberOfBoardgames = 3
        self.start_blocking()
Esempio n. 13
0
    def __init__(self, debug = False):

        self.logger = logging.getLogger(APP_ID)
        self.debug = debug

        # parameters

        self.mqtt_host = "localhost:1883"
        self.mqtt_user = None
        self.mqtt_pass = None

        self.rmv_api_key = None
        self.rmv_homestation = None
        self.rmv_homecity = None
        self.rmv_homecity_only = True
        self.time_offset = None
        self.short_info = False
        
        # read config.ini (HASS host + token)

        try:
            self.config = SnipsConfigParser.read_configuration_file("config.ini")
        except Exception as e:
            self.logger.error("Failed to read config.ini ({})".format(e))
            self.config = None

        try:
            self.read_toml()
        except Exception as e:
            self.logger.error("Failed to read /etc/snips.toml ({})".format(e))

        if 'rmv_api_key' in self.config['secret']:
            self.rmv_api_key = self.config['secret']['rmv_api_key']

        if 'rmv_homestation' in self.config['global']:
            self.rmv_homestation = self.config['global']['rmv_homestation']

        if 'rmv_homecity' in self.config['global']:
            self.rmv_homecity = self.config['global']['rmv_homecity']
        
        if 'rmv_homecity_only' in self.config['global'] and self.config['global']['rmv_homecity_only'] == "False":
            self.rmv_homecity_only = False

        if 'time_offset' in self.config['global']:
            self.time_offset = int(self.config['global']['time_offset'])

        if 'short_info' in self.config['global'] and self.config['global']['short_info'] == "True":
            self.short_info = True

        self.logger.debug("Connecting to {}@{} ...".format(self.mqtt_user, self.mqtt_host))

        self.start()
Esempio n. 14
0
    def __init__(self):
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except:
            self.config = None

        if self.config.get("global").get("feed_url") is None:
            print(
                "No feed URL key in config.ini, you must setup an RSS feed URL for this skill to work"
            )
            sys.exit(1)

        self.start_blocking()
Esempio n. 15
0
    def __init__(self):
        # get the configuration if needed
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except :
            self.config = None

		logger.setLevel(logging.WARN)
		# create console handler and set level to warn
		ch = logging.StreamHandler()
		ch.setLevel(logging.WARN)
		# add ch to logger
		logger.addHandler(ch)
Esempio n. 16
0
    def __init__(self):
        # get the configuration if needed
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except:
            self.config = None

        GPIO.setmode(GPIO.BCM)
        GPIO.setup(18, GPIO.OUT, initial=GPIO.LOW)
        pin18state = False
        pin23state = False

        # start listening to MQTT
        self.start_blocking()
    def __init__(self):

        self.logger = logging.getLogger(APP_ID)
        self.geolocator = Nominatim(user_agent = APP_ID)

        # parameters

        self.mqtt_host = "localhost:1883"
        self.mqtt_user = None
        self.mqtt_pass = None

        self.api_key = None
        self.home_location = None
        self.weekdays = ['montag', 'dienstag', 'mittwoch', 'donnerstag', 'freitag', 'samstag', 'sonntag']
        self.day_range_symbols = ['früh', 'vormittag', 'mittag', 'nachmittag', 'abend', 'nacht']

        self.known_intents = ['s710:getForecast','s710:getTemperature','s710:hasRain','s710:hasSun','s710:hasSnow']

        homecity = None
        
        # read config.ini (HASS host + token)

        try:
            self.config = SnipsConfigParser.read_configuration_file("config.ini")
        except Exception as e:
            self.logger.error("Failed to read config.ini ({})".format(e))
            self.config = None

        try:
            self.read_toml()
        except Exception as e:
            self.logger.error("Failed to read /etc/snips.toml ({})".format(e))

        if 'api_key' in self.config['secret']:
            self.api_key = self.config['secret']['api_key']

        if 'homecity' in self.config['global']:
            homecity = self.config['global']['homecity']

        self.http_headers = { 'Accept-Encoding': 'deflate, gzip' }

        self.logger.debug("Debug: Connecting to {}@{} ...".format(self.mqtt_user, self.mqtt_host))

        try:
            loc = self.geolocator.geocode(homecity)
            self.home_location = (loc.latitude, loc.longitude)
        except Exception as e:
            self.logger.error("Error: Failed to determine homecity coordinates for '{}' ({})".format(homecity, e))

        self.start()
    def __init__(self):
        # get the configuration if needed
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except:
            self.config = None

        self.defaultRoom = None
        self.defaultAppliance = None

        self.defaultRoom = self.config["global"]["default_room"]
        self.defaultAppliance = self.config["global"]["default_appliance"]

        # start listening to MQTT
        self.start_blocking()
Esempio n. 19
0
    def __init__(self):
        # get the configuration if needed
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except :
            self.config = None

        # Get parameters
        self.ip =  self.config.get("secret").get("ip")

        # init Vacuum
        self.vacuum = Valetudo(ip=self.ip)

        # start listening to MQTT
        self.start_blocking()
    def __init__(self):
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except Exception as e:
            print("[Error] Failed to parse config {}".format(e))
            self.config = {MQTT: {}, HASS: {}, INTENTS: {}}

        for c in (API_URL, AUTH_TOKEN):
            if c not in self.config[HASS]:
                print("[Error] Required hass config not present: {}".format(c))

        if not self.config[INTENTS]:
            print("[Error] No intents configured")

        self.start_blocking()
Esempio n. 21
0
    def __init__(self):
        # get the configuration if needed
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
            self.mqtt_address = self.config.get("secret").get("mqtt")
        except:
            self.config = None
            self.mqtt_address = MQTT_ADDR

        self.relay = grove.grove_relay.Grove(12)
        self.temperature_humidity_sensor = grove.grove_temperature_humidity_sensor_sht3x.Grove(
        )

        # start listening to MQTT
        self.start_blocking()
    def __init__(self):
        # get the configuration if needed

        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except:
            self.config = None

        self.hdnumber = self.config.get("secret").get("hdnumber")
        self.freeremotecode = self.config.get("secret").get("freeremotecode")
        self.defaultchannel = self.config.get("secret").get("defaultchannel")
        self.remoteaddr = 'http://hd' + self.hdnumber + '.freebox.fr/pub/remote_control?code=' + self.freeremotecode

        # start listening to MQTT
        self.start_blocking()
Esempio n. 23
0
 def __init__(self):
     print("Loading HomeManager")
     try:
         self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
     except:
         self.config = None
         print("[Warning] No config file")
     self.autho = self.config['secret']['http_api_token']
     self.header = {
         'Authorization': self.autho,
         "Content-Type": "application/json",
     }
     self.context = None
     self.last_question = None
     self.steward = SnipsHomeManager(self.autho, self.header)
     # start listening to MQTT
     self.start_blocking()
Esempio n. 24
0
    def __init__(self):
        # get the configuration if needed
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except:
            self.config = None

        api_key = self.config.get("secret").get("nre_api_key")
        self.home_station_code = self.config.get("secret").get(
            "home_station_code")
        self.destination_code = self.config.get("secret").get(
            "destination_code")
        self.darwin_session = DarwinLdbSession(
            wsdl="https://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx",
            api_key=api_key)

        # start listening to MQTT
        self.start_blocking()
Esempio n. 25
0
    def __init__(self):
        # get the configuration if needed
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except :
            self.config = None

        self.apiKey = self.config["secret"]["api_key"]

        self.bot = cleverbot.Cleverbot(self.apiKey, timeout=60)

        # start listening to MQTT
        self.tmpClient = paho.Client("snips-skill-cleverbot-" + str(int(round(time.time() * 1000))))
        self.tmpClient.on_message = self.on_message
        self.tmpClient.on_log = self.on_log
        self.tmpClient.connect(MQTT_IP_ADDR, MQTT_PORT)
        self.tmpClient.subscribe("hermes/intent/#")
        self.tmpClient.subscribe("hermes/nlu/intentNotRecognized")
        self.tmpClient.loop_forever()
Esempio n. 26
0
    def __init__(self):
        # get the configuration if needed
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except :
            self.config = None

        ## Prepare Kodi
        host = self.config.get("secret").get("kodihost")
        port = int(self.config.get("secret").get("kodiport"))
        self.kodi = Kodi(host, port)

        ## Language
        self.lang = self.config.get("secret").get("lang")
        self.vocal = {}
        for v in VOCABULARY:
            self.vocal[v] = VOCABULARY[v][self.lang]

        # start listening to MQTT
        self.start_blocking()
Esempio n. 27
0
    def __init__(self):
        # Get config
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except :
            print 'Error : can\'t load config'
            self.config = None

        # Get translations json
        try:
            self.t = json.loads(json.dumps(translations))
        except :
            print 'Error : can\'t load translations'
            self.t = None

        # start listening to MQTT
        if self.config != None and self.t != None:
            self.start_blocking()
        else:
            print 'Error : can\'t start blocking'
Esempio n. 28
0
    def __init__(self):
        # get the configuration if needed
        try:
            config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except:
            config = None
        ip = None
        port = None

        if config and config.get('secret', None) is not None:
            if config.get('secret').get('ip', None) is not None:
                ip = config.get('secret').get('ip')
                if ip == "":
                    ip = None
            if config.get('secret').get('port', None) is not None:
                port = config.get('secret').get('port')
                if port == "":
                    port = None
        IP = ip
        PORT = port
        print("HS100 : %s:%s" % (IP, PORT))
        # start listening to MQTT
        self.start_blocking()
Esempio n. 29
0
    def __init__(self):
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except:
            print 'No "config.ini" found!'
            sys.exit(1)

        self.relay_pin = int(
            self.config.get('global', {
                "gpio_bcm_relay": "12"
            }).get('gpio_bcm_relay', '12'))

        if self.config.get('global', {
                "activate_level": "high"
        }).get('activate_level', 'high') == 'high':
            self.relay_on = GPIO.HIGH
            self.relay_off = GPIO.LOW
        elif self.config.get('global', {
                "activate_level": "high"
        }).get('activate_level', 'high') == 'low':
            self.relay_on = GPIO.HIGH
            self.relay_off = GPIO.LOW

        self.mqtt_host = self.config.get('secret', {
            "mqtt_host": "localhost"
        }).get('mqtt_host', 'localhost')
        self.mqtt_port = self.config.get('secret', {
            "mqtt_port": "1883"
        }).get('mqtt_port', '1883')
        self.mqtt_addr = "{}:{}".format(self.mqtt_host, self.mqtt_port)

        self.site_id = self.config.get('secret', {
            "site_id": "default"
        }).get('site_id', 'default')

        self.gpioInit()
        self.start_blocking()
    def __init__(self):
        # get the configuration
        try:
            self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except:
            print 'Unable to load config'
            return

        # log in to the Bring API
        response = requests.get(
            'https://api.getbring.com/rest/bringlists?email=' +
            self.config.get('secret').get('email') + '&password='******'secret').get('password'))
        if response.status_code == 200:
            self.UUID = response.json()['uuid'].encode('utf-8')
            self.publicUUID = response.json()['publicUuid'].encode('utf-8')
            self.bringListUUID = response.json()['bringListUUID'].encode(
                'utf-8')
            print 'Login successfull'
        else:
            print 'Login failed'
            return

        self.headers = {
            'X-BRING-API-KEY': 'cof4Nc6D8saplXjE3h3HXqHH8m7VU2i1Gs0g85Sp',
            'X-BRING-CLIENT': 'android',
            'X-BRING-USER-UUID': self.UUID,
            'X-BRING-COUNTRY': 'FR'
        }

        # load the available shopping lists
        self.shoppingLists = {}
        response = requests.get('https://api.getbring.com/rest/bringusers/' +
                                self.UUID + '/lists',
                                headers=self.headers)
        if response.status_code == 200:
            for lists in response.json()['lists']:
                self.shoppingLists[lists['name'].encode(
                    'utf-8')] = lists['listUuid'].encode('utf-8')
        else:
            print 'Unable to load shopping lists'
            return

        # Load the translations
        self.items_fr = {}
        response = requests.get(
            'https://web.getbring.com/locale/articles.fr-FR.json')
        if response.status_code == 200:
            self.items_de = response.json()
            for i in self.items_de.keys():
                self.items_fr[self.items_de[i]] = i
        else:
            print 'Unable to load the translations'
            return

        # Load the available shopping lists and items to Snips to be sure they are up-to-date
        injecting_json = '{ "operations": [ [ "addFromVanilla", { "ShoppingListList" : ['
        first = 1
        for list in self.shoppingLists.keys():
            if first:
                first = 0
            else:
                injecting_json += ', '
            injecting_json += '"' + list + '"'
        injecting_json += '], "ShoppingListItem" : ['
        first = 1
        for item in self.items_fr.keys():
            if first:
                first = 0
            else:
                injecting_json += ', '
            injecting_json += '"' + item.encode('utf-8') + '"'
        response = requests.get('https://api.getbring.com/rest/bringlists/' +
                                self.bringListUUID + '/details',
                                headers=self.headers)
        if response.status_code == 200:
            for i in response.json():
                if i['itemId'] not in self.items_de.keys():
                    injecting_json += ', "' + i['itemId'].encode('utf-8') + '"'
        injecting_json += '] } ] ] }'
        injecting_mqtt = mqtt.Client()
        injecting_mqtt.connect(
            self.config.get('global').get('mqtt-host'),
            int(self.config.get('global').get('mqtt-port')))
        injecting_mqtt.loop_start()
        rc = injecting_mqtt.publish('hermes/injection/perform', injecting_json)
        rc.wait_for_publish()
        if rc.is_published:
            print 'Injected the lists to Snips ASR and NLU'
        else:
            print 'Could not inject the lists to Snips ASR and NLU'
        injecting_mqtt.disconnect()

        # start listening to MQTT
        self.start_blocking()