apple / HomeKitADK

Apache License 2.0
2.57k stars 233 forks source link

Accessories added through the bridge cannot display the correct name #100

Closed imlsq closed 3 years ago

imlsq commented 3 years ago

Accessories added through the bridge cannot display the correct name

Through the bridge to add accessories, reference link "How to implement a bridge"

This is my code

static HAPAccessory bridgeAccessory = { .aid = 1,
                                        .category = kHAPAccessoryCategory_Bridges,
                                        .name = "SNB Bridge",
                                        .manufacturer = "SNB",
                                        .model = "Bridge1,1",
                                        .serialNumber = "ABCDEFGH0001",
                                        .firmwareVersion = "1",
                                        .hardwareVersion = "1",
                                        .services = (const HAPService* const[]) { &accessoryInformationService,
                                                                                  &hapProtocolInformationService,
                                                                                  &pairingService,
                                                                                  NULL },
                                        .callbacks = { .identify = IdentifyAccessory } };
static HAPAccessory accessory = { .aid = 2,
                                  //.category = kHAPAccessoryCategory_Lighting,
                                  .category = kHAPAccessoryCategory_BridgedAccessory,
                                  .name = "Acme Light",
                                  .manufacturer = "Acme",
                                  .model = "LightBulb1,1",
                                  .serialNumber = "099DB48E9E28",
                                  .firmwareVersion = "1",
                                  .hardwareVersion = "1",
                                  .services = (const HAPService* const[]) { &accessoryInformationService,
                                                                            &hapProtocolInformationService,
                                                                            &pairingService,
                                                                            &lightBulbService,
                                                                            NULL },
                                  .callbacks = { .identify = IdentifyAccessory } };
const HAPAccessory* _Nullable const* _Nullable bridgedAccessories =
    (const HAPAccessory* const[]) { &accessory,
                                    NULL };

void AppAccessoryServerStart(void) {
    HAPAccessoryServerStartBridge(
        accessoryConfiguration.server, &bridgeAccessory,
        bridgedAccessories, true
    );
}

Successfully added accessories in the home, the name shows "Light Bulb", but what I expect is "Acme Light". Thanks!

imlsq commented 3 years ago

I have found out the cause of the problem.

const HAPService lightBulbService = {
    .iid = kIID_LightBulb,
    .serviceType = &kHAPServiceType_LightBulb,
    .debugDescription = kHAPServiceDebugDescription_LightBulb,
    .name = "Light",
    .properties = { .primaryService = true, .hidden = false, .ble = { .supportsConfiguration = false } },
    .linkedServices = NULL,
    .characteristics = (const HAPCharacteristic* const[]) { &lightBulbServiceSignatureCharacteristic,
                                                            //&lightBulbNameCharacteristic,
                                                            &lightBulbOnCharacteristic
                                                            NULL }
};

you needn`t set 'lightBulbNameCharacteristic'