Skip to content

Commit

Permalink
Added function discovery from response
Browse files Browse the repository at this point in the history
  • Loading branch information
sajmonr committed Mar 4, 2023
1 parent de889f7 commit 7902da6
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/services/discovery.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { getDeviceTypeForKey } from '../models/device-type';
import { Device } from '../models/device';
import { createAccessoryForDevice } from '../accessories/device-accessory-factory';
import { AxiosError } from 'axios';
import { DeviceFunction, DeviceFunctions } from '../models/device-functions';
import { DeviceFunctionResponse } from '../responses/device-function-response';

/**
* Service for discovering and managing devices
Expand Down Expand Up @@ -116,8 +118,26 @@ export class DiscoveryService{
name: response.friendlyName,
type: type,
manufacturer: response.description.device.manufacturerName,
model: response.description.device.model.split(',').map(m => m.trim())
model: response.description.device.model.split(',').map(m => m.trim()),
functions: this.getFunctionsFromResponse(response.description.functions)
};
}

private getFunctionsFromResponse(supportedFunctions: DeviceFunctionResponse[]): DeviceFunction[]{
const output: DeviceFunction[] = [];

for(const fc of supportedFunctions){
// Get the type for the function
const type = DeviceFunctions
.find(df => df.functionInstanceName === fc.functionInstance && df.functionClass === fc.functionClass)
?.type;

if(type === undefined || output.indexOf(type) >= 0) continue;

output.push(type);
}

return output;
}

}

0 comments on commit 7902da6

Please sign in to comment.