Exemple #1
0
    def start(self):
        super(PyHarmony, self).start()
        errors = 0
        self.current_activity_isy = False
        # Setup the Harmony client
        self.parent.logger.info(self.lpfx + " Initializing Client")
        self.token = ha_get_token(self.host, self.port)
        self.client = ha_get_client(self.token, self.host, self.port)
        self.parent.logger.info(self.lpfx + " Client: " + str(self.client))
        self.harmony_config = self.client.get_config()
        #
        # Build a FauxMo Herlper for this device?
        fcnt = 1
        if self.spoken_prefix is not None:
            myfauxmo = {"type": "FauxMo", "name": "FauxMo%s%d" % (self.name, fcnt), "use_spoken": False, "devices": []}
            for a in self.harmony_config["activity"]:
                if a["label"] != "PowerOff":
                    # Max of 5 devices per fauxmo seems to work best
                    if len(myfauxmo["devices"]) == 5:
                        self.parent.add_helper(myfauxmo)
                        myfauxmo["devices"] = []
                        fcnt += 1
                        myfauxmo["name"] = "FauxMo%s%d" % (self.name, fcnt)
                    # Print the Harmony Activities to the log
                    print("%s Activity: %s  Id: %s" % (self.lpfx, a["label"], a["id"]))
                    self.parent.logger.info(self.lpfx + "Activity: %s  Id: %s" % (a["label"], a["id"]))
                    # Truncate the activity id to 16 bit integer to use as the port so
                    # we always get the same port number.
                    myfauxmo["devices"].append(
                        {
                            "name": "%s %s" % (self.spoken_prefix, a["label"]),
                            "type": "PyHarmony",
                            "port": 0xFFFF & int(a["id"]),
                            "type_name": self.name,
                            "command": "activity",
                            "on_event": a["id"],
                            "off_event": -1,
                        }
                    )
            self.parent.add_helper(myfauxmo)

        # Intialize our isy variables
        if self.set_current_activity():
            # Subscribe to changes of the isy variable
            self.handler = self.current_activity_isy.val.subscribe("changed", partial(self.current_activity_changed))
            self.parent.sched.add_job(self.set_current_activity, "cron", second="15,45")
        else:
            errors += 1
        if errors > 0:
            raise ValueError("See Log")
Exemple #2
0
 def _get_client(self):
     self.l_info("get_client", "Initializing PyHarmony Client")
     try:
         self.token = ha_get_token(self.host, self.port)
     except:
         exc_type, exc_value, exc_traceback = sys.exc_info()
         err_str = ''.join(
             format_exception(exc_type, exc_value, exc_traceback))
         self.l_error("get_client", err_str)
         self._set_st(0)
         return False
     self.l_info("get_client", "PyHarmony token= " + str(self.token))
     try:
         self.client = ha_get_client(self.token, self.host, self.port)
     except:
         exc_type, exc_value, exc_traceback = sys.exc_info()
         err_str = ''.join(
             format_exception(exc_type, exc_value, exc_traceback))
         self.l_error("get_client", err_str)
         self._set_st(0)
         return False
     self._set_st(1)
     self.l_info("get_client", "PyHarmony client= " + str(self.client))
     return True
Exemple #3
0
def harmony_hub_client(host, port=5222):
    client = ha_get_client(host, port)
    return client
def harmony_hub_client(host, port=5222):
    token = ha_get_token(host, port)
    client = ha_get_client(token, host, port)
    return client
Exemple #5
0
    def start(self):
        super(PyHarmony, self).start()
        errors = 0
        self.current_activity_isy = False
        # Setup the Harmony client
        self.parent.logger.info(self.lpfx + " Initializing Client")
        self.token = ha_get_token(self.host, self.port)
        self.client = ha_get_client(self.token, self.host, self.port)
        self.parent.logger.info(self.lpfx + " Client: " + str(self.client))
        self.harmony_config = self.client.get_config()
        #
        # Build a FauxMo Herlper for this device?
        fcnt = 1
        if self.spoken_prefix is not None:
            myfauxmo = {
                'type': "FauxMo",
                'name': "FauxMo%s%d" % (self.name, fcnt),
                'use_spoken': False,
                'devices': []
            }
            for a in self.harmony_config['activity']:
                if a['label'] != 'PowerOff':
                    # Max of 5 devices per fauxmo seems to work best
                    if len(myfauxmo['devices']) == 5:
                        self.parent.add_helper(myfauxmo)
                        myfauxmo['devices'] = []
                        fcnt += 1
                        myfauxmo['name'] = "FauxMo%s%d" % (self.name, fcnt)
                    # Print the Harmony Activities to the log
                    print("%s Activity: %s  Id: %s" %
                          (self.lpfx, a['label'], a['id']))
                    self.parent.logger.info(self.lpfx +
                                            "Activity: %s  Id: %s" %
                                            (a['label'], a['id']))
                    # Truncate the activity id to 16 bit integer to use as the port so
                    # we always get the same port number.
                    myfauxmo['devices'].append({
                        'name':
                        "%s %s" % (self.spoken_prefix, a['label']),
                        'type':
                        'PyHarmony',
                        'port':
                        0xFFFF & int(a['id']),
                        'type_name':
                        self.name,
                        'command':
                        'activity',
                        'on_event':
                        a['id'],
                        'off_event':
                        -1,
                    })
            self.parent.add_helper(myfauxmo)

        # Intialize our isy variables
        if self.set_current_activity():
            # Subscribe to changes of the isy variable
            self.handler = self.current_activity_isy.val.subscribe(
                'changed', partial(self.current_activity_changed))
            self.parent.sched.add_job(self.set_current_activity,
                                      'cron',
                                      second='15,45')
        else:
            errors += 1
        if errors > 0:
            raise ValueError("See Log")