openhab export added
This commit is contained in:
@ -1,22 +1,30 @@
|
||||
export type ExportType = {
|
||||
'homekit': HomekitExportType,
|
||||
'openhab': string
|
||||
}
|
||||
|
||||
export type HomekitExportType = {
|
||||
'id': string,
|
||||
'object': any
|
||||
}
|
||||
|
||||
|
||||
export function SwitchHomekitExport(itemId: string, label: string, stateTopic: string, stateFeedbackTopic: string, type: string) : HomekitExportType {
|
||||
let out: HomekitExportType
|
||||
export function SwitchExport(itemId: string, label: string, stateTopic: string, stateFeedbackTopic: string, type: string) : ExportType {
|
||||
let homekitOut: HomekitExportType
|
||||
switch (type) {
|
||||
case 'bulb':
|
||||
out = SwitchHomekitBulbExport(itemId, label, stateTopic, stateFeedbackTopic)
|
||||
homekitOut = SwitchHomekitBulbExport(itemId, label, stateTopic, stateFeedbackTopic)
|
||||
break
|
||||
case 'outlet':
|
||||
out = SwitchHomekitOutletExport(itemId, label, stateTopic, stateFeedbackTopic)
|
||||
homekitOut = SwitchHomekitOutletExport(itemId, label, stateTopic, stateFeedbackTopic)
|
||||
break
|
||||
default:
|
||||
throw new Error(`no homekit export function for type ${type}`)
|
||||
}
|
||||
return out
|
||||
|
||||
let openhabOut : string = SwitchOpenHABExport(itemId, label, stateTopic, stateFeedbackTopic)
|
||||
|
||||
return { 'homekit': homekitOut, 'openhab': openhabOut }
|
||||
}
|
||||
|
||||
|
||||
@ -57,4 +65,10 @@ function SwitchHomekitOutletExport(id: string, label: string, setOn: string, sta
|
||||
"config": {}
|
||||
}
|
||||
return { 'id': id, 'object': o }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function SwitchOpenHABExport(id: string, label: string, setOn: string, statusOn: string): string {
|
||||
// Switch windowLightKitchen {mqtt=">[localbroker:nodered/items/windowLightKitchen:command:*:default]", mqtt="<[localbroker:nodered/items/windowLightKitchen/feedback:state:default]"}
|
||||
return `Switch ${id} {mqtt=">[localbroker:${setOn}:command:*:default]", mqtt="<[localbroker:${statusOn}:state:default]"}`
|
||||
}
|
Reference in New Issue
Block a user