Skip to content

Commit

Permalink
Improve default value handling of AccessoryInformation characteristics
Browse files Browse the repository at this point in the history
Removed error thrown when setting undefined
  • Loading branch information
Supereg committed Nov 11, 2020
1 parent 5f546cb commit 4d8039a
Showing 2 changed files with 18 additions and 9 deletions.
16 changes: 14 additions & 2 deletions src/lib/Characteristic.ts
Original file line number Diff line number Diff line change
@@ -1000,7 +1000,18 @@ export class Characteristic extends EventEmitter {
case Formats.BOOL:
return false;
case Formats.STRING:
return "";
switch (this.UUID) {
case Characteristic.Manufacturer.UUID:
return "Default-Manufacturer";
case Characteristic.Model.UUID:
return "Default-Model";
case Characteristic.SerialNumber.UUID:
return "Default-SerialNumber";
case Characteristic.FirmwareRevision.UUID:
return "0.0.0";
default:
return "";
}
case Formats.DATA:
return null; // who knows!
case Formats.TLV8:
@@ -1169,7 +1180,8 @@ export class Characteristic extends EventEmitter {
*/
private validateUserInput(value?: Nullable<CharacteristicValue>): Nullable<CharacteristicValue> {
if (value === undefined) {
throw new Error(`[${this.displayName}] characteristic was supplied illegal value: undefined!`);
console.warn(`[${this.displayName}] characteristic was supplied illegal value: undefined! This might throw errors in the future!`);
return this.value; // don't change the value
} else if (value === null) {
if (this.UUID === Characteristic.Model.UUID || this.UUID === Characteristic.SerialNumber.UUID) { // mirrors the statement in case: Formats.STRING
console.error(new Error(`[${this.displayName}] characteristic must have a non null value otherwise HomeKit will reject this accessory. Ignoring new value.`).stack);
11 changes: 4 additions & 7 deletions src/lib/gen/HomeKit.ts
Original file line number Diff line number Diff line change
@@ -916,10 +916,7 @@ export class FirmwareRevision extends Characteristic {
static readonly UUID: string = '00000052-0000-1000-8000-0026BB765291';

constructor() {
// TODO change later
// @ts-expect-error
super('Firmware Revision', FirmwareRevision.UUID);
this.setProps({
super('Firmware Revision', FirmwareRevision.UUID, {
format: Formats.STRING,
perms: [Perms.PAIRED_READ]
});
@@ -4026,10 +4023,10 @@ export class AccessoryInformation extends Service {

// Required Characteristics
this.addCharacteristic(Characteristic.Identify);
this.addCharacteristic(Characteristic.Manufacturer).updateValue("Default-Manufacturer");
this.addCharacteristic(Characteristic.Model).updateValue("Default-Model");
this.addCharacteristic(Characteristic.Manufacturer);
this.addCharacteristic(Characteristic.Model);
this.addCharacteristic(Characteristic.Name);
this.addCharacteristic(Characteristic.SerialNumber).updateValue("Default-SerialNumber");
this.addCharacteristic(Characteristic.SerialNumber);

// Optional Characteristics
this.addOptionalCharacteristic(Characteristic.AccessoryFlags);

0 comments on commit 4d8039a

Please sign in to comment.