iobroker.tibberlink 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +200 -0
- package/README.md +34 -0
- package/admin/i18n/de/translations.json +6 -0
- package/admin/i18n/en/translations.json +6 -0
- package/admin/i18n/es/translations.json +6 -0
- package/admin/i18n/fr/translations.json +6 -0
- package/admin/i18n/it/translations.json +6 -0
- package/admin/i18n/nl/translations.json +6 -0
- package/admin/i18n/pl/translations.json +6 -0
- package/admin/i18n/pt/translations.json +6 -0
- package/admin/i18n/ru/translations.json +6 -0
- package/admin/i18n/uk/translations.json +6 -0
- package/admin/i18n/zh-cn/translations.json +6 -0
- package/admin/jsonConfig.json +152 -0
- package/admin/tibberlink.png +0 -0
- package/build/lib/tibberAPICaller.js +126 -0
- package/build/lib/tibberAPICaller.js.map +1 -0
- package/build/lib/tibberHelper.js +88 -0
- package/build/lib/tibberHelper.js.map +1 -0
- package/build/lib/tibberPulse.js +109 -0
- package/build/lib/tibberPulse.js.map +1 -0
- package/build/lib/tools.js +99 -0
- package/build/lib/tools.js.map +1 -0
- package/build/main.js +293 -0
- package/build/main.js.map +1 -0
- package/io-package.json +110 -0
- package/package.json +85 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TibberAPICaller = void 0;
|
|
4
|
+
const tibber_api_1 = require("tibber-api");
|
|
5
|
+
const tibberHelper_1 = require("./tibberHelper");
|
|
6
|
+
class TibberAPICaller extends tibberHelper_1.TibberHelper {
|
|
7
|
+
constructor(tibberConfig, adapter) {
|
|
8
|
+
super(adapter);
|
|
9
|
+
this.tibberConfig = tibberConfig;
|
|
10
|
+
this.tibberQuery = new tibber_api_1.TibberQuery(this.tibberConfig);
|
|
11
|
+
this.currentHomeId = "";
|
|
12
|
+
}
|
|
13
|
+
async updateHomesFromAPI() {
|
|
14
|
+
const currentHomes = await this.tibberQuery.getHomes();
|
|
15
|
+
this.adapter.log.debug("Get homes from tibber api: " + JSON.stringify(currentHomes));
|
|
16
|
+
const homeIdList = [];
|
|
17
|
+
for (const homeIndex in currentHomes) {
|
|
18
|
+
const currentHome = currentHomes[homeIndex];
|
|
19
|
+
this.currentHomeId = currentHome.id;
|
|
20
|
+
homeIdList.push(this.currentHomeId);
|
|
21
|
+
// Set HomeId in tibberConfig for further API Calls
|
|
22
|
+
this.tibberConfig.homeId = this.currentHomeId;
|
|
23
|
+
// Home GENERAL
|
|
24
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, "General", "Id"), currentHome.id, "ID of your home");
|
|
25
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, "General", "Timezone"), currentHome.timeZone, "The time zone the home resides in");
|
|
26
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, "General", "NameInApp"), currentHome.appNickname, "The nickname given to the home by the user");
|
|
27
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, "General", "AvatarInApp"), currentHome.appAvatar, "The chosen avatar for the home");
|
|
28
|
+
// Values: APARTMENT, ROWHOUSE, FLOORHOUSE1, FLOORHOUSE2, FLOORHOUSE3, COTTAGE, CASTLE
|
|
29
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, "General", "Type"), currentHome.type, "The type of home.");
|
|
30
|
+
// Values: APARTMENT, ROWHOUSE, HOUSE, COTTAGE
|
|
31
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, "General", "PrimaryHeatingSource"), currentHome.primaryHeatingSource, "The primary form of heating in the household"); // Values: AIR2AIR_HEATPUMP, ELECTRICITY, GROUND, DISTRICT_HEATING, ELECTRIC_BOILER, AIR2WATER_HEATPUMP, OTHER
|
|
32
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.currentHomeId, "General", "Size"), currentHome.size, "The size of the home in square meters");
|
|
33
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.currentHomeId, "General", "NumberOfResidents"), currentHome.numberOfResidents, "The number of people living in the home");
|
|
34
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.currentHomeId, "General", "MainFuseSize"), currentHome.mainFuseSize, "The main fuse size");
|
|
35
|
+
this.checkAndSetValueBoolean(this.getStatePrefix(this.currentHomeId, "General", "HasVentilationSystem"), currentHome.hasVentilationSystem, "Whether the home has a ventilation system");
|
|
36
|
+
this.fetchAddress("Address", currentHome.address);
|
|
37
|
+
this.fetchLegalEntity("Owner", currentHome.owner);
|
|
38
|
+
// TO DO: currentHome.currentSubscription
|
|
39
|
+
// TO DO: currentHome.subscriptions
|
|
40
|
+
// TO DO: currentHome.consumption
|
|
41
|
+
// TO DO: currentHome.production
|
|
42
|
+
this.checkAndSetValueBoolean(this.getStatePrefix(this.currentHomeId, "Features", "RealTimeConsumptionEnabled"), currentHome.features.realTimeConsumptionEnabled);
|
|
43
|
+
}
|
|
44
|
+
return homeIdList;
|
|
45
|
+
}
|
|
46
|
+
generateErrorMessage(error, context) {
|
|
47
|
+
let errorMessages = "";
|
|
48
|
+
for (const index in error.errors) {
|
|
49
|
+
if (errorMessages) {
|
|
50
|
+
errorMessages += ", ";
|
|
51
|
+
}
|
|
52
|
+
errorMessages += error.errors[index].message;
|
|
53
|
+
}
|
|
54
|
+
return "Fehler (" + error.statusMessage + ") bei Vorgang: " + context + ": " + errorMessages;
|
|
55
|
+
}
|
|
56
|
+
async updateCurrentPrice(homeId) {
|
|
57
|
+
if (homeId) {
|
|
58
|
+
const currentPrice = await this.tibberQuery.getCurrentEnergyPrice(homeId);
|
|
59
|
+
this.adapter.log.debug("Get current price from tibber api: " + JSON.stringify(currentPrice));
|
|
60
|
+
this.currentHomeId = homeId;
|
|
61
|
+
await this.fetchPrice("CurrentPrice", currentPrice);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async updatePricesToday(homeId) {
|
|
65
|
+
const pricesToday = await this.tibberQuery.getTodaysEnergyPrices(homeId);
|
|
66
|
+
this.adapter.log.debug("Get prices today from tibber api: " + JSON.stringify(pricesToday));
|
|
67
|
+
this.currentHomeId = homeId;
|
|
68
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, "PricesToday", "json"), JSON.stringify(pricesToday), "The prices today as json");
|
|
69
|
+
for (const index in pricesToday) {
|
|
70
|
+
const price = pricesToday[index];
|
|
71
|
+
const hour = new Date(price.startsAt).getHours();
|
|
72
|
+
this.fetchPrice("PricesToday." + hour, price);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async updatePricesTomorrow(homeId) {
|
|
76
|
+
const pricesTomorrow = await this.tibberQuery.getTomorrowsEnergyPrices(homeId);
|
|
77
|
+
this.adapter.log.debug("Get prices tomorrow from tibber api: " + JSON.stringify(pricesTomorrow));
|
|
78
|
+
this.currentHomeId = homeId;
|
|
79
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, "PricesTomorrow", "json"), JSON.stringify(pricesTomorrow), "The prices tomorrow as json");
|
|
80
|
+
for (const index in pricesTomorrow) {
|
|
81
|
+
const price = pricesTomorrow[index];
|
|
82
|
+
const hour = new Date(price.startsAt).getHours();
|
|
83
|
+
this.fetchPrice("PricesTomorrow." + hour, price);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
fetchAddress(objectDestination, address) {
|
|
87
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "address1"), address.address1);
|
|
88
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "address2"), address.address2);
|
|
89
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "address3"), address.address3);
|
|
90
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "City"), address.city);
|
|
91
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "PostalCode"), address.postalCode);
|
|
92
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "Country"), address.country);
|
|
93
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "Latitude"), address.latitude);
|
|
94
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "Longitude"), address.longitude);
|
|
95
|
+
}
|
|
96
|
+
fetchPrice(objectDestination, price) {
|
|
97
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.currentHomeId, objectDestination, "total"), price.total, "The total price (energy + taxes)");
|
|
98
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.currentHomeId, objectDestination, "energy"), price.energy, "Spotmarket price");
|
|
99
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.currentHomeId, objectDestination, "tax"), price.tax, "The tax part of the price (guarantee of origin certificate, energy tax (Sweden only) and VAT)");
|
|
100
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "startsAt"), price.startsAt, "Start time of the price");
|
|
101
|
+
//this.checkAndSetValue(this.getStatePrefix(objectDestination, "currency"), price.currency, "The price currency");
|
|
102
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "level"), price.level, "Price level compared to recent price values");
|
|
103
|
+
}
|
|
104
|
+
fetchLegalEntity(objectDestination, legalEntity) {
|
|
105
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "Id"), legalEntity.id);
|
|
106
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "FirstName"), legalEntity.firstName);
|
|
107
|
+
this.checkAndSetValueBoolean(this.getStatePrefix(this.currentHomeId, objectDestination, "IsCompany"), legalEntity.isCompany);
|
|
108
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "Name"), legalEntity.name);
|
|
109
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "MiddleName"), legalEntity.middleName);
|
|
110
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "LastName"), legalEntity.lastName);
|
|
111
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "OrganizationNo"), legalEntity.organizationNo);
|
|
112
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "Language"), legalEntity.language);
|
|
113
|
+
if (legalEntity.contactInfo) {
|
|
114
|
+
this.fetchContactInfo(objectDestination + ".ContactInfo", legalEntity.contactInfo);
|
|
115
|
+
}
|
|
116
|
+
if (legalEntity.address) {
|
|
117
|
+
this.fetchAddress(objectDestination + ".Address", legalEntity.address);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
fetchContactInfo(objectDestination, contactInfo) {
|
|
121
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "Email"), contactInfo.email);
|
|
122
|
+
this.checkAndSetValue(this.getStatePrefix(this.currentHomeId, objectDestination, "Mobile"), contactInfo.mobile);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.TibberAPICaller = TibberAPICaller;
|
|
126
|
+
//# sourceMappingURL=tibberAPICaller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tibberAPICaller.js","sourceRoot":"","sources":["../../src/lib/tibberAPICaller.ts"],"names":[],"mappings":";;;AACA,2CAAkD;AAKlD,iDAA8C;AAE9C,MAAa,eAAgB,SAAQ,2BAAY;IAKhD,YAAY,YAAqB,EAAE,OAA8B;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,WAAW,GAAG,IAAI,wBAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACtD,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,kBAAkB;QACvB,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;QACvD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,6BAA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|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TibberHelper = void 0;
|
|
4
|
+
class TibberHelper {
|
|
5
|
+
constructor(adapter) {
|
|
6
|
+
this.adapter = adapter;
|
|
7
|
+
}
|
|
8
|
+
getStatePrefix(homeId, space, name) {
|
|
9
|
+
const statePrefix = {
|
|
10
|
+
key: name,
|
|
11
|
+
value: "Homes." + homeId + "." + space + "." + name,
|
|
12
|
+
};
|
|
13
|
+
return statePrefix;
|
|
14
|
+
}
|
|
15
|
+
async checkAndSetValue(stateName, value, description) {
|
|
16
|
+
if (value != undefined) {
|
|
17
|
+
if (value.trim().length > 0) {
|
|
18
|
+
await this.adapter.setObjectNotExistsAsync(stateName.value, {
|
|
19
|
+
type: "state",
|
|
20
|
+
common: {
|
|
21
|
+
name: stateName.key,
|
|
22
|
+
type: "string",
|
|
23
|
+
role: "String",
|
|
24
|
+
desc: description,
|
|
25
|
+
read: true,
|
|
26
|
+
write: false,
|
|
27
|
+
},
|
|
28
|
+
native: {},
|
|
29
|
+
});
|
|
30
|
+
await this.adapter.setStateAsync(stateName.value, value, true);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async checkAndSetValueNumber(stateName, value, description) {
|
|
35
|
+
if (value != undefined) {
|
|
36
|
+
await this.adapter.setObjectNotExistsAsync(stateName.value, {
|
|
37
|
+
type: "state",
|
|
38
|
+
common: {
|
|
39
|
+
name: stateName.key,
|
|
40
|
+
type: "number",
|
|
41
|
+
role: "Number",
|
|
42
|
+
desc: description,
|
|
43
|
+
read: true,
|
|
44
|
+
write: false,
|
|
45
|
+
},
|
|
46
|
+
native: {},
|
|
47
|
+
});
|
|
48
|
+
await this.adapter.setStateAsync(stateName.value, value, true);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async checkAndSetValueNumberUnit(stateName, value, unit, description) {
|
|
52
|
+
if (value != undefined) {
|
|
53
|
+
await this.adapter.setObjectNotExistsAsync(stateName.value, {
|
|
54
|
+
type: "state",
|
|
55
|
+
common: {
|
|
56
|
+
name: stateName.key,
|
|
57
|
+
type: "number",
|
|
58
|
+
role: "Number",
|
|
59
|
+
desc: description,
|
|
60
|
+
unit: unit,
|
|
61
|
+
read: true,
|
|
62
|
+
write: false,
|
|
63
|
+
},
|
|
64
|
+
native: {},
|
|
65
|
+
});
|
|
66
|
+
await this.adapter.setStateAsync(stateName.value, value, true);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async checkAndSetValueBoolean(stateName, value, description) {
|
|
70
|
+
if (value) {
|
|
71
|
+
await this.adapter.setObjectNotExistsAsync(stateName.value, {
|
|
72
|
+
type: "state",
|
|
73
|
+
common: {
|
|
74
|
+
name: stateName.key,
|
|
75
|
+
type: "boolean",
|
|
76
|
+
role: "Boolean",
|
|
77
|
+
desc: description,
|
|
78
|
+
read: true,
|
|
79
|
+
write: false,
|
|
80
|
+
},
|
|
81
|
+
native: {},
|
|
82
|
+
});
|
|
83
|
+
await this.adapter.setStateAsync(stateName.value, value, true);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.TibberHelper = TibberHelper;
|
|
88
|
+
//# sourceMappingURL=tibberHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tibberHelper.js","sourceRoot":"","sources":["../../src/lib/tibberHelper.ts"],"names":[],"mappings":";;;AAEA,MAAa,YAAY;IAGxB,YAAY,OAA8B;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAES,cAAc,CAAC,MAAc,EAAE,KAAa,EAAE,IAAY;QACnE,MAAM,WAAW,GAAG;YACnB,GAAG,EAAE,IAAI;YACT,KAAK,EAAE,QAAQ,GAAG,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,GAAG,GAAG,IAAI;SACnD,CAAC;QACF,OAAO,WAAW,CAAC;IACpB,CAAC;IAES,KAAK,CAAC,gBAAgB,CAAC,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K,IAAI,SAAS,EAAE;YACvB,MAAM,IAAI,CAAC,OAAO,CAAC,uBAAuB,CAAC,SAAS,CAAC,KAAK,EAAE;gBAC3D,IAAI,EAAE,OAAO;gBACb,MAAM,EAAE;oBACP,IAAI,EAAE,SAAS,CAAC,GAAG;oBACnB,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,IAAI;oBACV,IAAI,EAAE,IAAI;oBACV,KAAK,EAAE,KAAK;iBACZ;gBACD,MAAM,EAAE,EAAE;aACV,CAAC,CAAC;YACH,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;SAC/D;IACF,CAAC;IAES,KAAK,CAAC,uBAAuB,CAAC,SAAoC,EAAE,KAAc,EAAE,WAAoB;QACjH,IAAI,KAAK,EAAE;YACV,MAAM,IAAI,CAAC,OAAO,CAAC,uBAAuB,CAAC,SAAS,CAAC,KAAK,EAAE;gBAC3D,IAAI,EAAE,OAAO;gBACb,MAAM,EAAE;oBACP,IAAI,EAAE,SAAS,CAAC,GAAG;oBACnB,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,IAAI;oBACV,KAAK,EAAE,KAAK;iBACZ;gBACD,MAAM,EAAE,EAAE;aACV,CAAC,CAAC;YACH,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;SAC/D;IACF,CAAC;CACD;AAzFD,oCAyFC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TibberPulse = void 0;
|
|
4
|
+
const tibber_api_1 = require("tibber-api");
|
|
5
|
+
const tibberHelper_1 = require("./tibberHelper");
|
|
6
|
+
class TibberPulse extends tibberHelper_1.TibberHelper {
|
|
7
|
+
constructor(tibberConfig, adapter) {
|
|
8
|
+
super(adapter);
|
|
9
|
+
this.tibberConfig = tibberConfig;
|
|
10
|
+
this.tibberQuery = new tibber_api_1.TibberQuery(this.tibberConfig);
|
|
11
|
+
this.tibberFeed = new tibber_api_1.TibberFeed(this.tibberQuery);
|
|
12
|
+
this.httpQueryUrl = tibberConfig.apiEndpoint.queryUrl;
|
|
13
|
+
this.addEventHandlerOnFeed(this.tibberFeed);
|
|
14
|
+
}
|
|
15
|
+
ConnectPulseStream() {
|
|
16
|
+
try {
|
|
17
|
+
this.tibberFeed.connect();
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
this.adapter.log.warn("Error on connect Feed:" + e.message);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
DisconnectPulseStream() {
|
|
24
|
+
try {
|
|
25
|
+
this.tibberFeed.close();
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
this.adapter.log.warn("Error on Feed closed:" + e.message);
|
|
29
|
+
}
|
|
30
|
+
// reinit Tibberfeed
|
|
31
|
+
this.tibberFeed = new tibber_api_1.TibberFeed(new tibber_api_1.TibberQuery(this.tibberConfig));
|
|
32
|
+
}
|
|
33
|
+
addEventHandlerOnFeed(currentFeed) {
|
|
34
|
+
// Set info.connection state
|
|
35
|
+
currentFeed.on("connected", (data) => {
|
|
36
|
+
this.adapter.log.debug("Tibber Feed: " + data.toString());
|
|
37
|
+
this.adapter.setState("info.connection", true, true);
|
|
38
|
+
});
|
|
39
|
+
// Set info.connection state
|
|
40
|
+
currentFeed.on("disconnected", (data) => {
|
|
41
|
+
this.adapter.log.debug("Tibber Feed: " + data.toString());
|
|
42
|
+
this.adapter.setState("info.connection", false, true);
|
|
43
|
+
if (this.adapter.config.FeedActive) {
|
|
44
|
+
this.adapter.log.warn("Feed was disconnected. I try to reconnect in 5s");
|
|
45
|
+
this.reconnect();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
// Add Error Handler on connection
|
|
49
|
+
currentFeed.on("error", (e) => {
|
|
50
|
+
this.adapter.log.error("ERROR on Tibber-Feed: " + e.toString());
|
|
51
|
+
});
|
|
52
|
+
// Add data receiver
|
|
53
|
+
currentFeed.on("data", (data) => {
|
|
54
|
+
const receivedData = data;
|
|
55
|
+
this.fetchLiveMeasurement("LiveMeasurement", receivedData);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
fetchLiveMeasurement(objectDestination, liveMeasurement) {
|
|
59
|
+
let power = 0;
|
|
60
|
+
if (liveMeasurement.power > 0) {
|
|
61
|
+
power = liveMeasurement.power;
|
|
62
|
+
}
|
|
63
|
+
else if (liveMeasurement.powerProduction > 0) {
|
|
64
|
+
power = liveMeasurement.powerProduction * -1;
|
|
65
|
+
}
|
|
66
|
+
if (this.tibberConfig.homeId !== undefined) {
|
|
67
|
+
this.checkAndSetValue(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "timestamp"), liveMeasurement.timestamp, "Timestamp when usage occurred");
|
|
68
|
+
this.checkAndSetValueNumberUnit(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "power"), power, "W", "Consumption at the moment");
|
|
69
|
+
this.checkAndSetValueNumberUnit(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "lastMeterConsumption"), liveMeasurement.lastMeterConsumption, "kWh", "Last meter active import register state");
|
|
70
|
+
this.checkAndSetValueNumberUnit(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "accumulatedConsumption"), liveMeasurement.accumulatedConsumption, "kWh", "Energy consumed since midnight");
|
|
71
|
+
this.checkAndSetValueNumberUnit(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "accumulatedProduction"), liveMeasurement.accumulatedProduction, "kWh", "Energy produced since midnight");
|
|
72
|
+
this.checkAndSetValueNumberUnit(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "accumulatedConsumptionLastHour"), liveMeasurement.accumulatedConsumptionLastHour, "kWh", "Energy consumed since since last hour shift");
|
|
73
|
+
this.checkAndSetValueNumberUnit(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "accumulatedProductionLastHour"), liveMeasurement.accumulatedProductionLastHour, "kWh", "Energy produced since last hour shift");
|
|
74
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "accumulatedCost"), liveMeasurement.accumulatedCost, "Accumulated cost since midnight; requires active Tibber power deal");
|
|
75
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "accumulatedReward"), liveMeasurement.accumulatedReward, "Accumulated reward since midnight; requires active Tibber power deal");
|
|
76
|
+
this.checkAndSetValue(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "currency"), liveMeasurement.currency, "Currency of displayed cost; requires active Tibber power deal");
|
|
77
|
+
this.checkAndSetValueNumberUnit(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "minPower"), liveMeasurement.minPower, "W", "Min consumption since midnight");
|
|
78
|
+
this.checkAndSetValueNumberUnit(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "averagePower"), liveMeasurement.averagePower, "W", "Average consumption since midnight");
|
|
79
|
+
this.checkAndSetValueNumberUnit(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "maxPower"), liveMeasurement.maxPower, "W", "Peak consumption since midnight");
|
|
80
|
+
this.checkAndSetValueNumberUnit(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "powerConsumption"), liveMeasurement.power, "W", "Net consumption (A+) at the moment");
|
|
81
|
+
this.checkAndSetValueNumberUnit(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "powerProduction"), liveMeasurement.powerProduction, "W", "Net production (A-) at the moment");
|
|
82
|
+
this.checkAndSetValueNumberUnit(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "minPowerProduction"), liveMeasurement.minPowerProduction, "W", "Min net production since midnight");
|
|
83
|
+
this.checkAndSetValueNumberUnit(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "maxPowerProduction"), liveMeasurement.maxPowerProduction, "W", "Max net production since midnight");
|
|
84
|
+
this.checkAndSetValueNumberUnit(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "lastMeterProduction"), liveMeasurement.lastMeterProduction, "kWh", "Last meter active export register state");
|
|
85
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "powerFactor"), liveMeasurement.powerFactor, "Power factor (active power / apparent power)");
|
|
86
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "voltagePhase1"), liveMeasurement.voltagePhase1, "Voltage on phase 1; on Kaifa and Aidon meters the value is not part of every HAN data frame therefore the value is null at timestamps with second value other than 0, 10, 20, 30, 40, 50. There can be other deviations based on concrete meter firmware.");
|
|
87
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "voltagePhase2"), liveMeasurement.voltagePhase2, "Voltage on phase 2; on Kaifa and Aidon meters the value is not part of every HAN data frame therefore the value is null at timestamps with second value other than 0, 10, 20, 30, 40, 50. There can be other deviations based on concrete meter firmware.");
|
|
88
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "voltagePhase3"), liveMeasurement.voltagePhase3, "Voltage on phase 3; on Kaifa and Aidon meters the value is not part of every HAN data frame therefore the value is null at timestamps with second value other than 0, 10, 20, 30, 40, 50. There can be other deviations based on concrete meter firmware.");
|
|
89
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "currentL1"), liveMeasurement.currentL1, "Current on L1; on Kaifa and Aidon meters the value is not part of every HAN data frame therefore the value is null at timestamps with second value other than 0, 10, 20, 30, 40, 50. There can be other deviations based on concrete meter firmware.");
|
|
90
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "currentL2"), liveMeasurement.currentL2, "Current on L2; on Kaifa and Aidon meters the value is not part of every HAN data frame therefore the value is null at timestamps with second value other than 0, 10, 20, 30, 40, 50. There can be other deviations based on concrete meter firmware.");
|
|
91
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "currentL3"), liveMeasurement.currentL3, "Current on L3; on Kaifa and Aidon meters the value is not part of every HAN data frame therefore the value is null at timestamps with second value other than 0, 10, 20, 30, 40, 50. There can be other deviations based on concrete meter firmware.");
|
|
92
|
+
this.checkAndSetValueNumber(this.getStatePrefix(this.tibberConfig.homeId, objectDestination, "signalStrength"), liveMeasurement.signalStrength, "Device signal strength (Pulse - dB; Watty - percent)");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
reconnect() {
|
|
96
|
+
const reconnectionInterval = this.adapter.setInterval(() => {
|
|
97
|
+
if (!this.tibberFeed.connected) {
|
|
98
|
+
this.adapter.log.debug("Try reconnecting now!");
|
|
99
|
+
this.ConnectPulseStream();
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.adapter.log.debug("Reconnect successful! Interval not necessary.");
|
|
103
|
+
this.adapter.clearInterval(reconnectionInterval);
|
|
104
|
+
}
|
|
105
|
+
}, 5000);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.TibberPulse = TibberPulse;
|
|
109
|
+
//# sourceMappingURL=tibberPulse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tibberPulse.js","sourceRoot":"","sources":["../../src/lib/tibberPulse.ts"],"names":[],"mappings":";;;AAAA,2CAA8D;AAG9D,iDAA8C;AAE9C,MAAa,WAAY,SAAQ,2BAAY;IAM5C,YAAY,YAAqB,EAAE,OAA8B;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,WAAW,GAAG,IAAI,wBAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACtD,IAAI,CA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AAC,oBAAoB,CAAC,CAAC;aACjD;QACF,CAAC,EAAE,IAAI,CAAC,CAAC;IACV,CAAC;CACD;AAhOD,kCAgOC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.translateText = exports.isArray = exports.isObject = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
/**
|
|
9
|
+
* Tests whether the given variable is a real object and not an Array
|
|
10
|
+
* @param it The variable to test
|
|
11
|
+
*/
|
|
12
|
+
function isObject(it) {
|
|
13
|
+
// This is necessary because:
|
|
14
|
+
// typeof null === 'object'
|
|
15
|
+
// typeof [] === 'object'
|
|
16
|
+
// [] instanceof Object === true
|
|
17
|
+
return Object.prototype.toString.call(it) === "[object Object]";
|
|
18
|
+
}
|
|
19
|
+
exports.isObject = isObject;
|
|
20
|
+
/**
|
|
21
|
+
* Tests whether the given variable is really an Array
|
|
22
|
+
* @param it The variable to test
|
|
23
|
+
*/
|
|
24
|
+
function isArray(it) {
|
|
25
|
+
if (Array.isArray != null)
|
|
26
|
+
return Array.isArray(it);
|
|
27
|
+
return Object.prototype.toString.call(it) === "[object Array]";
|
|
28
|
+
}
|
|
29
|
+
exports.isArray = isArray;
|
|
30
|
+
/**
|
|
31
|
+
* Translates text using the Google Translate API
|
|
32
|
+
* @param text The text to translate
|
|
33
|
+
* @param targetLang The target languate
|
|
34
|
+
* @param yandexApiKey The yandex API key. You can create one for free at https://translate.yandex.com/developers
|
|
35
|
+
*/
|
|
36
|
+
async function translateText(text, targetLang, yandexApiKey) {
|
|
37
|
+
if (targetLang === "en") {
|
|
38
|
+
return text;
|
|
39
|
+
}
|
|
40
|
+
else if (!text) {
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
if (yandexApiKey) {
|
|
44
|
+
return translateYandex(text, targetLang, yandexApiKey);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return translateGoogle(text, targetLang);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.translateText = translateText;
|
|
51
|
+
/**
|
|
52
|
+
* Translates text with Yandex API
|
|
53
|
+
* @param text The text to translate
|
|
54
|
+
* @param targetLang The target languate
|
|
55
|
+
* @param apiKey The yandex API key. You can create one for free at https://translate.yandex.com/developers
|
|
56
|
+
*/
|
|
57
|
+
async function translateYandex(text, targetLang, apiKey) {
|
|
58
|
+
var _a;
|
|
59
|
+
if (targetLang === "zh-cn") {
|
|
60
|
+
targetLang = "zh";
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const url = `https://translate.yandex.net/api/v1.5/tr.json/translate?key=${apiKey}&text=${encodeURIComponent(text)}&lang=en-${targetLang}`;
|
|
64
|
+
const response = await axios_1.default.request({ url, timeout: 15000 });
|
|
65
|
+
if (isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.text)) {
|
|
66
|
+
return response.data.text[0];
|
|
67
|
+
}
|
|
68
|
+
throw new Error("Invalid response for translate request");
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
throw new Error(`Could not translate to "${targetLang}": ${e}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Translates text with Google API
|
|
76
|
+
* @param text The text to translate
|
|
77
|
+
* @param targetLang The target languate
|
|
78
|
+
*/
|
|
79
|
+
async function translateGoogle(text, targetLang) {
|
|
80
|
+
var _a;
|
|
81
|
+
try {
|
|
82
|
+
const url = `http://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=${targetLang}&dt=t&q=${encodeURIComponent(text)}&ie=UTF-8&oe=UTF-8`;
|
|
83
|
+
const response = await axios_1.default.request({ url, timeout: 15000 });
|
|
84
|
+
if (isArray(response.data)) {
|
|
85
|
+
// we got a valid response
|
|
86
|
+
return response.data[0][0][0];
|
|
87
|
+
}
|
|
88
|
+
throw new Error("Invalid response for translate request");
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
if (((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 429) {
|
|
92
|
+
throw new Error(`Could not translate to "${targetLang}": Rate-limited by Google Translate`);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw new Error(`Could not translate to "${targetLang}": ${e}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/lib/tools.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B;;;GAGG;AACH,SAAgB,QAAQ,CAAC,EAAW;IACnC,6BAA6B;IAC7B,2BAA2B;IAC3B,yBAAyB;IACzB,gCAAgC;IAChC,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,iBAAiB,CAAC;AACjE,CAAC;AAND,4BAMC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,EAAW;IAClC,IAAI,KAAK,CAAC,OAAO,IAAI,IAAI;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACpD,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,gBAAgB,CAAC;AAChE,CAAC;AAHD,0BAGC;AAED;;;;;GAKG;AACI,KAAK,UAAU,aAAa,CAAC,IAAY,EAAE,UAAkB,EAAE,YAAqB;IAC1F,IAAI,UAAU,KAAK,IAAI,EAAE;QACxB,OAAO,IAAI,CAAC;KACZ;SAAM,IAAI,CAAC,IAAI,EAAE;QACjB,OAAO,EAAE,CAAC;KACV;IACD,IAAI,YAAY,EAAE;QACjB,OAAO,eAAe,CAA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