def update_config(self, filename, data, hostname, code):
     if not os.path.exists(CACHE_INI_DIR):
         os.makedirs(CACHE_INI_DIR)
     if 'secret' not in data or data['secret'] is None:
         data['secret'] = {}
     data['secret']['hostname'] = hostname
     data['secret'][API_KEY] = code
     SnipsConfigParser.write_configuration_file(filename, data)
    def __init__(self):
        config_dict = SnipsConfigParser.read_configuration_file()
        bridge_ip = config_dict.get(BRIDGE_IP_KEY, None)
        api_key = config_dict.get(API_KEY_KEY, None)
        (bridge_ip, api_key, config_changed) = HueSetup.validate_config(bridge_ip, api_key)
        if config_changed:
            SnipsConfigParser.write_configuration_file(bridge_ip, api_key)
        self.snipshue = SnipsHue(bridge_ip, api_key)

        with Hermes(MQTT_ADDR) as h:
            h.subscribe_intents(self.callback).start()
 def __init__(self):
     try:
         config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
     except:
         config = None
     hostname = None
     code = None
     if config and config.get('secret') is not None:
         if config.get('secret').get('hostname') is not None:
             hostname = config.get('secret').get('hostname')
             if hostname == "":
                 hostname = None
         if config.get('secret').get(API_KEY) is not None:
             code = config.get('secret').get(API_KEY)
             if code == "":
                 code = None
     if hostname is None or code is None:
         print('No configuration')
     self.snipshue = SnipsHue(hostname, code)
     hostname = self.snipshue.hostname
     code = self.snipshue.username
     self.update_config(CONFIG_INI, config, hostname, code)
     self.queue = Queue.Queue()
     self.thread_handler = ThreadHandler()
     self.thread_handler.run(target=self.start_blocking)
     self.thread_handler.start_run_loop()
    def __init__(self, cli, dataDir):
        self.logger = logging.getLogger(APP_LOGGER)
        self.config = SnipsConfigParser.read_configuration_file(SNIPS_CONF)
        self.mqttClient = cli
        self.dataDir = dataDir

        self.provider = GoogleCalendarProvider(self.config['secret'],
                                               self.dataDir)
    def __init__(self):
        print("[HARMONY] Starting INIT")

        try:
            config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except:
            config = None
            print("[HARMONY] Config error")

        # Config variables to fill
        harmony_ip = None
        watch_film_activity_id = None

        # Getting conf
        if config and config.get('secret', None) is not None:
            # Get Harmony IP from Config
            if config.get('secret').get(HARMONY_IP_CONFIG_KEY,
                                        None) is not None:
                harmony_ip = config.get('secret').get(HARMONY_IP_CONFIG_KEY)
                if harmony_ip == "":
                    harmony_ip = None

            # Get Activities ID from Config
            if config.get('secret').get(WATCH_FILM_ACTIVITY_CONFIG_KEY,
                                        None) is not None:
                watch_film_activity_id = config.get('secret').get(
                    WATCH_FILM_ACTIVITY_CONFIG_KEY)
                if watch_film_activity_id == "":
                    self.WATCH_FILM_ACTIVITY_ID = None
                else:
                    self.WATCH_FILM_ACTIVITY_ID = watch_film_activity_id

        if harmony_ip is None or watch_film_activity_id is None:
            print('No configuration')

        print("[HARMONY] Creating Harmony Controller")
        self.harmony_controller = HarmonyController(harmony_ip=harmony_ip)
        print("[HARMONY] Harmony Controller Ready")

        self.queue = queue.Queue()
        self.thread_handler = ThreadHandler()
        self.thread_handler.run(target=self.start_blocking)
        self.thread_handler.start_run_loop()

        print("[HARMONY] Ending INIT")
