Cron implemented
This commit is contained in:
23
dist/Cron.js
vendored
Normal file
23
dist/Cron.js
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const logger = require("./log");
|
||||
const MqttDispatcher_1 = require("./MqttDispatcher");
|
||||
const cron = require("cron");
|
||||
class Cron {
|
||||
constructor(name, target, crontab) {
|
||||
this.name = name;
|
||||
this.targetTopic = target.getInTopic();
|
||||
this.crontab = crontab;
|
||||
}
|
||||
start() {
|
||||
this.crontab.forEach((cronEntry) => {
|
||||
logger.info(`Starting cronjob for: ${this.targetTopic}, ${cronEntry.output} at ${cronEntry.cronTime}`);
|
||||
cronEntry.cronJob = new cron.CronJob(cronEntry.cronTime, () => {
|
||||
logger.info(`Firing ${this.targetTopic}, ${cronEntry.output}`);
|
||||
MqttDispatcher_1.mqttHandler.send(this.targetTopic, cronEntry.output);
|
||||
}, undefined, true, 'Europe/Berlin');
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.Cron = Cron;
|
||||
//# sourceMappingURL=Cron.js.map
|
3
dist/MaxThermostat.js
vendored
3
dist/MaxThermostat.js
vendored
@ -6,6 +6,9 @@ const AHomematicItem_1 = require("./AHomematicItem");
|
||||
const WINDOW_OPEN_TEMPERATURE = 4.5;
|
||||
class MaxThermostat extends AHomematicItem_1.AHomematicItem {
|
||||
// Thermostat: homegear/instance1/set/3/1/SET_TEMPERATURE
|
||||
getInTopic() {
|
||||
return this.temperatureTopic;
|
||||
}
|
||||
constructor(floor, room, item, label, hmId, windowContacts) {
|
||||
super(floor, room, item, label, hmId);
|
||||
this.temperatureTopic = `${this.topicFirstPart}/temperature`;
|
||||
|
7
dist/main.js
vendored
7
dist/main.js
vendored
@ -15,6 +15,7 @@ const Scene_1 = require("./Scene");
|
||||
const MaxEcoSwitch_1 = require("./MaxEcoSwitch");
|
||||
const MaxThermostat_1 = require("./MaxThermostat");
|
||||
const MaxWindowContact_1 = require("./MaxWindowContact");
|
||||
const Cron_1 = require("./Cron");
|
||||
logger.info("Dispatcher starting");
|
||||
let allLabeledItems = new Array();
|
||||
// Anna -----------------------------------------------------------------------------------------------------
|
||||
@ -162,6 +163,12 @@ let windowContact2 = new MaxWindowContact_1.MaxWindowContact('Gnd', 'Bathroom',
|
||||
windowContact2.start();
|
||||
let thermostat1 = new MaxThermostat_1.MaxThermostat('Gnd', 'Bathroom', 'Thermostat', 'Thermostat Bad unten', 3, [windowContact1, windowContact2]);
|
||||
thermostat1.start();
|
||||
let thermostat1Cron = new Cron_1.Cron('Thermostat1Cron', thermostat1, [
|
||||
{ cronTime: '00 47 17 * * *', output: '5.0' },
|
||||
{ cronTime: '00 48 17 * * *', output: '20.0' },
|
||||
{ cronTime: '00 49 17 * * *', output: '25.0' }
|
||||
]);
|
||||
thermostat1Cron.start();
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// Homekit export
|
||||
let homekitObject = {};
|
||||
|
22
package-lock.json
generated
22
package-lock.json
generated
@ -19,6 +19,12 @@
|
||||
"integrity": "sha512-lLN/Rtud+SONdclROGc8CnZeZ/ujQ69U4otFMtoCfCdLfs2x2R2lJFSy583uI9dnnsd6I9Pdy/Mw3efqxO/2bg==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/cron": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/cron/-/cron-1.2.1.tgz",
|
||||
"integrity": "sha1-lcHkMtYQbKNMkvB0Nji8eGwHP6o=",
|
||||
"dev": true
|
||||
},
|
||||
"@types/moment": {
|
||||
"version": "2.13.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/moment/-/moment-2.13.0.tgz",
|
||||
@ -166,6 +172,14 @@
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
||||
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
|
||||
},
|
||||
"cron": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/cron/-/cron-1.3.0.tgz",
|
||||
"integrity": "sha512-K/SF7JlgMmNjcThWxkKvsHhey2EDB4CeOEWJ9aXWj3fbQJppsvTPIeyLdHfNq5IbbsMUUjRW1nr5dSO95f2E4w==",
|
||||
"requires": {
|
||||
"moment-timezone": "0.5.14"
|
||||
}
|
||||
},
|
||||
"duplexify": {
|
||||
"version": "3.5.1",
|
||||
"resolved": "https://registry.npmjs.org/duplexify/-/duplexify-3.5.1.tgz",
|
||||
@ -382,6 +396,14 @@
|
||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.20.1.tgz",
|
||||
"integrity": "sha1-1usaRsvMFKKy+UNBEsH/iQfzE/0="
|
||||
},
|
||||
"moment-timezone": {
|
||||
"version": "0.5.14",
|
||||
"resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.14.tgz",
|
||||
"integrity": "sha1-TrOP+VOLgBCLpGekWPPtQmjM/LE=",
|
||||
"requires": {
|
||||
"moment": "2.20.1"
|
||||
}
|
||||
},
|
||||
"mqtt": {
|
||||
"version": "2.15.0",
|
||||
"resolved": "https://registry.npmjs.org/mqtt/-/mqtt-2.15.0.tgz",
|
||||
|
@ -21,6 +21,7 @@
|
||||
"dependencies": {
|
||||
"chalk": "^2.3.0",
|
||||
"command-line-args": "^4.0.7",
|
||||
"cron": "^1.3.0",
|
||||
"moment": "^2.20.1",
|
||||
"mqtt": "^2.15.0",
|
||||
"nodemailer": "^4.4.1",
|
||||
@ -29,6 +30,7 @@
|
||||
"devDependencies": {
|
||||
"@types/chalk": "^2.2.0",
|
||||
"@types/command-line-args": "^4.0.2",
|
||||
"@types/cron": "^1.2.1",
|
||||
"@types/moment": "^2.13.0",
|
||||
"@types/mqtt": "^2.5.0",
|
||||
"@types/node": "^8.5.8",
|
||||
|
@ -12,6 +12,10 @@ export interface HasStateAndFeedbackTopic extends HasStateTopic {
|
||||
getStateFeedbackTopic() : string
|
||||
}
|
||||
|
||||
export interface HasInTopic {
|
||||
getInTopic() : string
|
||||
}
|
||||
|
||||
export abstract class AItem {
|
||||
protected topicFirstPart: string
|
||||
protected itemId: string
|
||||
|
33
src/Cron.ts
Normal file
33
src/Cron.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { HasInTopic } from './AItem'
|
||||
import * as cron from 'cron'
|
||||
|
||||
|
||||
type CronEntry = {
|
||||
output: string
|
||||
cronTime: string
|
||||
cronJob?: cron.CronJob
|
||||
}
|
||||
|
||||
export class Cron {
|
||||
private crontab: CronEntry[]
|
||||
private targetTopic: string
|
||||
private name: string
|
||||
|
||||
constructor(name: string, target: HasInTopic, crontab: CronEntry[]) {
|
||||
this.name = name
|
||||
this.targetTopic = target.getInTopic()
|
||||
this.crontab = crontab
|
||||
}
|
||||
|
||||
start() : void {
|
||||
this.crontab.forEach((cronEntry) => {
|
||||
logger.info(`Starting cronjob for: ${this.targetTopic}, ${cronEntry.output} at ${cronEntry.cronTime}`)
|
||||
cronEntry.cronJob = new cron.CronJob(cronEntry.cronTime, () => {
|
||||
logger.info(`Firing ${this.targetTopic}, ${cronEntry.output}`)
|
||||
mqttHandler.send(this.targetTopic, cronEntry.output)
|
||||
}, undefined, true, 'Europe/Berlin')
|
||||
})
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { HasInTopic } from './AItem'
|
||||
import { AHomematicItem } from './AHomematicItem'
|
||||
import { MaxWindowContact } from './MaxWindowContact';
|
||||
// import { SwitchExport, ExportType } from './Export'
|
||||
@ -12,7 +13,7 @@ type WindowContactHolder = {
|
||||
state : string
|
||||
}
|
||||
|
||||
export class MaxThermostat extends AHomematicItem {
|
||||
export class MaxThermostat extends AHomematicItem implements HasInTopic {
|
||||
private actionTopic: string
|
||||
private deviceFeedbackTopic: string
|
||||
private temperatureFeedbackTopic: string
|
||||
@ -22,6 +23,10 @@ export class MaxThermostat extends AHomematicItem {
|
||||
private windowOpen: boolean
|
||||
// Thermostat: homegear/instance1/set/3/1/SET_TEMPERATURE
|
||||
|
||||
getInTopic() : string {
|
||||
return this.temperatureTopic
|
||||
}
|
||||
|
||||
constructor(floor: string, room: string, item: string, label: string, hmId: number, windowContacts: MaxWindowContact[]) {
|
||||
super(floor, room, item, label, hmId)
|
||||
this.temperatureTopic = `${this.topicFirstPart}/temperature`
|
||||
|
@ -17,7 +17,7 @@ import { LightScene } from './Scene'
|
||||
import { MaxEcoSwitch } from './MaxEcoSwitch'
|
||||
import { MaxThermostat } from './MaxThermostat'
|
||||
import { MaxWindowContact } from './MaxWindowContact'
|
||||
|
||||
import { Cron } from './Cron'
|
||||
|
||||
logger.info("Dispatcher starting")
|
||||
|
||||
@ -221,6 +221,12 @@ windowContact2.start()
|
||||
let thermostat1 = new MaxThermostat('Gnd', 'Bathroom', 'Thermostat', 'Thermostat Bad unten', 3, [windowContact1, windowContact2])
|
||||
thermostat1.start()
|
||||
|
||||
let thermostat1Cron = new Cron('Thermostat1Cron', thermostat1, [
|
||||
{cronTime: '00 47 17 * * *', output: '5.0'},
|
||||
{cronTime: '00 48 17 * * *', output: '20.0'},
|
||||
{cronTime: '00 49 17 * * *', output: '25.0'}
|
||||
])
|
||||
thermostat1Cron.start()
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// Homekit export
|
||||
|
Reference in New Issue
Block a user