some changes, not yet done with WindowContact, too cold in Q-West to complete

This commit is contained in:
Wolfgang Hottgenroth
2018-01-15 16:20:59 +01:00
parent 677f9c807d
commit f88cf5ee0d
4 changed files with 104 additions and 11 deletions

60
src/MaxThermostat.ts Normal file
View File

@ -0,0 +1,60 @@
import * as logger from './log'
import { mqttHandler } from './MqttDispatcher'
import { AHomematicItem } from './AHomematicItem'
import { MaxWindowContact } from './MaxWindowContact';
// import { SwitchExport, ExportType } from './Export'
const WINDOW_OPEN_TEMPERATURE = 4.5
export class MaxThermostat extends AHomematicItem {
private actionTopic: string
private deviceFeedbackTopic: string
private temperatureFeedbackTopic: string
private temperatureTopic: string
private temperature: number
private windowContacts: MaxWindowContact[]
private windowContactTopics: string[]
private windowOpen: boolean
// Thermostat: homegear/instance1/set/3/1/SET_TEMPERATURE
constructor(floor: string, room: string, item: string, label: string, hmId: number, windowContacts: MaxWindowContact[]) {
super(floor, room, item, label, hmId)
this.temperatureTopic = `${this.topicFirstPart}/temperature`
this.temperatureFeedbackTopic = `${this.topicFirstPart}/temperature/feedback`
this.deviceFeedbackTopic = `${this.deviceTopicPre}/1/SET_TEMPERATURE`
this.actionTopic = `${this.actionTopicPre}/1/SET_TEMPERATURE`
this.subscribeTopics = [
this.temperatureTopic,
this.deviceFeedbackTopic
]
this.windowContacts = windowContacts
this.windowOpen = false
this.windowContactTopics = []
this.windowContacts.forEach((windowContact) => {
this.subscribeTopics.push(windowContact.getStateFeedbackTopic())
this.windowContactTopics.push(windowContact.getStateFeedbackTopic())
})
}
processMessage(topic: string, payload: string) : void {
if (topic == this.temperatureTopic) {
this.temperature = parseFloat(payload)
mqttHandler.send(this.temperatureFeedbackTopic, `${this.temperature}`)
mqttHandler.send(this.actionTopic, `${this.temperature}`)
} else if (topic == this.deviceFeedbackTopic) {
this.temperature = parseFloat(payload)
mqttHandler.send(this.temperatureFeedbackTopic, `${this.temperature}`)
} else if (this.windowContactTopics.indexOf(topic) >= 0) {
if (payload == 'CLOSED') {
} else {
}
}
}
}

32
src/MaxWindowContact.ts Normal file
View File

@ -0,0 +1,32 @@
import * as logger from './log'
import { mqttHandler } from './MqttDispatcher'
import { AHomematicItem } from './AHomematicItem'
// import { SwitchExport, ExportType } from './Export'
export class MaxWindowContact extends AHomematicItem {
private deviceFeedbackTopic: string
private stateFeedbackTopic: string
private stateTopic: string
private state: string
getStateFeedbackTopic(): string {
return this.stateFeedbackTopic
}
constructor(floor: string, room: string, item: string, label: string, hmId: number) {
super(floor, room, item, label, hmId)
this.stateTopic = `${this.topicFirstPart}/state`
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`
this.deviceFeedbackTopic = `${this.deviceTopicPre}/1/STATE`
this.subscribeTopics = [
this.stateTopic,
this.deviceFeedbackTopic
]
}
processMessage(topic: string, payload: string) : void {
this.state = payload
mqttHandler.send(this.stateFeedbackTopic, this.state)
}
}

View File

@ -90,17 +90,17 @@ class MqttHandler {
}
send(topic: string, payload: string, internalFirst: boolean = false) : void {
let sent = false
if (internalFirst) {
logger.info(`Try internal sending: ${topic}`)
sent = this.processMessage(topic, payload)
}
if (! sent) {
//let sent = false
//if (internalFirst) {
// logger.info(`Try internal sending: ${topic}`)
// sent = this.processMessage(topic, payload)
//}
//if (! sent) {
logger.info(`External sending required: ${topic}`)
this.mqttClient.publish(topic, payload)
} else {
logger.info(`Internally delivered: ${topic}`)
}
//} else {
// logger.info(`Internally delivered: ${topic}`)
//}
}
}

View File

@ -2,6 +2,7 @@ import * as logger from './log'
import { mqttHandler } from './MqttDispatcher'
import { AItem, HasStateAndFeedbackTopic } from './AItem'
import { SwitchExport, ExportType } from './Export'
import * as http from 'http'
export class UrlSwitchItem extends AItem implements HasStateAndFeedbackTopic {
@ -44,9 +45,9 @@ export class UrlSwitchItem extends AItem implements HasStateAndFeedbackTopic {
mqttHandler.send(this.stateFeedbackTopic, this.state);
if (this.state != this.oldState) {
if (this.state == 'ON') {
mqttHandler.send(this.actionTopic, this.onCode);
http.get(this.onUrl)
} else {
mqttHandler.send(this.actionTopic, this.offCode);
http.get(this.offUrl)
}
this.oldState = this.state;
}