introduce interfaces for state/feedback topics

This commit is contained in:
Wolfgang Hottgenroth
2018-01-11 13:52:09 +01:00
parent c7834fefb1
commit 28eec19e53
7 changed files with 92 additions and 54 deletions

View File

@ -4,6 +4,12 @@ const MqttDispatcher_1 = require("./MqttDispatcher");
const AHomematicItem_1 = require("./AHomematicItem"); const AHomematicItem_1 = require("./AHomematicItem");
const Export_1 = require("./Export"); const Export_1 = require("./Export");
class HomematicSwitchItem extends AHomematicItem_1.AHomematicItem { class HomematicSwitchItem extends AHomematicItem_1.AHomematicItem {
getStateTopic() {
return this.stateTopic;
}
getStateFeedbackTopic() {
return this.stateFeedbackTopic;
}
constructor(floor, room, item, label, hmId, type = 'bulb') { constructor(floor, room, item, label, hmId, type = 'bulb') {
super(floor, room, item, label, hmId); super(floor, room, item, label, hmId);
this.stateTopic = `${this.topicFirstPart}/state`; this.stateTopic = `${this.topicFirstPart}/state`;

View File

@ -4,6 +4,12 @@ const MqttDispatcher_1 = require("./MqttDispatcher");
const AItem_1 = require("./AItem"); const AItem_1 = require("./AItem");
const Export_1 = require("./Export"); const Export_1 = require("./Export");
class M433SwitchItem extends AItem_1.AItem { class M433SwitchItem extends AItem_1.AItem {
getStateTopic() {
return this.stateTopic;
}
getStateFeedbackTopic() {
return this.stateFeedbackTopic;
}
constructor(floor, room, item, label, onCode, offCode, type = 'bulb') { constructor(floor, room, item, label, onCode, offCode, type = 'bulb') {
super(floor, room, item, label); super(floor, room, item, label);
this.stateTopic = `${this.topicFirstPart}/state`; this.stateTopic = `${this.topicFirstPart}/state`;

50
dist/main.js vendored
View File

@ -102,37 +102,37 @@ bedRoomWindowLight.start();
allLabeledItems.push(bedRoomWindowLight); allLabeledItems.push(bedRoomWindowLight);
// --------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------
let morningLightForwarder = new Forwarder_1.Forwarder('Gnd', 'Hallway', 'MorningLight', 'state', 'MorningLight', [ let morningLightForwarder = new Forwarder_1.Forwarder('Gnd', 'Hallway', 'MorningLight', 'state', 'MorningLight', [
kitchenWindowLight.stateTopic, kitchenWindowLight.getStateTopic(),
kitchenCeilingLight.stateTopic, kitchenCeilingLight.getStateTopic(),
hallwayDeskLight.stateTopic, hallwayDeskLight.getStateTopic(),
hallwayStandLight.stateTopic, hallwayStandLight.getStateTopic(),
hallwayWardrobeLight.stateTopic hallwayWardrobeLight.getStateTopic()
]); ]);
morningLightForwarder.start(); morningLightForwarder.start();
let dayLightForwarder = new Forwarder_1.Forwarder('Gnd', 'Hallway', 'DayLight', 'state', 'DayLight', [ let dayLightForwarder = new Forwarder_1.Forwarder('Gnd', 'Hallway', 'DayLight', 'state', 'DayLight', [
kitchenWindowLight.stateTopic, kitchenWindowLight.getStateTopic(),
kitchenCeilingLight.stateTopic, kitchenCeilingLight.getStateTopic(),
hallwayDeskLight.stateTopic, hallwayDeskLight.getStateTopic(),
hallwayStandLight.stateTopic, hallwayStandLight.getStateTopic(),
hallwayWardrobeLight.stateTopic, hallwayWardrobeLight.getStateTopic(),
diningRoomSmallLight.stateTopic, diningRoomSmallLight.getStateTopic(),
diningRoomStandLight.stateTopic, diningRoomStandLight.getStateTopic(),
diningRoomCupboardLight.stateTopic, diningRoomCupboardLight.getStateTopic(),
livingRoomLargeLight.stateTopic, livingRoomLargeLight.getStateTopic(),
livingRoomSmallLight.stateTopic, livingRoomSmallLight.getStateTopic(),
livingRoomStars.stateTopic, livingRoomStars.getStateTopic(),
livingRoomStandLight.stateTopic livingRoomStandLight.getStateTopic()
]); ]);
dayLightForwarder.start(); dayLightForwarder.start();
let ecoLightForwarder = new Forwarder_1.Forwarder('Gnd', 'Hallway', 'EcoLight', 'state', 'EcoLight', [ let ecoLightForwarder = new Forwarder_1.Forwarder('Gnd', 'Hallway', 'EcoLight', 'state', 'EcoLight', [
kitchenWindowLight.stateTopic, kitchenWindowLight.getStateTopic(),
hallwayDeskLight.stateTopic, hallwayDeskLight.getStateTopic(),
hallwayWardrobeLight.stateTopic, hallwayWardrobeLight.getStateTopic(),
diningRoomSmallLight.stateTopic, diningRoomSmallLight.getStateTopic(),
diningRoomStandLight.stateTopic, diningRoomStandLight.getStateTopic(),
diningRoomCupboardLight.stateTopic, diningRoomCupboardLight.getStateTopic(),
livingRoomStars.stateTopic, livingRoomStars.getStateTopic(),
livingRoomStandLight.stateTopic livingRoomStandLight.getStateTopic()
]); ]);
ecoLightForwarder.start(); ecoLightForwarder.start();
// ---------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------

View File

@ -3,6 +3,15 @@ import { mqttHandler } from './MqttDispatcher'
import { ExportType } from './Export' import { ExportType } from './Export'
export interface HasStateTopic {
getStateTopic() : string
}
export interface HasStateAndFeedbackTopic extends HasStateTopic {
getStateFeedbackTopic() : string
}
export abstract class AItem { export abstract class AItem {
protected topicFirstPart: string protected topicFirstPart: string
protected itemId: string protected itemId: string

View File

@ -2,8 +2,9 @@ import * as logger from './log'
import { mqttHandler } from './MqttDispatcher' import { mqttHandler } from './MqttDispatcher'
import { AHomematicItem } from './AHomematicItem' import { AHomematicItem } from './AHomematicItem'
import { SwitchExport, ExportType } from './Export' import { SwitchExport, ExportType } from './Export'
import { HasStateAndFeedbackTopic } from './AItem';
export class HomematicSwitchItem extends AHomematicItem { export class HomematicSwitchItem extends AHomematicItem implements HasStateAndFeedbackTopic {
private oldState: string|undefined private oldState: string|undefined
private state: string private state: string
private actionTopic: string private actionTopic: string
@ -12,6 +13,14 @@ export class HomematicSwitchItem extends AHomematicItem {
private stateTopic: string private stateTopic: string
private type: string private type: string
getStateTopic() : string {
return this.stateTopic
}
getStateFeedbackTopic() : string {
return this.stateFeedbackTopic
}
constructor(floor: string, room: string, item: string, label: string, hmId: number, type: string = 'bulb') { constructor(floor: string, room: string, item: string, label: string, hmId: number, type: string = 'bulb') {
super(floor, room, item, label, hmId) super(floor, room, item, label, hmId)
this.stateTopic = `${this.topicFirstPart}/state` this.stateTopic = `${this.topicFirstPart}/state`

View File

@ -1,19 +1,27 @@
import * as logger from './log' import * as logger from './log'
import { mqttHandler } from './MqttDispatcher' import { mqttHandler } from './MqttDispatcher'
import { AItem } from './AItem' import { AItem, HasStateAndFeedbackTopic } from './AItem'
import { SwitchExport, ExportType } from './Export' import { SwitchExport, ExportType } from './Export'
export class M433SwitchItem extends AItem { export class M433SwitchItem extends AItem implements HasStateAndFeedbackTopic {
private offCode: string private offCode: string
private onCode: string private onCode: string
private oldState: string|undefined private oldState: string|undefined
private state: string private state: string
private actionTopic: string private actionTopic: string
private stateFeedbackTopic: string private stateFeedbackTopic: string
public stateTopic: string private stateTopic: string
private type: string private type: string
getStateTopic() : string {
return this.stateTopic
}
getStateFeedbackTopic() : string {
return this.stateFeedbackTopic
}
constructor(floor: string, room: string, item: string, label: string, onCode: string, offCode: string, type: string = 'bulb') { constructor(floor: string, room: string, item: string, label: string, onCode: string, offCode: string, type: string = 'bulb') {
super(floor, room, item, label) super(floor, room, item, label)
this.stateTopic = `${this.topicFirstPart}/state` this.stateTopic = `${this.topicFirstPart}/state`

View File

@ -134,39 +134,39 @@ allLabeledItems.push(bedRoomWindowLight)
// --------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------
let morningLightForwarder = new Forwarder('Gnd', 'Hallway', 'MorningLight', 'state', 'MorningLight', [ let morningLightForwarder = new Forwarder('Gnd', 'Hallway', 'MorningLight', 'state', 'MorningLight', [
kitchenWindowLight.stateTopic, kitchenWindowLight.getStateTopic(),
kitchenCeilingLight.stateTopic, kitchenCeilingLight.getStateTopic(),
hallwayDeskLight.stateTopic, hallwayDeskLight.getStateTopic(),
hallwayStandLight.stateTopic, hallwayStandLight.getStateTopic(),
hallwayWardrobeLight.stateTopic hallwayWardrobeLight.getStateTopic()
]) ])
morningLightForwarder.start() morningLightForwarder.start()
let dayLightForwarder = new Forwarder('Gnd', 'Hallway', 'DayLight', 'state', 'DayLight', [ let dayLightForwarder = new Forwarder('Gnd', 'Hallway', 'DayLight', 'state', 'DayLight', [
kitchenWindowLight.stateTopic, kitchenWindowLight.getStateTopic(),
kitchenCeilingLight.stateTopic, kitchenCeilingLight.getStateTopic(),
hallwayDeskLight.stateTopic, hallwayDeskLight.getStateTopic(),
hallwayStandLight.stateTopic, hallwayStandLight.getStateTopic(),
hallwayWardrobeLight.stateTopic, hallwayWardrobeLight.getStateTopic(),
diningRoomSmallLight.stateTopic, diningRoomSmallLight.getStateTopic(),
diningRoomStandLight.stateTopic, diningRoomStandLight.getStateTopic(),
diningRoomCupboardLight.stateTopic, diningRoomCupboardLight.getStateTopic(),
livingRoomLargeLight.stateTopic, livingRoomLargeLight.getStateTopic(),
livingRoomSmallLight.stateTopic, livingRoomSmallLight.getStateTopic(),
livingRoomStars.stateTopic, livingRoomStars.getStateTopic(),
livingRoomStandLight.stateTopic livingRoomStandLight.getStateTopic()
]) ])
dayLightForwarder.start() dayLightForwarder.start()
let ecoLightForwarder = new Forwarder('Gnd', 'Hallway', 'EcoLight', 'state', 'EcoLight', [ let ecoLightForwarder = new Forwarder('Gnd', 'Hallway', 'EcoLight', 'state', 'EcoLight', [
kitchenWindowLight.stateTopic, kitchenWindowLight.getStateTopic(),
hallwayDeskLight.stateTopic, hallwayDeskLight.getStateTopic(),
hallwayWardrobeLight.stateTopic, hallwayWardrobeLight.getStateTopic(),
diningRoomSmallLight.stateTopic, diningRoomSmallLight.getStateTopic(),
diningRoomStandLight.stateTopic, diningRoomStandLight.getStateTopic(),
diningRoomCupboardLight.stateTopic, diningRoomCupboardLight.getStateTopic(),
livingRoomStars.stateTopic, livingRoomStars.getStateTopic(),
livingRoomStandLight.stateTopic livingRoomStandLight.getStateTopic()
]) ])
ecoLightForwarder.start() ecoLightForwarder.start()
// ---------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------