0

I'm currently working on a quite important study project. I'm working on the topic of home automation. Therefore I would like to implement the HomeKit framework to control action modules.

My App is already able to search for Homes, Rooms, Accessories, Services and Characteristics. But I don't know how to properly handle all of the different characteristic types. Is there a way to get the characteristic type as real string (for example: HMCharacteristicTypePowerState).

I really don't know how to present the user just those characteristics that matter.

I would appreciate if someone could drop me a hint ;)

Mark
  • 7,167
  • 4
  • 44
  • 68
A. Osterthun
  • 175
  • 1
  • 3
  • 18

3 Answers3

1

HMCharacteristic has a characteristicType property, which you can compare to the constants.

if characteristic.characteristicType == HMCharacteristicTypePowerState {
    // do something
}

Reference

Mark
  • 7,167
  • 4
  • 44
  • 68
  • Yeah I worked it out that way to. But for some reason there are still Characteristics that aren't defined by apple, that I can't access that way. For example the current power draw of an power outlet. – A. Osterthun Mar 07 '16 at 14:59
  • So you're saying the characteristic has a type not defined by any of those constants? Is it an unofficial HomeKit accessory? What is the value of `characteristicType` for those characteristics? – Mark Mar 10 '16 at 17:40
  • Just in case anyone is doing this with ObjectiveC, you'll need to use isEqualToString, not ==. – hanno Jan 10 '21 at 01:56
0

HMCharacteristic has a localizedDescription property which returns a readable string, but if you want to select only certain characteristics it is better to use the the HMCharacteristicsType constants as suggested by Mark

Christian R
  • 1,545
  • 3
  • 13
  • 17
-1
if characteristic.characteristicType isEqualToString: HMCharacteristicTypePowerState {
    // do something
}
SRI
  • 1,514
  • 21
  • 39