Skip to content

Commit

Permalink
"Resolved TypeScript Null Check Errors
Browse files Browse the repository at this point in the history
- Added safety checks for potentially undefined services in VZugAccessory.
- Ensured AccessoryInformation service is available before setting Serial Number and Manufacturer characteristics.
- Improved error handling for undefined service cases."
  • Loading branch information
rtuszik committed Dec 2, 2023
1 parent 11791a8 commit 40afa90
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/VZugAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ export class VZugAccessory {
const modelNumber = serialNumber.substring(0, 5);
const modelName = this.findModelName(modelNumber);

this.accessory.getService(this.api.hap.Service.AccessoryInformation)
.setCharacteristic(this.api.hap.Characteristic.SerialNumber, serialNumber)
.setCharacteristic(this.api.hap.Characteristic.Model, modelName);
const accessoryInfoService = this.accessory.getService(this.api.hap.Service.AccessoryInformation);
if (accessoryInfoService) {
accessoryInfoService
.setCharacteristic(this.api.hap.Characteristic.SerialNumber, serialNumber)
.setCharacteristic(this.api.hap.Characteristic.Model, modelName);
} else {
this.log.error('Accessory Information Service not found');
}
}
} catch (error) {
this.log.error('Error fetching serial number:', error instanceof Error ? error.message : 'Unknown error');
Expand All @@ -66,11 +71,16 @@ export class VZugAccessory {
}

private setManufacturer() {
this.accessory.getService(this.api.hap.Service.AccessoryInformation)
.setCharacteristic(this.api.hap.Characteristic.Manufacturer, 'V-Zug');
const accessoryInfoService = this.accessory.getService(this.api.hap.Service.AccessoryInformation);
if (accessoryInfoService) {
accessoryInfoService.setCharacteristic(this.api.hap.Characteristic.Manufacturer, 'V-Zug');
} else {
this.log.error('Accessory Information Service not found');
}
}



async fetchDeviceStatus() {
try {
const url = `http://${this.config.ip}/ai?command=getDeviceStatus`;
Expand Down

0 comments on commit 40afa90

Please sign in to comment.