-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
executable file
·122 lines (100 loc) · 4.2 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// DOMUSTO
import config from '../../config';
import DomustoPlugin from '../../domusto/DomustoPlugin';
// INTERFACES
import { Domusto } from '../../domusto/DomustoTypes';
import DomustoP1Api from './api';
// PLUGIN SPECIFIC
import * as P1Reader from 'p1-reader';
/**
* P1 plugin for DOMUSTO
* @author Bas van Dijk
* @version 0.0.1
*
* @class DomustoP1
* @extends {DomustoPlugin}
*/
class DomustoP1 extends DomustoPlugin {
/**
* Creates an instance of DomustoP1.
* @param {any} Plugin configuration as defined in the config.js file
* @memberof DomustoP1
*/
constructor(pluginConfiguration: Domusto.PluginConfiguration) {
super({
plugin: 'P1 smartmeter for Landys Gyr E350',
author: 'Bas van Dijk',
category: Domusto.PluginCategories.utility,
version: '0.0.1',
website: 'http://domusto.com'
});
this.pluginConfiguration = pluginConfiguration;
const isConfigurationValid = this.validateConfigurationAttributes(pluginConfiguration.settings, [
{
attribute: 'port',
type: 'string'
},
{
attribute: 'wireless',
type: 'boolean'
}
]);
if (isConfigurationValid) {
if (!pluginConfiguration.settings.wireless) {
try {
let p1Reader = new P1Reader({
serialPort: pluginConfiguration.settings.port,
emulator: pluginConfiguration.dummyData,
});
this.hardwareInstance = p1Reader;
this.hardwareInstance.on('reading', this.updatePowerData.bind(this));
this.console.header(`${pluginConfiguration.id} plugin ready for sending / receiving data`);
} catch (error) {
this.console.log('Initialisation of P1 plugin failed', error);
}
}
DomustoP1Api.setPluginInstance(this);
}
}
/**
*
* Trigged when the P1 device broadcasts new data
* Explanation of the Dutch Smart Meter Requirements (DSRM 4.2.2) standard data layout found on:
* http://www.netbeheernederland.nl/_upload/Files/Slimme_meter_15_32ffe3cc38.pdf
*
* @param {any} data Data broadcasted by the device
* @memberof DomustoP1
*/
updatePowerData(data) {
// this.console.prettyJson(data);
this.broadcastSignal('received', {
tariff1: {
value: data.electricity.received.tariff1.reading, // Amount of electricity received for tariff1 (LOW)
unit: data.electricity.received.tariff1.unit // Unit of the electricity reading e.g. kWh
},
tariff2: {
value: data.electricity.received.tariff2.reading, // Amount of electricity received for tariff2 (NORMAL / HIGH)
unit: data.electricity.received.tariff2.unit // Unit of the electricity reading e.g. kWh
},
actual: {
value: data.electricity.received.actual.reading, // Amount of electricity currently consumed
unit: data.electricity.received.actual.unit // Unit of the electricity reading e.g. kWh
}
});
this.broadcastSignal('delivered', {
tariff1: {
value: data.electricity.delivered.tariff1.reading, // Amount of electricity delivered for tariff1 (LOW)
unit: data.electricity.delivered.tariff1.unit // Unit of the electricity reading e.g. kWh
},
tariff2: {
value: data.electricity.delivered.tariff2.reading, // Amount of electricity delivered for tariff2 (NORMAL / HIGH)
unit: data.electricity.delivered.tariff2.unit // Unit of the electricity reading e.g. kWh
},
actual: {
value: data.electricity.delivered.actual.reading, // Amount of electricity currently consumed
unit: data.electricity.delivered.actual.unit // Unit of the electricity reading e.g. kWh
}
});
}
}
export default DomustoP1;