add all existing items, homekit export
This commit is contained in:
60
src/Export.ts
Normal file
60
src/Export.ts
Normal 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 }
|
||||
}
|
Reference in New Issue
Block a user