def setup(hass, config): """Set up the Camect component.""" import camect # Create camect.Home instances. homes = [] data = [] for conf in config[DOMAIN]: host = conf.get(CONF_HOST) port = conf.get(CONF_PORT) home = camect.Home('{}:{}'.format(host, port), conf.get(CONF_USERNAME), conf.get(CONF_PASSWORD)) home.add_event_listener(lambda evt: hass.bus.fire('camect_event', evt)) homes.append(home) data.append((conf.get(CONF_CAMERA_IDS), conf.get(CONF_ID))) hass.data[DOMAIN] = homes discovery.load_platform(hass, camera.DOMAIN, DOMAIN, data, config) # Register service. def handle_change_op_mode_service(call): mode = call.data.get(ATTR_MODE).upper() if mode in ('HOME', 'DEFAULT'): home.set_mode(mode) elif mode == 'AWAY': home.set_mode('DEFAULT') hass.services.register(DOMAIN, SERVICE_CHANGE_OP_MODE, handle_change_op_mode_service, schema=CHANGE_OP_MODE_SCHEMA) return True
def connect_host(self,host): LOGGER.info(f'Connecting to {host}...') try: camect_obj = camect.Home(f"{host}:443", self.user, self.password) except: LOGGER.error(f'Failed to connect to camect host {host}',exc_info=True) return False self.hosts_connected += 1 self.set_hosts_connected() LOGGER.info(f'Camect Name={camect_obj.get_name()}') LOGGER.debug(f'Camect Info={camect_obj.get_info()}') return camect_obj
def sendEvent(string): headers = {'content-type': 'application/json'} try: r = requests.post(hubitatOAUTHURL, data=json.dumps(string), headers=headers, timeout=5) if (r.status_code != 200): print("Error sending event to Hubitat: %s" % r.status_code) else: print("Successfully sent event to hubitat") except (requests.exceptions.HTTPError, AttributeError) as err: print("Error sending event to Hubitat: %s" % err) while (True): try: home = camect.Home(camectHost, camectUsername, camectPassword) print("Connected to %s" % home.get_name()) loop = home.add_event_listener(lambda evt: sendEvent(evt)) run = 0 while (1): time.sleep(5) except (KeyboardInterrupt): exit(0) except: e = sys.exc_info()[0] print("Unexpected exception: %s", e)