hoffmation-base 1.1.38 → 1.1.40

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/lib/index.js CHANGED
@@ -37,7 +37,7 @@ class HoffmationBase {
37
37
  server_1.ServerLogService.writeLog(models_1.LogLevel.Info, `Hoffmation-Base Startup`);
38
38
  if (initObject.config.persistence) {
39
39
  if (initObject.config.persistence.postgreSql) {
40
- server_1.Utils.dbo = new server_1.PostgreSqlPersist(initObject.config.persistence);
40
+ server_1.Utils.dbo = new server_1.PostgreSqlPersist(initObject.config.persistence.postgreSql);
41
41
  }
42
42
  await ((_a = server_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.initialize());
43
43
  }
@@ -67,7 +67,7 @@ class ZigbeeEuroHeater extends BaseDevices_1.ZigbeeHeater {
67
67
  switch (idSplit[3]) {
68
68
  case 'valve_position':
69
69
  this.log(models_1.LogLevel.Trace, `Euro Valve valve_position Update for ${this.info.customName} to "${state.val}"`);
70
- this._level = state.val;
70
+ this._level = state.val / 100;
71
71
  break;
72
72
  case 'local_temp':
73
73
  this.log(models_1.LogLevel.Trace, `Euro Valve Local_Temp Update for ${this.info.customName} to "${state.val}"`);
@@ -87,13 +87,9 @@ class ZigbeeEuroHeater extends BaseDevices_1.ZigbeeHeater {
87
87
  case 'spz_trv_mode':
88
88
  this.log(models_1.LogLevel.Trace, `Euro Valve mode Update for ${this.info.customName} to "${state.val}"`);
89
89
  this._mode = state.val;
90
- if (!this.settings.seasonalTurnOffActive) {
91
- if (this.settings.controlByPid && this._mode == 2) {
92
- this.setMode(1);
93
- }
94
- else if (this._mode == 1) {
95
- this.setMode(2);
96
- }
90
+ const desiredMode = this.settings.controlByPid ? 1 : 2;
91
+ if (!this.settings.seasonalTurnOffActive && this._mode !== desiredMode) {
92
+ this.setMode(desiredMode);
97
93
  }
98
94
  break;
99
95
  case 'target_temperature':
@@ -42,7 +42,7 @@ class ZigbeeTuyaValve extends BaseDevices_1.ZigbeeHeater {
42
42
  switch (idSplit[3]) {
43
43
  case 'valve_position':
44
44
  this.log(models_1.LogLevel.Trace, `Tuya Valve valve_position Update for ${this.info.customName} to "${state.val}"`);
45
- this._level = state.val;
45
+ this._level = state.val / 100;
46
46
  break;
47
47
  case 'local_temp':
48
48
  this.log(models_1.LogLevel.Trace, `Tuya Valve Local_Temp Update for ${this.info.customName} to "${state.val}"`);
@@ -108,7 +108,7 @@ class AcDevice {
108
108
  }
109
109
  persist() {
110
110
  var _a;
111
- if (!utils_1.Utils.anyDboActive) {
111
+ if (!utils_1.Utils.anyDboActive || this.on === undefined) {
112
112
  return;
113
113
  }
114
114
  (_a = utils_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistAC(this);
@@ -1,11 +1,12 @@
1
1
  import { iPersist } from './iPersist';
2
2
  import { CountToday, CurrentIlluminationDataPoint, DesiredShutterPosition, EnergyCalculation, RoomBase, ShutterCalibration, TemperaturDataPoint } from '../../../models';
3
3
  import { ButtonPressType, iAcDevice, iActuator, iBaseDevice, iButtonSwitch, iHeater, iMotionSensor, IoBrokerBaseDevice, iShutter, iTemperatureSensor } from '../../devices';
4
- import { iPersistenceSettings } from '../../config';
4
+ import { PoolConfig } from 'pg';
5
5
  export declare class PostgreSqlPersist implements iPersist {
6
6
  initialized: boolean;
7
7
  private readonly psql;
8
- constructor(config: iPersistenceSettings);
8
+ private readonly config;
9
+ constructor(conf: PoolConfig);
9
10
  addRoom(room: RoomBase): void;
10
11
  addDevice(device: iBaseDevice): void;
11
12
  addTemperaturDataPoint(heater: iHeater): void;
@@ -7,10 +7,10 @@ const pg_1 = require("pg");
7
7
  const log_service_1 = require("../log-service");
8
8
  const DeviceCapability_1 = require("../../devices/DeviceCapability");
9
9
  class PostgreSqlPersist {
10
- constructor(config) {
10
+ constructor(conf) {
11
11
  this.initialized = false;
12
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13
- this.psql = new pg_1.Pool(config.postgreSql);
12
+ this.config = conf;
13
+ this.psql = new pg_1.Pool(this.config);
14
14
  }
15
15
  addRoom(room) {
16
16
  this.query(`
@@ -39,7 +39,7 @@ values ('${device.id}','${device.info.room}','${device.info.allDevicesKey}','${d
39
39
  log_service_1.ServerLogService.writeLog(models_1.LogLevel.Trace, `Persisting Temperatur Data for ${heater.info.customName}`);
40
40
  this.query(`
41
41
  insert into hoffmation_schema."TemperaturData" ("date", "humidity", "istTemperatur", "level", "name", "sollTemperatur")
42
- values ('${new Date().toISOString()}',${heater.humidity},${heater.iTemperature},${heater.iLevel},'${heater.info.customName}',${heater.desiredTemperature});`);
42
+ values ('${new Date().toISOString()}',${heater.humidity},${heater.iTemperature},${heater.iLevel / 100},'${heater.info.customName}',${heater.desiredTemperature});`);
43
43
  this.query(`
44
44
  insert into hoffmation_schema."HeatGroupCollection" ("date", "humidity", "istTemperatur", "level", "name", "sollTemperatur")
45
45
  values ('${new Date().toISOString()}',${heater.humidity},${heater.iTemperature},${heater.iLevel},'${heater.info.customName}',${heater.desiredTemperature})
@@ -90,232 +90,233 @@ WHERE "deviceID" = '${device.id}' and "movementDetected" and date >= CURRENT_DAT
90
90
  await this.psql.query(`
91
91
  DO $$
92
92
  BEGIN
93
- IF (SELECT to_regclass('hoffmation_schema."BasicRooms"') IS NULL) Then
94
- create table "BasicRooms"
95
- (
96
- name varchar(30) not null
97
- constraint table_name_pk
98
- primary key,
99
- etage integer
100
- );
93
+ IF (SELECT to_regclass('hoffmation_schema."BasicRooms"') IS NULL) Then
94
+ create table "BasicRooms"
95
+ (
96
+ name varchar(30) not null
97
+ constraint table_name_pk
98
+ primary key,
99
+ etage integer
100
+ );
101
101
 
102
- alter table "BasicRooms"
103
- owner to postgres;
102
+ alter table hoffmation_schema."BasicRooms"
103
+ owner to "${this.config.user}";
104
104
 
105
- create unique index table_name_name_uindex
106
- on "BasicRooms" (name);
105
+ create unique index table_name_name_uindex
106
+ on "BasicRooms" (name);
107
107
 
108
- END IF;
109
- IF (SELECT to_regclass('hoffmation_schema."DeviceInfo"') IS NULL) Then
108
+ END IF;
109
+
110
+ IF (SELECT to_regclass('hoffmation_schema."DeviceInfo"') IS NULL) Then
110
111
  create table hoffmation_schema."DeviceInfo"
111
- (
112
- deviceid varchar(60) not null
113
- constraint deviceinfo_pk
114
- primary key,
115
- roomname varchar(30)
116
- constraint "DeviceInfo_BasicRooms_null_fk"
117
- references hoffmation_schema."BasicRooms",
118
- alldeviceskey varchar(30),
119
- customname varchar(60),
120
- devtype integer
121
- );
112
+ (
113
+ deviceid varchar(60) not null
114
+ constraint deviceinfo_pk
115
+ primary key,
116
+ roomname varchar(30)
117
+ constraint "DeviceInfo_BasicRooms_null_fk"
118
+ references hoffmation_schema."BasicRooms",
119
+ alldeviceskey varchar(30),
120
+ customname varchar(60),
121
+ devtype integer
122
+ );
122
123
 
123
- alter table hoffmation_schema."DeviceInfo"
124
- owner to postgres;
124
+ alter table hoffmation_schema."DeviceInfo"
125
+ owner to "${this.config.user}";
125
126
 
126
- END IF;
127
+ END IF;
127
128
 
128
- IF (SELECT to_regclass('hoffmation_schema."CurrentIllumination"') IS NULL) Then
129
- create table "CurrentIllumination"
130
- (
131
- "roomName" varchar(30)
132
- constraint currentillumination_basicrooms_name_fk
133
- references hoffmation_schema."BasicRooms",
134
- "deviceID" integer not null,
135
- "currentIllumination" double precision,
136
- date timestamp with time zone,
137
- "lightIsOn" boolean
138
- );
129
+ IF (SELECT to_regclass('hoffmation_schema."CurrentIllumination"') IS NULL) Then
130
+ create table hoffmation_schema."CurrentIllumination"
131
+ (
132
+ "roomName" varchar(30)
133
+ constraint currentillumination_basicrooms_name_fk
134
+ references hoffmation_schema."BasicRooms",
135
+ "deviceID" integer not null,
136
+ "currentIllumination" double precision,
137
+ date timestamp with time zone,
138
+ "lightIsOn" boolean
139
+ );
139
140
 
140
- alter table "CurrentIllumination"
141
- owner to postgres;
142
- END IF;
141
+ alter table hoffmation_schema."CurrentIllumination"
142
+ owner to "${this.config.user}";
143
+ END IF;
143
144
 
144
- IF (SELECT to_regclass('hoffmation_schema."ButtonSwitchPresses"') IS NULL) Then
145
- create table if not exists hoffmation_schema."ButtonSwitchPresses"
146
- (
147
- "deviceID" varchar(60) not null
148
- constraint "ButtonSwitchPresses_DeviceInfo_null_fk"
149
- references hoffmation_schema."DeviceInfo"
150
- on delete set null,
151
- "pressType" int,
152
- "buttonName" varchar(30),
153
- date timestamp not null,
154
- constraint buttonswitchpresses_pk
155
- primary key ("deviceID", "pressType", date)
156
- );
145
+ IF (SELECT to_regclass('hoffmation_schema."ButtonSwitchPresses"') IS NULL) Then
146
+ create table if not exists hoffmation_schema."ButtonSwitchPresses"
147
+ (
148
+ "deviceID" varchar(60) not null
149
+ constraint "ButtonSwitchPresses_DeviceInfo_null_fk"
150
+ references hoffmation_schema."DeviceInfo"
151
+ on delete set null,
152
+ "pressType" int,
153
+ "buttonName" varchar(30),
154
+ date timestamp not null,
155
+ constraint buttonswitchpresses_pk
156
+ primary key ("deviceID", "pressType", date)
157
+ );
157
158
 
158
- alter table hoffmation_schema."ButtonSwitchPresses"
159
- owner to postgres;
160
- END IF;
159
+ alter table hoffmation_schema."ButtonSwitchPresses"
160
+ owner to "${this.config.user}";
161
+ END IF;
161
162
 
162
- IF (SELECT to_regclass('hoffmation_schema."EnergyCalculation"') IS NULL) Then
163
- create table "EnergyCalculation"
164
- (
165
- "startDate" timestamp not null
166
- constraint energycalculation_pk
167
- primary key,
168
- "endDate" timestamp,
169
- "selfConsumedKwH" double precision,
170
- "injectedKwH" double precision,
171
- "drawnKwH" double precision
172
- );
173
-
174
- alter table "EnergyCalculation"
175
- owner to postgres;
176
-
177
- create unique index energycalculation_startdate_uindex
178
- on "EnergyCalculation" ("startDate");
179
-
180
- END IF;
181
- IF (SELECT to_regclass('hoffmation_schema."HeatGroupCollection"') IS NULL) Then
182
- create table "HeatGroupCollection"
183
- (
184
- date timestamp,
185
- humidity integer,
186
- "istTemperatur" double precision,
187
- level integer,
188
- name varchar(60) not null
189
- constraint heatgroupcollection_pk
190
- primary key,
191
- "sollTemperatur" double precision
192
- );
163
+ IF (SELECT to_regclass('hoffmation_schema."EnergyCalculation"') IS NULL) Then
164
+ create table hoffmation_schema."EnergyCalculation"
165
+ (
166
+ "startDate" timestamp not null
167
+ constraint energycalculation_pk
168
+ primary key,
169
+ "endDate" timestamp,
170
+ "selfConsumedKwH" double precision,
171
+ "injectedKwH" double precision,
172
+ "drawnKwH" double precision
173
+ );
193
174
 
194
- alter table "HeatGroupCollection"
195
- owner to postgres;
175
+ alter table hoffmation_schema."EnergyCalculation"
176
+ owner to "${this.config.user}";
196
177
 
197
- create unique index heatgroupcollection_name_uindex
198
- on "HeatGroupCollection" (name);
178
+ create unique index energycalculation_startdate_uindex
179
+ on "EnergyCalculation" ("startDate");
199
180
 
200
- END IF;
181
+ END IF;
182
+ IF (SELECT to_regclass('hoffmation_schema."HeatGroupCollection"') IS NULL) Then
183
+ create table hoffmation_schema."HeatGroupCollection"
184
+ (
185
+ date timestamp,
186
+ humidity integer,
187
+ "istTemperatur" double precision,
188
+ level integer,
189
+ name varchar(60) not null
190
+ constraint heatgroupcollection_pk
191
+ primary key,
192
+ "sollTemperatur" double precision
193
+ );
201
194
 
202
- IF (SELECT to_regclass('hoffmation_schema."AcDeviceData"') IS NULL) Then
203
- create table hoffmation_schema."AcDeviceData"
204
- (
205
- "deviceID" varchar(60) not null,
206
- "on" boolean,
207
- "istTemperatur" double precision,
208
- date timestamp not null,
209
- constraint acdevicedata_pk
210
- primary key ("deviceID", date)
211
- );
195
+ alter table hoffmation_schema."HeatGroupCollection"
196
+ owner to "${this.config.user}";
212
197
 
213
- alter table hoffmation_schema."AcDeviceData"
214
- owner to postgres;
215
- END IF;
198
+ create unique index heatgroupcollection_name_uindex
199
+ on "HeatGroupCollection" (name);
216
200
 
201
+ END IF;
217
202
 
218
- IF (SELECT to_regclass('hoffmation_schema."ActuatorDeviceData"') IS NULL) Then
219
- create table hoffmation_schema."ActuatorDeviceData"
220
- (
221
- "deviceID" varchar(60) not null,
222
- "on" boolean,
223
- date timestamp not null,
224
- constraint ActuatorDeviceData_pk
225
- primary key ("deviceID", date)
226
- );
227
-
228
- alter table hoffmation_schema."ActuatorDeviceData"
229
- owner to postgres;
230
- END IF;
231
-
232
- IF (SELECT to_regclass('hoffmation_schema."MotionSensorDeviceData"') IS NULL) Then
233
- create table hoffmation_schema."MotionSensorDeviceData"
234
- (
235
- "deviceID" varchar(60) not null,
236
- "movementDetected" boolean,
237
- date timestamp not null,
238
- constraint motionsensordevicedata_pk
239
- primary key ("deviceID", date)
240
- );
203
+ IF (SELECT to_regclass('hoffmation_schema."AcDeviceData"') IS NULL) Then
204
+ create table hoffmation_schema."AcDeviceData"
205
+ (
206
+ "deviceID" varchar(60) not null,
207
+ "on" boolean,
208
+ "istTemperatur" double precision,
209
+ date timestamp not null,
210
+ constraint acdevicedata_pk
211
+ primary key ("deviceID", date)
212
+ );
213
+
214
+ alter table hoffmation_schema."AcDeviceData"
215
+ owner to "${this.config.user}";
216
+ END IF;
241
217
 
242
- alter table hoffmation_schema."MotionSensorDeviceData"
243
- owner to postgres;
244
- END IF;
245
218
 
246
- IF (SELECT to_regclass('hoffmation_schema."ShutterDeviceData"') IS NULL) Then
247
- create table if not exists hoffmation_schema."ShutterDeviceData"
248
- (
249
- "deviceID" varchar(60) not null
250
- constraint "ShutterDeviceData_DeviceInfo_null_fk"
251
- references hoffmation_schema."DeviceInfo"
252
- on delete set null,
253
- "position" double precision,
254
- date timestamp not null,
255
- "desiredPosition" double precision,
256
- constraint shutterdevicedata_pk
257
- primary key ("deviceID", date)
258
- );
219
+ IF (SELECT to_regclass('hoffmation_schema."ActuatorDeviceData"') IS NULL) Then
220
+ create table hoffmation_schema."ActuatorDeviceData"
221
+ (
222
+ "deviceID" varchar(60) not null,
223
+ "on" boolean,
224
+ date timestamp not null,
225
+ constraint ActuatorDeviceData_pk
226
+ primary key ("deviceID", date)
227
+ );
228
+
229
+ alter table hoffmation_schema."ActuatorDeviceData"
230
+ owner to "${this.config.user}";
231
+ END IF;
259
232
 
260
- alter table hoffmation_schema."ShutterDeviceData"
261
- owner to postgres;
262
- END IF;
233
+ IF (SELECT to_regclass('hoffmation_schema."MotionSensorDeviceData"') IS NULL) Then
234
+ create table hoffmation_schema."MotionSensorDeviceData"
235
+ (
236
+ "deviceID" varchar(60) not null,
237
+ "movementDetected" boolean,
238
+ date timestamp not null,
239
+ constraint motionsensordevicedata_pk
240
+ primary key ("deviceID", date)
241
+ );
242
+
243
+ alter table hoffmation_schema."MotionSensorDeviceData"
244
+ owner to "${this.config.user}";
245
+ END IF;
263
246
 
264
- IF (SELECT to_regclass('hoffmation_schema."TemperatureSensorDeviceData"') IS NULL) Then
265
- create table if not exists hoffmation_schema."TemperatureSensorDeviceData"
266
- (
267
- "deviceID" varchar(60) not null
268
- constraint "TemperatureSensorDeviceData_DeviceInfo_null_fk"
269
- references hoffmation_schema."DeviceInfo"
270
- on delete set null,
271
- temperature double precision,
272
- date timestamp not null,
273
- "roomTemperature" double precision,
274
- constraint temperaturesensordevicedata_pk
275
- primary key ("deviceID", date)
276
- );
247
+ IF (SELECT to_regclass('hoffmation_schema."ShutterDeviceData"') IS NULL) Then
248
+ create table if not exists hoffmation_schema."ShutterDeviceData"
249
+ (
250
+ "deviceID" varchar(60) not null
251
+ constraint "ShutterDeviceData_DeviceInfo_null_fk"
252
+ references hoffmation_schema."DeviceInfo"
253
+ on delete set null,
254
+ "position" double precision,
255
+ date timestamp not null,
256
+ "desiredPosition" double precision,
257
+ constraint shutterdevicedata_pk
258
+ primary key ("deviceID", date)
259
+ );
260
+
261
+ alter table hoffmation_schema."ShutterDeviceData"
262
+ owner to "${this.config.user}";
263
+ END IF;
277
264
 
278
- alter table hoffmation_schema."TemperatureSensorDeviceData"
279
- owner to postgres;
280
- END IF;
265
+ IF (SELECT to_regclass('hoffmation_schema."TemperatureSensorDeviceData"') IS NULL) Then
266
+ create table if not exists hoffmation_schema."TemperatureSensorDeviceData"
267
+ (
268
+ "deviceID" varchar(60) not null
269
+ constraint "TemperatureSensorDeviceData_DeviceInfo_null_fk"
270
+ references hoffmation_schema."DeviceInfo"
271
+ on delete set null,
272
+ temperature double precision,
273
+ date timestamp not null,
274
+ "roomTemperature" double precision,
275
+ constraint temperaturesensordevicedata_pk
276
+ primary key ("deviceID", date)
277
+ );
278
+
279
+ alter table hoffmation_schema."TemperatureSensorDeviceData"
280
+ owner to "${this.config.user}";
281
+ END IF;
281
282
 
282
283
 
283
284
 
284
285
  IF (SELECT to_regclass('hoffmation_schema."HeaterDeviceData"') IS NULL) Then
285
- create table if not exists hoffmation_schema."HeaterDeviceData"
286
- (
287
- "deviceID" varchar(60) not null
288
- constraint "HeaterDeviceData_DeviceInfo_null_fk"
289
- references hoffmation_schema."DeviceInfo",
290
- "level" double precision,
291
- date timestamp not null,
292
- "roomTemperature" double precision,
293
- "desiredTemperature" double precision,
294
- "seasonTurnOff" boolean,
295
- constraint heaterevicedata_pk
296
- primary key ("deviceID", date)
297
- );
298
-
299
- alter table hoffmation_schema."HeaterDeviceData"
300
- owner to postgres;
301
- END IF;
286
+ create table if not exists hoffmation_schema."HeaterDeviceData"
287
+ (
288
+ "deviceID" varchar(60) not null
289
+ constraint "HeaterDeviceData_DeviceInfo_null_fk"
290
+ references hoffmation_schema."DeviceInfo",
291
+ "level" double precision,
292
+ date timestamp not null,
293
+ "roomTemperature" double precision,
294
+ "desiredTemperature" double precision,
295
+ "seasonTurnOff" boolean,
296
+ constraint heaterevicedata_pk
297
+ primary key ("deviceID", date)
298
+ );
302
299
 
303
- IF (SELECT to_regclass('hoffmation_schema."TemperaturData"') IS NULL) Then
304
- create table "TemperaturData"
305
- (
306
- date timestamp,
307
- humidity integer,
308
- "istTemperatur" double precision,
309
- level integer,
310
- name text,
311
- "sollTemperatur" double precision,
312
- constraint temperaturdata_pk
313
- unique (date, name)
314
- );
315
-
316
- alter table "TemperaturData"
317
- owner to postgres;
318
- END IF;
300
+ alter table hoffmation_schema."HeaterDeviceData"
301
+ owner to "${this.config.user}";
302
+ END IF;
303
+
304
+ IF (SELECT to_regclass('hoffmation_schema."TemperaturData"') IS NULL) Then
305
+ create table hoffmation_schema."TemperaturData"
306
+ (
307
+ date timestamp,
308
+ humidity integer,
309
+ "istTemperatur" double precision,
310
+ level integer,
311
+ name text,
312
+ "sollTemperatur" double precision,
313
+ constraint temperaturdata_pk
314
+ unique (date, name)
315
+ );
316
+
317
+ alter table hoffmation_schema."TemperaturData"
318
+ owner to "${this.config.user}";
319
+ END IF;
319
320
  END
320
321
  $$;`);
321
322
  this.initialized = true;