fixes and start of UrlSwitchItem
This commit is contained in:
@ -26,7 +26,7 @@ export abstract class AItem {
|
||||
this.floor = floor
|
||||
this.room = room
|
||||
this.item = item
|
||||
this.itemId = `${this.floor}.${this.room}.${this.item}`
|
||||
this.itemId = `${this.floor}_${this.room}_${this.item}`
|
||||
if (label == '') {
|
||||
this.label = this.itemId
|
||||
} else {
|
||||
|
@ -70,5 +70,5 @@ function SwitchHomekitOutletExport(id: string, label: string, setOn: string, sta
|
||||
|
||||
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]"}`
|
||||
}
|
||||
return `Switch ${id} {mqtt=">[localbroker:${setOn}:command:*:default],<[localbroker:${statusOn}:state:default]"}`
|
||||
}
|
||||
|
55
src/UrlSwitchItem.ts
Normal file
55
src/UrlSwitchItem.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { AItem, HasStateAndFeedbackTopic } from './AItem'
|
||||
import { SwitchExport, ExportType } from './Export'
|
||||
|
||||
|
||||
export class UrlSwitchItem extends AItem implements HasStateAndFeedbackTopic {
|
||||
private offUrl: string
|
||||
private onUrl: string
|
||||
private oldState: string|undefined
|
||||
private state: string
|
||||
private actionTopic: string
|
||||
private stateFeedbackTopic: string
|
||||
private stateTopic: string
|
||||
private type: string
|
||||
|
||||
getStateTopic() : string {
|
||||
return this.stateTopic
|
||||
}
|
||||
|
||||
getStateFeedbackTopic() : string {
|
||||
return this.stateFeedbackTopic
|
||||
}
|
||||
|
||||
constructor(floor: string, room: string, item: string, label: string, onUrl: string, offUrl: string, type: string = 'bulb') {
|
||||
super(floor, room, item, label)
|
||||
this.stateTopic = `${this.topicFirstPart}/state`
|
||||
this.subscribeTopics = [this.stateTopic]
|
||||
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`
|
||||
this.actionTopic = 'IoT/Mqtt433Gateway/Message'
|
||||
this.state = 'OFF'
|
||||
this.oldState = undefined
|
||||
this.onUrl = onUrl
|
||||
this.offUrl = offUrl
|
||||
this.type = type
|
||||
}
|
||||
|
||||
exportItem() : ExportType|null {
|
||||
return SwitchExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type)
|
||||
}
|
||||
|
||||
processMessage(topic: string, payload: string) {
|
||||
this.state = payload;
|
||||
mqttHandler.send(this.stateFeedbackTopic, this.state);
|
||||
if (this.state != this.oldState) {
|
||||
if (this.state == 'ON') {
|
||||
mqttHandler.send(this.actionTopic, this.onCode);
|
||||
} else {
|
||||
mqttHandler.send(this.actionTopic, this.offCode);
|
||||
}
|
||||
this.oldState = this.state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ 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')
|
||||
let matthiasStandLights = new M433SwitchItem('1st', 'Matthias', 'StandLight', 'Stehlampen Matthias', '7 24 1', '6 24 1')
|
||||
matthiasStandLights.start()
|
||||
allLabeledItems.push(matthiasStandLights)
|
||||
|
||||
|
Reference in New Issue
Block a user