Hi Jeff,
have a look on following snippet. Thanks to Lucas’ examples it’s really easy:
std::string GarageDoorAccessoryBase::getDoorStatus (HKConnection *sender)
{
/*0 = fully open;
1 = "Closed. The door is fully closed."
2 = Opening
3 = closing */
if (lr->isOn())
return format("%d", 1);
else
return format("%d", 0);
}
std::string GarageDoorAccessoryBase::getTargetDoorStatus (HKConnection *sender)
{
if (lr->isOn())
return format("%d", 1);
else
return format("%d", 0);
}
void GarageDoorAccessoryBase::setTargetDoor (bool oldValue, bool newValue, HKConnection *sender)
{
if(newValue)
lr->switchOn();
else lr->switchOff();
}
void GarageDoorAccessoryBase::sync()
{
if (currentState != NULL)
currentState->notify(NULL);
if (targetDoorState != NULL)
targetDoorState->notify(NULL);
}
void GarageDoorAccessoryBase::gdIdentify(bool oldValue, bool newValue, HKConnection *sender) {
hkLog.info("Start Identify Garage Door Opener\n");
}
void GarageDoorAccessoryBase::initAccessorySet() {
Accessory *gdAcc1 = new Accessory();
AccessorySet *accSet = &AccessorySet::getInstance();
addInfoServiceToAccessory(gdAcc1, " Garage Door Opener", "Vendor name", "Model name", "1","1.0.0", std::bind(&GarageDoorAccessoryBase::gdIdentify, this, std::placeholders::_1, std::placeholders::_2,std::placeholders::_3));
accSet->addAccessory(gdAcc1);
Service *gdService1 = new Service(serviceType_garageDoorOpener);
gdAcc1->addService(gdService1);
stringCharacteristics *gdServiceName1 = new stringCharacteristics(charType_serviceName, permission_read, 0);
gdServiceName1->characteristics::setValue("Garage");
gdAcc1->addCharacteristics(gdService1, gdServiceName1);
currentState = new intCharacteristics(charType_currentDoorState, permission_read|permission_notify,0, 4, 1, unit_none);
currentState->perUserQuery = std::bind(&GarageDoorAccessoryBase::getDoorStatus, this, std::placeholders::_1);
gdAcc1->addCharacteristics(gdService1, currentState);
targetDoorState = new intCharacteristics(charType_targetDoorState, permission_read|permission_write|permission_notify,0,1,1,unit_none);
targetDoorState->perUserQuery = std::bind(&GarageDoorAccessoryBase::getTargetDoorStatus, this, std::placeholders::_1);
targetDoorState->valueChangeFunctionCall = std::bind(&GarageDoorAccessoryBase::setTargetDoor, this, std::placeholders::_1, std::placeholders::_2,std::placeholders::_3);
gdAcc1->addCharacteristics(gdService1, targetDoorState);
boolCharacteristics *obstruction = new boolCharacteristics(charType_obstruction, permission_read|permission_notify);
obstruction->characteristics::setValue("false");
gdAcc1->addCharacteristics(gdService1, obstruction);
};
works pretty fine in my case.
Best, Michael