Hello,
I have a class CLightBulb and it is defined as a accessory delegate:
In the “init?()” I set self as the delegate:
And I override the “didUpdateValueFor” method as follows, but it is never invoked when I turn a lightbulb on or off from the Homekit app on another device (other than the one I am testing on)
// AccessoryDelegate: Update Characteristic Value
//
//
//_____
func accessory(_ accessory: HMAccessory, service: HMService, didUpdateValueFor characteristic: HMCharacteristic)
{
var results: CResults
print("******------> CLightBulb AccessoryDelegate: Update Characteristic View")
results = CResults()
if ((accessory == m_lightBulb) && (service == m_lightBulbService))
{
switch characteristic.characteristicType
{
case HMCharacteristicTypePowerState:
results = GetThePowerStateFromTheLightBulb(workComplete:
{ () in
let delegate = self.m_delegate
if (results.GetResultCode() != CResults.code.success)
{
// NOTE: The attribute value is incorrect for Philips HUE bulbs so we have to check the error description
// to see if the reason for the error is that its unreachable. It's not really an error if its unreachable
if (self.m_isReachable == false)
{
delegate?.lightBulbReachablilityChanged!(device: self, newState: self.m_isReachable)
}
else
{
delegate?.lightBulbEncounteredError(device: self, opResults: results)
}
}
else
{
delegate?.lightBulbPowerStateChanged!(device: self, newState: self.m_powerState)
}
})
default:
print("CLightBulb: Encountered unexpected service type in accessory characteristic update.")
}
}
}
But when I test my app on my phone, it doesn’t get called when I, say, turn the light bulb off from the Homekit app on my iPad. Do you know what I’m missing?