예제 #6
0
 def __init__(self):
     config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
     ip = config.get("secret").get("ip", None)
     if not ip:
         print("Could not load [secret][ip] from %s" % CONFIG_INI)
         sys.exit(1)
     mac = config.get("secret").get("mac", None)
     if not mac:
         print("Could not load [secret][mac] from %s" % CONFIG_INI)
         sys.exit(1)
     onkyoip = config.get("secret").get("onkyoip", None)
     if not onkyoip:
         print("Could not load [secret][onkyoip] from %s" % CONFIG_INI)
         sys.exit(1)
     self.snipslgtv = SnipsLGTV(ip, mac, onkyoip)
     self.queue = queue.Queue()
     self.thread_handler = ThreadHandler()
     self.thread_handler.run(target=self.start_blocking)
     self.thread_handler.start_run_loop()
class SkillHarmonyControl:
    snipsConfigParser = SnipsConfigParser()

    def __init__(self):
        print("[HARMONY] Starting INIT")

        try:
            config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
        except:
            config = None
            print("[HARMONY] Config error")

        # Config variables to fill
        harmony_ip = None
        watch_film_activity_id = None

        # Getting conf
        if config and config.get('secret', None) is not None:
            # Get Harmony IP from Config
            if config.get('secret').get(HARMONY_IP_CONFIG_KEY,
                                        None) is not None:
                harmony_ip = config.get('secret').get(HARMONY_IP_CONFIG_KEY)
                if harmony_ip == "":
                    harmony_ip = None

            # Get Activities ID from Config
            if config.get('secret').get(WATCH_FILM_ACTIVITY_CONFIG_KEY,
                                        None) is not None:
                watch_film_activity_id = config.get('secret').get(
                    WATCH_FILM_ACTIVITY_CONFIG_KEY)
                if watch_film_activity_id == "":
                    self.WATCH_FILM_ACTIVITY_ID = None
                else:
                    self.WATCH_FILM_ACTIVITY_ID = watch_film_activity_id

        if harmony_ip is None or watch_film_activity_id is None:
            print('No configuration')

        print("[HARMONY] Creating Harmony Controller")
        self.harmony_controller = HarmonyController(harmony_ip=harmony_ip)
        print("[HARMONY] Harmony Controller Ready")

        self.queue = queue.Queue()
        self.thread_handler = ThreadHandler()
        self.thread_handler.run(target=self.start_blocking)
        self.thread_handler.start_run_loop()

        print("[HARMONY] Ending INIT")

    def action_wrapper(self, hermes, intent_message):
        print("[HARMONY] Received")

        # all the intents have a house_room slot, extract here
        intent_name = intent_message.intent.intent_name
        if ':' in intent_name:
            intent_name = intent_name.split(":")[1]
        if intent_name == 'watchFilm':
            self.queue.put(self.start_watch_film(hermes, intent_message))

        if intent_name == 'powerOff':
            self.queue.put(self.power_off(hermes, intent_message))

    def start_watch_film(self, hermes, intent_message):
        self.start_activity(hermes, intent_message,
                            self.WATCH_FILM_ACTIVITY_ID)

    def start_activity(self, hermes, intent_message, activity_id):
        self.harmony_controller.start_activity(activity_id)
        self.terminate_feedback(hermes, intent_message)

    def power_off(self, hermes, intent_message):
        self.harmony_controller.power_off()
        self.terminate_feedback(hermes, intent_message)

    def terminate_feedback(self, hermes, intent_message, mode='default'):
        if mode == 'default':
            hermes.publish_end_session(intent_message.session_id, "")
        else:
            # more design
            hermes.publish_end_session(intent_message.session_id, "")

    def subscribe_intent_callback(self, hermes, intent_message):
        self.action_wrapper(hermes, intent_message)

    def start_blocking(self, run_event):
        while run_event.is_set():
            try:
                self.queue.get(False)
            except queue.Empty:
                with Hermes(MQTT_ADDR) as h:
                    h.subscribe_intents(self.subscribe_intent_callback).start()
예제 #8
0
    port = config.get('global', {"port": "8080"}).get('port', '8080')

    thermostat = SVT(ip, port)
    return thermostat


def intent_received(hermes, intent_message):
    intentName = intent_message.intent.intent_name
    sentence = 'Voila c\'est fait.'
    print(intentName, sentence)


