Skip to content

Commit

Permalink
homekit: datamigration for addIdentifyingMaterial
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Apr 7, 2024
1 parent 00d8054 commit 0db3b7d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions plugins/homekit/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/homekit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scrypted/homekit",
"version": "1.2.45",
"version": "1.2.46",
"description": "HomeKit Plugin for Scrypted",
"scripts": {
"scrypted-setup-project": "scrypted-setup-project",
Expand Down
6 changes: 5 additions & 1 deletion plugins/homekit/src/hap-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,17 @@ export function getRandomPort() {
return Math.round(30000 + Math.random() * 20000);
}

export function createHAPUsernameStorageSettingsDict(device: { storage: Storage, name?: string }, group: string, subgroup?: string): StorageSettingsDict<'mac' | 'qrCode' | 'pincode' | 'portOverride' | 'resetAccessory'> {
export function createHAPUsernameStorageSettingsDict(device: { storage: Storage, name?: string }, group: string, subgroup?: string): StorageSettingsDict<'mac' | 'addIdentifyingMaterial' | 'qrCode' | 'pincode' | 'portOverride' | 'resetAccessory'> {
const alertReload = () => {
sdk.log.a(`The HomeKit plugin will reload momentarily for the changes to ${device.name} to take effect.`);
sdk.deviceManager.requestRestart();
}

return {
addIdentifyingMaterial: {
hide: true,
type: 'boolean',
},
qrCode: {
group,
// subgroup,
Expand Down
9 changes: 6 additions & 3 deletions plugins/homekit/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ export class HomeKitPlugin extends ScryptedDeviceBase implements MixinProvider,
},
undefined, 'Pairing'));
storageSettings.settings.pincode.persistedDefaultValue = randomPinCode();
// TODO: change this value after this current default has been persisted to existing clients.
// changing it now will cause existing accessories be renamed.
storageSettings.settings.addIdentifyingMaterial.persistedDefaultValue = false;

const mixinConsole = deviceManager.getMixinConsole(device.id, this.nativeId);

Expand All @@ -277,7 +280,7 @@ export class HomeKitPlugin extends ScryptedDeviceBase implements MixinProvider,
published = true;
mixinConsole.log('Device is in accessory mode and is online. HomeKit services are being published.');

await this.publishAccessory(accessory, storageSettings.values.mac, storageSettings.values.pincode, standaloneCategory, storageSettings.values.portOverride);
await this.publishAccessory(accessory, storageSettings.values.mac, storageSettings.values.pincode, standaloneCategory, storageSettings.values.portOverride, storageSettings.values.addIdentifyingMaterial);
if (!hasPublished) {
hasPublished = true;
storageSettings.values.qrCode = accessory.setupURI();
Expand Down Expand Up @@ -420,15 +423,15 @@ export class HomeKitPlugin extends ScryptedDeviceBase implements MixinProvider,
return bind;
}

async publishAccessory(accessory: Accessory, username: string, pincode: string, category: Categories, port: number) {
async publishAccessory(accessory: Accessory, username: string, pincode: string, category: Categories, port: number, addIdentifyingMaterial: boolean) {
const bind = await this.getAdvertiserInterfaceBind();

await accessory.publish({
username,
port,
pincode,
category,
addIdentifyingMaterial: true,
addIdentifyingMaterial,
advertiser: this.getAdvertiser(),
bind,
});
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/storage-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class StorageSettings<T extends string> implements Settings {
if (!setting)
return this.device.storage.getItem(key);
const readDefaultValue = () => {
if (setting.persistedDefaultValue) {
if (setting.persistedDefaultValue != null) {
this.putSettingInternal(setting, undefined, key, setting.persistedDefaultValue);
return setting.persistedDefaultValue;
}
Expand Down

0 comments on commit 0db3b7d

Please sign in to comment.