示例#1
0
 def accessory_setup(self):
     """Handle setup of a HomeKit accessory."""
     # pylint: disable=import-error
     import homekit
     self.controllerkey, self.accessorykey = \
         homekit.get_session_keys(self.conn, self.pairing_data)
     self.securecon = homekit.SecureHttp(self.conn.sock, self.accessorykey,
                                         self.controllerkey)
     response = self.securecon.get('/accessories')
     data = json.loads(response.read().decode())
     for accessory in data['accessories']:
         serial = get_serial(accessory)
         if serial in self.hass.data[KNOWN_ACCESSORIES]:
             continue
         self.hass.data[KNOWN_ACCESSORIES][serial] = self
         aid = accessory['aid']
         for service in accessory['services']:
             service_info = {
                 'serial': serial,
                 'aid': aid,
                 'iid': service['iid']
             }
             devtype = homekit.ServicesTypes.get_short(service['type'])
             _LOGGER.debug("Found %s", devtype)
             component = HOMEKIT_ACCESSORY_DISPATCH.get(devtype, None)
             if component is not None:
                 discovery.load_platform(self.hass, component, DOMAIN,
                                         service_info, self.config)
示例#2
0
    def connect(self):
        """Open the connection to the HomeKit device."""
        # pylint: disable=import-error
        import homekit

        self.conn = http.client.HTTPConnection(self.host,
                                               port=self.port,
                                               timeout=REQUEST_TIMEOUT)
        if self.pairing_data is not None:
            controllerkey, accessorykey = \
                homekit.get_session_keys(self.conn, self.pairing_data)
            self.securecon = homekit.SecureHttp(self.conn.sock, accessorykey,
                                                controllerkey)