Esempio n. 1
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. 2
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. 3
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()
    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_commands = True
        self.arriving = True
        self.last_question = None
        self.light_on = False
        self.light_color = None
        self.light_brightness = None
        self.tv_on = False
        self.steward = SnipsHomeManager(self.autho, self.header)

        # start listening to MQTT
        self.start_blocking()
Esempio n. 5
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()
Esempio n. 7
0
    def __init__(self, debug=False):

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

        # parameters

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

        self.hass_host = None
        self.hass_token = None

        # read config.ini

        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))

        # try to use HASSIO token via environment variable & internal API URL in case no config.ini parameters are given

        if 'hass_token' in self.config['secret']:
            self.hass_token = self.config['secret']['hass_token']
        elif 'HASSIO_TOKEN' in environ:
            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 environ:
            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 = "Okay"

        if 'confirmation_failure' in self.config['global']:
            self.confirmation_failure = self.config['global'][
                'confirmation_failure']
        else:
            self.confirmation_failure = "Fehler"

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

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

        self.start()
Esempio n. 8
0
def subscribir_Comprobar_usuario_llamada(hermes, MensajeIntent):
    conf = SnipsConfigParser.read_configuration_file(Configuracion_inicial)
    controlador_accion_comprobar_usuario(hermes, MensajeIntent, conf)
Esempio n. 9
0
def subscribir_Negar_llamada(hermes, MensajeIntent):
    conf = SnipsConfigParser.read_configuration_file(Configuracion_inicial)
    controlador_accion_Negar(hermes, MensajeIntent, conf)
        """
            Register callback function and start MQTT bus.
        """
        logger.info("...myShoppingList...")
        logger.info("Connection au MQTT broker" + MQTT_ADDR)

        with Hermes(MQTT_ADDR) as h:
            h.subscribe_intents(self.master_intent_callback).start()


# main function


if __name__ == "__main__":
    try:
        config = SnipsConfigParser.read_configuration_file(CONFIG_INI)

    except:
        print("config --> vide")
        config = None

    MQTT_IP_ADDR = config["global"].get("mqtt_host")
    MQTT_PORT = config["global"].get("mqtt_port")
    MQTT_ADDR = "{}:{}".format(MQTT_IP_ADDR, str(MQTT_PORT))

    MEDIA = config["media"].get("default_media")
    USERNAME = config["mail"].get("default_user")
    MAIL_TO = config["mail"].get("mail_default_user")
    SMTP_ADDR = config["mail"].get("smtp_server")
    SMTP_PORT = config["mail"].get("smtp_port")
    LOGIN = config["mail"].get("smtp_login")
Esempio n. 11
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.hass_host = None
        self.hass_token = None

        self.known_intents = [
            's710:isHeatingOn', 's710:enableHeating', 's710:disableHeating',
            's710:setTemperature'
        ]

        # read config.ini

        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))

        # try to use HASSIO token via environment variable & internal API URL in case no config.ini parameters are given

        if 'hass_token' in self.config['secret']:
            self.hass_token = self.config['secret']['hass_token']
        elif 'HASSIO_TOKEN' in environ:
            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 environ:
            self.hass_host = 'http://hassio/homeassistant/api'

        self.hass_headers = {
            'Content-Type': 'application/json',
            'Authorization': "Bearer " + self.hass_token
        }

        if 'entity_dict' in self.config['global']:
            try:
                self.entity_dict = json.loads(
                    self.config['global']['entity_dict'])
            except Exception as e:
                self.logger.error(
                    'Failed to parse entity-dictionary ({})'.format(e))
                self.entity_dict = {}
        else:
            self.entity_dict = {}

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

        self.start()