SimpleTopicSwitchItem added, Regallicht changed
This commit is contained in:
70
src/SimpleTopicSwitchItem.ts
Normal file
70
src/SimpleTopicSwitchItem.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { AItem } from './AItem'
|
||||
import { SwitchExport, ExportType } from './Export'
|
||||
import { HasStateAndFeedbackTopicAndLabelAndRoom } from './AItem';
|
||||
|
||||
export class SimpleTopicSwitchItem extends AItem implements HasStateAndFeedbackTopicAndLabelAndRoom {
|
||||
private oldState: string|undefined
|
||||
private state: string
|
||||
private actionTopic: string
|
||||
private deviceFeedbackTopic: string
|
||||
private stateFeedbackTopic: string
|
||||
private stateTopic: string
|
||||
private type: string
|
||||
private partId: number
|
||||
|
||||
getLabel(): string {
|
||||
return this.label
|
||||
}
|
||||
|
||||
getRoom() : string {
|
||||
return this.room
|
||||
}
|
||||
|
||||
getStateTopic() : string {
|
||||
return this.stateTopic
|
||||
}
|
||||
|
||||
getStateFeedbackTopic() : string {
|
||||
return this.stateFeedbackTopic
|
||||
}
|
||||
|
||||
getState() : string {
|
||||
return this.state
|
||||
}
|
||||
|
||||
constructor(floor: string, room: string, item: string, label: string, actionTopic: string) {
|
||||
super(floor, room, item, label)
|
||||
this.stateTopic = `${this.topicFirstPart}/state`
|
||||
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`
|
||||
this.actionTopic = actionTopic
|
||||
this.subscribeTopics = [
|
||||
this.stateTopic
|
||||
]
|
||||
this.state = 'OFF'
|
||||
this.oldState = undefined
|
||||
}
|
||||
|
||||
exportItem() : ExportType|null {
|
||||
return SwitchExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type)
|
||||
}
|
||||
|
||||
processMessage(topic: string, payload: string) : void {
|
||||
switch (topic) {
|
||||
case this.stateTopic:
|
||||
this.state = payload
|
||||
mqttHandler.send(this.stateFeedbackTopic, this.state)
|
||||
if (this.state != this.oldState) {
|
||||
if (this.state == 'ON') {
|
||||
mqttHandler.send(this.actionTopic, 'true')
|
||||
} else {
|
||||
mqttHandler.send(this.actionTopic, 'false')
|
||||
}
|
||||
this.oldState = this.state
|
||||
}
|
||||
break
|
||||
}
|
||||
this.emit('somethingChanged')
|
||||
}
|
||||
}
|
11
src/main.ts
11
src/main.ts
@ -26,6 +26,8 @@ import { RelayBoxThing } from './RelayBox'
|
||||
import { HeatingScene } from './HeatingScene'
|
||||
import { TwoLedSignal } from './TwoLedSignal'
|
||||
import { MySwitchThing, MySwitchSingleItem } from './MySwitchThing'
|
||||
import { SimpleTopicSwitchItem } from './SimpleTopicSwitchItem'
|
||||
|
||||
|
||||
|
||||
logger.info("Dispatcher starting")
|
||||
@ -137,10 +139,11 @@ allRelevantLights.push(diningRoomCupboardLight)
|
||||
allLights.push(diningRoomCupboardLight)
|
||||
|
||||
// Esszimmer Regallicht
|
||||
let diningRoomShelfLight = new UrlSwitchItem('Gnd', 'Esszimmer', 'ShelfLight', 'Regallicht', 'http://172.16.2.43/dv?dv=1023', 'http://172.16.2.43/dv?dv=0')
|
||||
// diningRoomShelfLight.start()
|
||||
// allLabeledItems.push(diningRoomShelfLight)
|
||||
// allRelevantLights.push(diningRoomShelfLight)
|
||||
let diningRoomShelfLight = new SimpleTopicSwitchItem('Gnd', 'Esszimmer', 'ShelfLight', 'Regallicht', 'IoT/WifiRelay1/State')
|
||||
diningRoomShelfLight.start()
|
||||
allLabeledItems.push(diningRoomShelfLight)
|
||||
allRelevantLights.push(diningRoomShelfLight)
|
||||
allLights.push(diningRoomShelfLight)
|
||||
|
||||
let diningRoomNaehkaestchenLight = new HueColorBulbItem('Gnd', 'Esszimmer', 'NaehkaestchenLight', 'Nähkästchen', 15)
|
||||
diningRoomNaehkaestchenLight.start()
|
||||
|
Reference in New Issue
Block a user