add all existing items, homekit export
This commit is contained in:
@ -6,8 +6,8 @@ export abstract class AHomematicItem extends AItem {
|
||||
protected actionTopicPre: string;
|
||||
protected homegearTopicPre: string;
|
||||
protected hmId: number;
|
||||
constructor(floor: string, room: string, item: string, hmId: number) {
|
||||
super(floor, room, item);
|
||||
constructor(floor: string, room: string, item: string, label: string, hmId: number) {
|
||||
super(floor, room, item, label);
|
||||
this.hmId = hmId;
|
||||
this.homegearTopicPre = 'homegear/instance1';
|
||||
this.actionTopicPre = `${this.homegearTopicPre}/set/${this.hmId}`;
|
||||
|
15
src/AItem.ts
15
src/AItem.ts
@ -1,26 +1,37 @@
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { HomekitExportType } from './Export'
|
||||
|
||||
|
||||
export abstract class AItem {
|
||||
protected topicFirstPart: string
|
||||
protected itemId: string
|
||||
protected label: string
|
||||
private item: string
|
||||
private room: string
|
||||
private floor: string
|
||||
protected subscribeTopics: string[]
|
||||
|
||||
|
||||
constructor(floor: string, room: string, item: string) {
|
||||
constructor(floor: string, room: string, item: string, label: string = '') {
|
||||
this.floor = floor
|
||||
this.room = room
|
||||
this.item = item
|
||||
this.itemId = `${this.floor}.${this.room}.${this.item}`
|
||||
if (label == '') {
|
||||
this.label = this.itemId
|
||||
} else {
|
||||
this.label = label
|
||||
}
|
||||
this.topicFirstPart = `dispatcher_ng/items/${this.floor}/${this.room}/${this.item}`
|
||||
}
|
||||
|
||||
abstract processMessage(topic: string, payload: string) : void
|
||||
|
||||
exportHomekit() : HomekitExportType {
|
||||
return {'id': this.itemId, 'object': null }
|
||||
}
|
||||
|
||||
start() : void {
|
||||
mqttHandler.register(this.subscribeTopics, (topic: string, payload: string) : void => {
|
||||
logger.info(`item ${this.itemId}: ${topic}, ${payload}`)
|
||||
@ -28,5 +39,3 @@ export abstract class AItem {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
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 }
|
||||
}
|
@ -7,13 +7,14 @@ export class Forwarder extends AItem {
|
||||
private targetTopics: string[]
|
||||
private inTopic: string
|
||||
|
||||
constructor(floor: string, room: string, item: string, topicLastPart: string, targetTopics: string[]) {
|
||||
super(floor, room, item)
|
||||
constructor(floor: string, room: string, item: string, label: string, topicLastPart: string, targetTopics: string[]) {
|
||||
super(floor, room, item, label)
|
||||
this.inTopic = `${this.topicFirstPart}/${topicLastPart}`
|
||||
this.subscribeTopics = [ this.inTopic ]
|
||||
this.targetTopics = targetTopics
|
||||
}
|
||||
|
||||
|
||||
processMessage(topic: string, payload: string) : void {
|
||||
switch (topic) {
|
||||
case this.inTopic:
|
||||
|
@ -17,8 +17,8 @@ export class HomematicDimmerItem extends AHomematicItem {
|
||||
private brightTopic: string
|
||||
private stateTopic: string
|
||||
|
||||
constructor(floor: string, room: string, item: string, hmId: number) {
|
||||
super(floor, room, item, hmId)
|
||||
constructor(floor: string, room: string, item: string, label: string, hmId: number) {
|
||||
super(floor, room, item, label, hmId)
|
||||
this.stateTopic = `${this.topicFirstPart}/state`
|
||||
this.brightTopic = `${this.topicFirstPart}/bright`
|
||||
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`
|
||||
|
@ -33,7 +33,7 @@ export class HomematicFourButtonThing extends AHomematicItem {
|
||||
private itemObjs: HomematicFourButtonSingleItem[]
|
||||
|
||||
constructor(floor: string, room: string, item: string, hmId: number, itemObjs: HomematicFourButtonSingleItem[]) {
|
||||
super(floor, room, item, hmId)
|
||||
super(floor, room, item, '', hmId)
|
||||
this.itemObjs = itemObjs
|
||||
if (this.itemObjs.length != 4) {
|
||||
throw new Error('itemObjs for HomematicFourButtonThing must have four elements')
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { AHomematicItem } from './AHomematicItem'
|
||||
|
||||
import { SwitchHomekitExport, HomekitExportType } from './Export'
|
||||
|
||||
export class HomematicSwitchItem extends AHomematicItem {
|
||||
private oldState: string|undefined
|
||||
@ -10,9 +10,10 @@ export class HomematicSwitchItem extends AHomematicItem {
|
||||
private deviceFeedbackTopic: string
|
||||
private stateFeedbackTopic: string
|
||||
private stateTopic: string
|
||||
private type: string
|
||||
|
||||
constructor(floor: string, room: string, item: string, hmId: number) {
|
||||
super(floor, room, item, hmId)
|
||||
constructor(floor: string, room: string, item: string, label: string, hmId: number, type: string = 'bulb') {
|
||||
super(floor, room, item, label, hmId)
|
||||
this.stateTopic = `${this.topicFirstPart}/state`
|
||||
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`
|
||||
this.deviceFeedbackTopic = `${this.deviceTopicPre}/1/STATE`
|
||||
@ -23,8 +24,12 @@ export class HomematicSwitchItem extends AHomematicItem {
|
||||
]
|
||||
this.state = 'OFF'
|
||||
this.oldState = undefined
|
||||
this.type = type
|
||||
}
|
||||
|
||||
exportHomekit() : HomekitExportType {
|
||||
return SwitchHomekitExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type)
|
||||
}
|
||||
|
||||
processMessage(topic: string, payload: string) : void {
|
||||
switch (topic) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { AItem } from './AItem'
|
||||
import { SwitchHomekitExport, HomekitExportType } from './Export'
|
||||
|
||||
|
||||
export class M433SwitchItem extends AItem {
|
||||
@ -11,9 +12,10 @@ export class M433SwitchItem extends AItem {
|
||||
private actionTopic: string
|
||||
private stateFeedbackTopic: string
|
||||
private stateTopic: string
|
||||
private type: string
|
||||
|
||||
constructor(floor: string, room: string, item: string, onCode: string, offCode: string) {
|
||||
super(floor, room, item)
|
||||
constructor(floor: string, room: string, item: string, label: string, onCode: string, offCode: string, type: string = 'bulb') {
|
||||
super(floor, room, item, label)
|
||||
this.stateTopic = `${this.topicFirstPart}/state`
|
||||
this.subscribeTopics = [this.stateTopic]
|
||||
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`
|
||||
@ -22,6 +24,11 @@ export class M433SwitchItem extends AItem {
|
||||
this.oldState = undefined
|
||||
this.onCode = onCode
|
||||
this.offCode = offCode
|
||||
this.type = type
|
||||
}
|
||||
|
||||
exportHomekit() : HomekitExportType {
|
||||
return SwitchHomekitExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type)
|
||||
}
|
||||
|
||||
processMessage(topic: string, payload: string) {
|
||||
|
143
src/main.ts
143
src/main.ts
@ -1,7 +1,11 @@
|
||||
import * as fs from 'fs'
|
||||
|
||||
import * as config from './config'
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
|
||||
import { AItem } from './AItem'
|
||||
import { HomekitExportType } from './Export'
|
||||
import { M433SwitchItem } from './M433SwitchItem'
|
||||
import { HomematicFourButtonThing, HomematicFourButtonSingleItem } from './HomematicFourButtonThing'
|
||||
import { DimmerAdaptor } from './DimmerAdaptor'
|
||||
@ -14,12 +18,121 @@ import { Forwarder } from './Forwarder'
|
||||
|
||||
logger.info("Dispatcher starting")
|
||||
|
||||
let aquariumLight = new M433SwitchItem('1st', 'Anna', 'AquariumLight', '14665044 24 1', '14665041 24 1')
|
||||
aquariumLight.start()
|
||||
|
||||
let deskLight = new M433SwitchItem('Gnd', 'Hallway', 'DeskLight', '83221 24 1', '83220 24 1')
|
||||
deskLight.start()
|
||||
let allLabeledItems : Array<AItem> = new Array<AItem>()
|
||||
|
||||
|
||||
// Anna -----------------------------------------------------------------------------------------------------
|
||||
// Anna Aquarium 14665044 24 1 14665041 24 1
|
||||
let aquariumLight = new M433SwitchItem('1st', 'Anna', 'AquariumLight', 'Aquariumlicht', '14665044 24 1', '14665041 24 1')
|
||||
aquariumLight.start()
|
||||
allLabeledItems.push(aquariumLight)
|
||||
|
||||
// Anna Bett 14668116 24 1 14668113 24 1
|
||||
let annaBedLight = new M433SwitchItem('1st', 'Anna', 'BedLight', 'Bettlicht Anna', '14668116 24 1', '14668113 24 1')
|
||||
annaBedLight.start()
|
||||
allLabeledItems.push(annaBedLight)
|
||||
|
||||
// Matthias -------------------------------------------------------------------------------------------------
|
||||
// Matthias Stehlampen 7 24 1 6 24 1
|
||||
let matthiasStandLights = new M433SwitchItem('1st', 'Matthias', 'Stehlampen Matthias', 'StandLight', '7 24 1', '6 24 1')
|
||||
matthiasStandLights.start()
|
||||
allLabeledItems.push(matthiasStandLights)
|
||||
|
||||
// Matthias Bett 15 24 1 14 24 1
|
||||
let matthiasBedLight = new M433SwitchItem('1st', 'Matthias', 'BedLight', 'Bettlicht Matthias', '15 24 1', '14 24 1')
|
||||
matthiasBedLight.start()
|
||||
allLabeledItems.push(matthiasBedLight)
|
||||
|
||||
// Matthias Lautsprecher 11 24 1 10 24 1
|
||||
let matthiasSpeaker = new M433SwitchItem('1st', 'Matthias', 'Speaker', 'Lautsprecher Matthias', '11 24 1', '10 24 1', 'outlet')
|
||||
matthiasSpeaker.start()
|
||||
allLabeledItems.push(matthiasSpeaker)
|
||||
|
||||
// Esszimmer ------------------------------------------------------------------------------------------------
|
||||
// Esszimmer kleine Lampe 69653 24 1 69652 24 1
|
||||
let diningRoomSmallLight = new M433SwitchItem('Gnd', 'DiningRoom', 'SmallLight', 'kleine Lampe Esszimmer', '69653 24 1', '69652 24 1')
|
||||
diningRoomSmallLight.start()
|
||||
allLabeledItems.push(diningRoomSmallLight)
|
||||
|
||||
// Esszimmer Stehlampe 86037 24 1 86036 24 1
|
||||
let diningRoomStandLight = new M433SwitchItem('Gnd', 'DiningRoom', 'StandLight', 'Stehlampe Esszimmer', '86037 24 1', '86036 24 1')
|
||||
diningRoomStandLight.start()
|
||||
allLabeledItems.push(diningRoomStandLight)
|
||||
|
||||
// Esszimmer Schranklicht 65813 24 1 65812 24 1
|
||||
let diningRoomCupboardLight = new M433SwitchItem('Gnd', 'DiningRoom', 'CupboardLight', 'Schranklicht Esszimmer', '65813 24 1', '65812 24 1')
|
||||
diningRoomCupboardLight.start()
|
||||
allLabeledItems.push(diningRoomCupboardLight)
|
||||
|
||||
// Wohnzimmer -----------------------------------------------------------------------------------------------
|
||||
// Wohnzimmer grosse Lampe 65557 24 1 65556 24 1
|
||||
let livingRoomLargeLight = new M433SwitchItem('Gnd', 'LivingRoom', 'LargeLight', 'große Lampe Wohnzimmer', '65557 24 1', '65556 24 1')
|
||||
livingRoomLargeLight.start()
|
||||
allLabeledItems.push(livingRoomLargeLight)
|
||||
|
||||
// Wohnzimmer kleine Lampe 87061 24 1 87060 24 1
|
||||
let livingRoomSmallLight = new M433SwitchItem('Gnd', 'LivingRoom', 'SmallLight', 'kleine Lampe Wohnzimmer', '87061 24 1', '87060 24 1')
|
||||
livingRoomSmallLight.start()
|
||||
allLabeledItems.push(livingRoomSmallLight)
|
||||
|
||||
// Wohnzimmer Sterne 69909 24 1 69908 24 1
|
||||
let livingRoomStars = new M433SwitchItem('Gnd', 'LivingRoom', 'Stars', 'Sterne Wohnzimmer', '69909 24 1', '69908 24 1')
|
||||
livingRoomStars.start()
|
||||
allLabeledItems.push(livingRoomStars)
|
||||
|
||||
// Wohnzimmer kleine Stehlampe 81941 24 1 81940 24 1
|
||||
let livingRoomStandLight = new M433SwitchItem('Gnd', 'LivingRoom', 'StandLight', 'Stehlampe Wohnzimmer', '81941 24 1', '81940 24 1')
|
||||
livingRoomStandLight.start()
|
||||
allLabeledItems.push(livingRoomStandLight)
|
||||
|
||||
|
||||
// Flur -----------------------------------------------------------------------------------------------------
|
||||
// Flur Schreibtisch 83221 24 1 83220 24 1
|
||||
let hallwayDeskLight = new M433SwitchItem('Gnd', 'Hallway', 'DeskLight', 'Schreibtischlampe Flur', '83221 24 1', '83220 24 1')
|
||||
hallwayDeskLight.start()
|
||||
allLabeledItems.push(hallwayDeskLight)
|
||||
|
||||
// Flur Stehlampe 8704914 24 5 8793154 24 5
|
||||
let hallwayStandLight = new M433SwitchItem('Gnd', 'Hallway', 'StandLight', 'Stehlampe Flur', '8704914 24 5', '8793154 24 5')
|
||||
hallwayStandLight.start()
|
||||
allLabeledItems.push(hallwayStandLight)
|
||||
|
||||
// Flur Schranklicht 66581 24 1 66580 24 1
|
||||
let hallwayWardrobeLight = new M433SwitchItem('Gnd', 'Hallway', 'StandLight', 'Schranklicht Flur', '66581 24 1', '66580 24 1')
|
||||
hallwayWardrobeLight.start()
|
||||
allLabeledItems.push(hallwayWardrobeLight)
|
||||
|
||||
|
||||
// Küche ----------------------------------------------------------------------------------------------------
|
||||
// Küche Fensterbank 66837 24 1 66836 24 1
|
||||
let kitchenWindowLight = new M433SwitchItem('Gnd', 'Kitchen', 'WindowLight', 'Fensterbanklicht Küche', '66837 24 1', '66836 24 1')
|
||||
kitchenWindowLight.start()
|
||||
allLabeledItems.push(kitchenWindowLight)
|
||||
|
||||
// Küche Deckenlampe 82197 24 1 82196 24 1
|
||||
let kitchenCeilingLight = new M433SwitchItem('Gnd', 'Kitchen', 'CeilingLight', 'Deckenlampe Küche', '82197 24 1', '82196 24 1')
|
||||
kitchenWindowLight.start()
|
||||
allLabeledItems.push(kitchenCeilingLight)
|
||||
|
||||
|
||||
// Schlafzimmer ---------------------------------------------------------------------------------------------
|
||||
// Schlafzimmer Wolfgangs Seite 13976916 24 1 13976913 24 1
|
||||
let bedRoomWolfgangsSide = new M433SwitchItem('1st', 'BedRoom', 'WolfgangsSide', 'Wolfgangs Seite Schlafzimmer', '13976916 24 1', '13976913 24 1')
|
||||
bedRoomWolfgangsSide.start()
|
||||
allLabeledItems.push(bedRoomWolfgangsSide)
|
||||
|
||||
// Schlafzimmer Pattys Seite 13980756 24 1 13980753 24 1
|
||||
let bedRoomPattysSide = new M433SwitchItem('1st', 'BedRoom', 'PattysSide', 'Pattys Seite Schlafzimmer', '13980756 24 1', '13980753 24 1')
|
||||
bedRoomPattysSide.start()
|
||||
allLabeledItems.push(bedRoomPattysSide)
|
||||
|
||||
// Schlafzimmer Fensterbank 13979988 24 1 13979985 24 1
|
||||
let bedRoomWindowLight = new M433SwitchItem('1st', 'BedRoom', 'WindowLight', 'Fensterbanklicht Schlafzimmer', '13979988 24 1', '13979985 24 1')
|
||||
bedRoomWindowLight.start()
|
||||
allLabeledItems.push(bedRoomWindowLight)
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
let testFourButton = new HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [
|
||||
new HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'),
|
||||
new HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/DeskLight/timerIn'),
|
||||
@ -34,13 +147,13 @@ testDimmerAdaptor.start()
|
||||
let testTimerAdaptor = new TimerAdaptor('Gnd', 'Hallway', 'DeskLight', 10)
|
||||
testTimerAdaptor.start()
|
||||
|
||||
let testLight = new HomematicDimmerItem('Gnd', 'Hallway', 'Testlight', 8)
|
||||
let testLight = new HomematicDimmerItem('Gnd', 'Hallway', 'Testlight', 'Testlampe mit Dimmer', 8)
|
||||
testLight.start()
|
||||
|
||||
let testLight2 = new HomematicSwitchItem('Gnd', 'Hallway', 'Testlight2', 5)
|
||||
let testLight2 = new HomematicSwitchItem('Gnd', 'Hallway', 'Testlight2', 'Testlampe ohne Dimmer', 5)
|
||||
testLight2.start()
|
||||
|
||||
let testForwarder = new Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', [
|
||||
let testForwarder = new Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', 'TestForwarder', [
|
||||
'dispatcher_ng/items/Gnd/Hallway/Testlight2/state',
|
||||
'dispatcher_ng/items/Gnd/Hallway/DeskLight/state'
|
||||
])
|
||||
@ -48,6 +161,20 @@ testForwarder.start()
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// Homekit export
|
||||
let homekitObject : { [key:string]:{} } = {}
|
||||
|
||||
allLabeledItems.forEach((item: AItem) => {
|
||||
let homekitExport : HomekitExportType = item.exportHomekit()
|
||||
if ('id' in homekitExport) {
|
||||
homekitObject[homekitExport['id']] = homekitExport['object']
|
||||
}
|
||||
})
|
||||
fs.writeFileSync(config.dict.homekitFile, JSON.stringify(homekitObject, null, 4))
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
mqttHandler.exec()
|
||||
logger.info("Dispatcher running")
|
||||
|
||||
|
Reference in New Issue
Block a user