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 Export_1 = require("./Export");
class HomematicSwitchItem extends AHomematicItem_1.AHomematicItem {
getStateTopic() {
return this.stateTopic;
}
getStateFeedbackTopic() {
return this.stateFeedbackTopic;
}
constructor(floor, room, item, label, hmId, type = 'bulb') {
super(floor, room, item, label, hmId);
this.stateTopic = `${this.topicFirstPart}/state`;

View File

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

50
dist/main.js vendored
View File

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

View File

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

View File

@ -2,8 +2,9 @@ import * as logger from './log'
import { mqttHandler } from './MqttDispatcher'
import { AHomematicItem } from './AHomematicItem'
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 state: string
private actionTopic: string
@ -12,6 +13,14 @@ export class HomematicSwitchItem extends AHomematicItem {
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, hmId: number, type: string = 'bulb') {
super(floor, room, item, label, hmId)
this.stateTopic = `${this.topicFirstPart}/state`

View File

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

View File

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