add all existing items, homekit export

This commit is contained in:
Wolfgang Hottgenroth
2018-01-10 14:15:43 +01:00
parent 153b8570e4
commit 8a6547ff91
20 changed files with 746 additions and 42 deletions

60
src/Export.ts Normal file
View File

@ -0,0 +1,60 @@
export type HomekitExportType = {
'id': string,
'object': any
}
export function SwitchHomekitExport(itemId: string, label: string, stateTopic: string, stateFeedbackTopic: string, type: string) : HomekitExportType {
let out: HomekitExportType
switch (type) {
case 'bulb':
out = SwitchHomekitBulbExport(itemId, label, stateTopic, stateFeedbackTopic)
break
case 'outlet':
out = SwitchHomekitOutletExport(itemId, label, stateTopic, stateFeedbackTopic)
break
default:
throw new Error(`no homekit export function for type ${type}`)
}
return out
}
function SwitchHomekitBulbExport(id: string, label: string, setOn: string, statusOn: string) : HomekitExportType {
let o : any = {
"id": id,
"name": label,
"service": "Lightbulb",
"topic": {
"setOn": setOn,
"statusOn": statusOn
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
}
return { 'id': id, 'object': o }
}
function SwitchHomekitOutletExport(id: string, label: string, setOn: string, statusOn: string) : HomekitExportType {
let o : any = {
"id": id,
"name": label,
"service": "Outlet",
"topic": {
"setOn": setOn,
"statusOn": statusOn
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF"
},
"config": {}
}
return { 'id': id, 'object': o }
}