with Hermes(MQTT_ADDR) as h:

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

    thermostat = open_thermostat(config)
    print('Thermostat initialization: OK')

    try:
        print("thermostat mode is {}".format(thermostat.mode))
        print("thermostat state is {}".format(thermostat.state))
        print("thermostat pause is {}".format(thermostat.pause))
        # thermostat.mode=10
        # print("thermostat mode is {}".format(thermostat.mode))
        # print("thermostat state is {}".format(thermostat.state))
        # thermostat.state='auto'
        # thermostat.pause=True
예제 #9
0
                else:
                    sentence = "Je n'ai pas compris s'il fait froid ou s'il fait chaud."

            else:
                sentence = "Je ne comprends pas l'action à effectuer avec le thermostat."

            logger.debug(sentence)
            hermes.publish_end_session(intent_message.session_id, sentence)
            return


with Hermes(MQTT_ADDR) as h:

    try:
        config = SnipsConfigParser.read_configuration_file(configPath)

    except BaseException:
        config = None

    thermostat = None

    try:
        thermostat = open_thermostat(config)
        logger.info('Thermostat initialization: OK')

    except Exception as e:
        logger.error('Error Thermostat {}'.format(e))

    h.subscribe_intent(THERMOSTATMODE, intent_received)\
        .subscribe_intent(THERMOSTATTURNOFF, intent_received)\
예제 #10
0
    def run(self):
        try:
            config = SnipsConfigParser.read_configuration_file(configPath)
            # print configPath, config
        except:
            config = None
            print "Read config.ini error"
            return

        start = time.time()
        zibaseId = config.get('secret').get('zibaseid')
        tokenId = config.get('secret').get('tokenid')
        url = 'http://zibase2.net/api/get/ZAPI.php?zibase={}&token={}&service=get&target=home'.format(
            zibaseId, tokenId)

        try:
            resp = requests.get(url)
        except:
            print "resp exception when getting {}".format(url)
            logging.warning('RESP EXCEPTION WHEN GETTING  %s' %
                            (threading.current_thread()))
            resp = None
            return

        elapsed = (time.time() - start) * 1000
        logging.debug(' RETRIEVE DATA FROM ZIBASE.NET  [%d ms]' % (elapsed))
        data = json.loads(resp.text)
        probes = data['body']['probes']
        textAnchorY = -25
        textYoffset = 32
        scope.clear(BLACK)

        for i, v in enumerate(probes):
            #print i,v
            name = v['name'].encode('raw_unicode_escape').decode('utf-8')
            name = name.upper()
            id = v['id']
            if v['type'] == 'temperature' and id != 'TT13' and id != 'OS439156754' and name != 'FGMS001':
                #print v
                timestr = ''
                temp = ''
                hum = ''
                if 'val1' in v:
                    temp = "{:.1f}".format(v['val1'])
                    temp = temp + u'\N{DEGREE SIGN}' + 'C'
                if 'val2' in v and v['val2'] > 0:
                    hum = str(v['val2']) + '%'
                if 'time' in v:
                    timestr = str(datetime.fromtimestamp(v['time']))
                    textAnchorY += textYoffset
                    #print timestr, id, temp, hum, name, textAnchorX, textAnchorY
                    logging.debug(' %s %s %s %s %s ' %
                                  (timestr, id, temp, hum, name))
                    text = zfontSm.render(name + ' ', True, BLACK, LIGHTBLUE)
                    size = zfontSm.size(name)
                    textrect = text.get_rect()
                    textrect.topright = (170, textAnchorY + 8)
                    lcd.blit(logoLightBlue,
                             (170 - size[0] - 20, textAnchorY + 8))
                    lcd.blit(text, textrect)
                    # textAnchorY+=textYoffset
                    text = zfontTemp.render(temp, True, WHITE)
                    textrect = text.get_rect()
                    textrect.topright = (300, textAnchorY)
                    lcd.blit(text, textrect)

                pygame.display.update()