homebridge-melcloud-control 4.1.3-beta.2 → 4.1.3-beta.21

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/src/deviceatw.js CHANGED
@@ -37,9 +37,8 @@ class DeviceAtw extends EventEmitter {
37
37
  this.temperatureReturnWaterTankSensor = device.temperatureReturnWaterTankSensor || false;
38
38
  this.temperatureFlowZone2Sensor = device.temperatureFlowZone2Sensor || false;
39
39
  this.temperatureReturnZone2Sensor = device.temperatureReturnZone2Sensor || false;
40
- this.holidayModeSensor = device.holidayModeSensor || false;
41
- this.scheduleSensor = device.scheduleSensor || false;
42
40
  this.errorSensor = device.errorSensor || false;
41
+ this.holidayModeSupport = device.holidayModeSupport || false;
43
42
  this.presets = this.accountType === 'melcloud' ? (device.presets || []).filter(preset => (preset.displayType ?? 0) > 0 && preset.id !== '0') : [];
44
43
  this.schedules = this.accountType === 'melcloudhome' ? (device.schedules || []).filter(schedule => (schedule.displayType ?? 0) > 0 && schedule.id !== '0') : [];
45
44
  this.buttons = (device.buttonsSensors || []).filter(button => (button.displayType ?? 0) > 0);
@@ -68,8 +67,8 @@ class DeviceAtw extends EventEmitter {
68
67
  //schedules configured
69
68
  for (const schedule of this.schedules) {
70
69
  schedule.name = schedule.name || 'Schedule'
71
- schedule.serviceType = [null, Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][schedule.displayType];
72
- schedule.characteristicType = [null, Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][schedule.displayType];
70
+ schedule.serviceType = [null, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][schedule.displayType];
71
+ schedule.characteristicType = [null, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][schedule.displayType];
73
72
  schedule.state = false;
74
73
  }
75
74
 
@@ -1049,37 +1048,10 @@ class DeviceAtw extends EventEmitter {
1049
1048
  });
1050
1049
  };
1051
1050
 
1052
- //holiday mode sensor
1053
- if (this.holidayModeSensor && this.accessory.holidayModeEnabled !== null) {
1054
- if (this.logDebug) this.emit('debug', `Prepare holiday mode service`);
1055
- this.holidayModeSensorService = new Service.ContactSensor(`${serviceName} Holiday Mode`, `Holiday Mode Sensor ${deviceId}`);
1056
- this.holidayModeSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1057
- this.holidayModeSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Holiday Mode`);
1058
- this.holidayModeSensorService.getCharacteristic(Characteristic.ContactSensorState)
1059
- .onGet(async () => {
1060
- const state = this.accessory.holidayModeActive;
1061
- return state;
1062
- })
1063
- accessory.addService(this.holidayModeSensorService);
1064
- }
1065
-
1066
- //schedule sensor
1067
- if (this.scheduleSensor && this.accessory.scheduleEnabled !== null) {
1068
- if (this.logDebug) this.emit('debug', `Prepare schedule service`);
1069
- this.scheduleSensorService = new Service.ContactSensor(`${serviceName} Schedule`, `Schedule Sensor ${deviceId}`);
1070
- this.scheduleSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1071
- this.scheduleSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Schedule`);
1072
- this.scheduleSensorService.getCharacteristic(Characteristic.ContactSensorState)
1073
- .onGet(async () => {
1074
- const state = this.accessory.scheduleEnabled;
1075
- return state;
1076
- })
1077
- accessory.addService(this.scheduleSensorService);
1078
- }
1079
-
1080
1051
  //error sensor
1081
1052
  if (this.errorSensor && this.accessory.isInError !== null) {
1082
1053
  if (this.logDebug) this.emit('debug', `Prepare error service`);
1054
+ const serviceName = `${deviceTypeText} ${accessoryName}`;
1083
1055
  this.errorService = new Service.ContactSensor(`${serviceName} Error`, `Error Sensor ${deviceId}`);
1084
1056
  this.errorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1085
1057
  this.errorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Error`);
@@ -1091,6 +1063,53 @@ class DeviceAtw extends EventEmitter {
1091
1063
  accessory.addService(this.errorService);
1092
1064
  }
1093
1065
 
1066
+ //holiday mode
1067
+ if (this.holidayModeSupport && this.accessory.holidayModeEnabled !== null) {
1068
+ //control
1069
+ if (this.logDebug) this.emit('debug', `Prepare holiday mode control service`);
1070
+ this.holidayModeControlService = new Service.Switch(`${serviceName} Holiday Mode`, `holidayModeControlService${deviceId}`);
1071
+ this.holidayModeControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1072
+ this.holidayModeControlService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Holiday Mode`);
1073
+ this.holidayModeControlService.getCharacteristic(Characteristic.On)
1074
+ .onGet(async () => {
1075
+ const state = this.accessory.holidayModeEnabled;
1076
+ return state;
1077
+ })
1078
+ .onSet(async (state) => {
1079
+ try {
1080
+ deviceData.HolidayMode.Enabled = state;
1081
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'holidaymode');
1082
+ if (this.logInfo) this.emit('info', `Holiday mode: ${state ? 'Enabled' : 'Disabled'}`);
1083
+ } catch (error) {
1084
+ if (this.logWarn) this.emit('warn', `Set holiday mode error: ${error}`);
1085
+ };
1086
+ });
1087
+ accessory.addService(this.holidayModeControlService);
1088
+
1089
+ if (this.logDebug) this.emit('debug', `Prepare holiday mode control sensor service`);
1090
+ this.holidayModeControlSensorService = new Service.ContactSensor(`${serviceName} Holiday Mode Control`, `holidayModeControlSensorService${deviceId}`);
1091
+ this.holidayModeControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1092
+ this.holidayModeControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Holiday Mode Control`);
1093
+ this.holidayModeControlSensorService.getCharacteristic(Characteristic.ContactSensorState)
1094
+ .onGet(async () => {
1095
+ const state = this.accessory.holidayModeEnabled;
1096
+ return state;
1097
+ })
1098
+ accessory.addService(this.holidayModeControlSensorService);
1099
+
1100
+ //sensors
1101
+ if (this.logDebug) this.emit('debug', `Prepare holiday mode sensor service`);
1102
+ this.holidayModeSensorService = new Service.ContactSensor(`${serviceName} Holiday Mode`, `holidayModeSensorService${deviceId}`);
1103
+ this.holidayModeSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1104
+ this.holidayModeSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Holiday Mode State`);
1105
+ this.holidayModeSensorService.getCharacteristic(Characteristic.ContactSensorState)
1106
+ .onGet(async () => {
1107
+ const state = this.accessory.holidayModeActive;
1108
+ return state;
1109
+ })
1110
+ accessory.addService(this.holidayModeSensorService);
1111
+ }
1112
+
1094
1113
  //presets services
1095
1114
  if (this.presets.length > 0) {
1096
1115
  if (this.logDebug) this.emit('debug', `Prepare presets services`);
@@ -1162,7 +1181,7 @@ class DeviceAtw extends EventEmitter {
1162
1181
  };
1163
1182
 
1164
1183
  //schedules services
1165
- if (this.schedules.length > 0) {
1184
+ if (this.schedules.length > 0 && this.accessory.scheduleEnabled !== null) {
1166
1185
  if (this.logDebug) this.emit('debug', `Prepare schedules services`);
1167
1186
  this.schedulesServices = [];
1168
1187
  this.schedules.forEach((schedule, i) => {
@@ -1172,25 +1191,52 @@ class DeviceAtw extends EventEmitter {
1172
1191
  //get preset name prefix
1173
1192
  const namePrefix = schedule.namePrefix;
1174
1193
 
1194
+ //control
1195
+ if (i === 0) {
1196
+ if (this.logDebug) this.emit('debug', `Prepare schedule control service`);
1197
+ const serviceNameSchedule = namePrefix ? `${accessoryName} Schedule Control` : `Schedule Control`;
1198
+ this.schedulesControlService = new Service.Switch(serviceNameSchedule, `Schedule Control ${deviceId} ${i}`);
1199
+ this.schedulesControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1200
+ this.schedulesControlService.setCharacteristic(Characteristic.ConfiguredName, serviceNameSchedule);
1201
+ this.schedulesControlService.getCharacteristic(Characteristic.On)
1202
+ .onGet(async () => {
1203
+ const state = this.accessory.scheduleEnabled;
1204
+ return state;
1205
+ })
1206
+ .onSet(async (state) => {
1207
+ try {
1208
+ deviceData.ScheduleEnabled = state;
1209
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'schedule');
1210
+ if (this.logInfo) this.emit('info', `Schedule: ${state ? 'Enabled' : 'Disabled'}`);
1211
+ } catch (error) {
1212
+ if (this.logWarn) this.emit('warn', `Set schedule error: ${error}`);
1213
+ };
1214
+ });
1215
+ accessory.addService(this.schedulesControlService);
1216
+
1217
+ if (this.logDebug) this.emit('debug', `Prepare schedule control sensor service`);
1218
+ this.scheduleSensorService = new Service.ContactSensor(serviceNameSchedule, `Schedule Control Sensor ${deviceId}`);
1219
+ this.scheduleSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1220
+ this.scheduleSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceNameSchedule);
1221
+ this.scheduleSensorService.getCharacteristic(Characteristic.ContactSensorState)
1222
+ .onGet(async () => {
1223
+ const state = this.accessory.scheduleEnabled;
1224
+ return state;
1225
+ })
1226
+ accessory.addService(this.scheduleSensorService);
1227
+ }
1228
+
1229
+ //sensors
1175
1230
  const serviceName = namePrefix ? `${accessoryName} ${name}` : name;
1176
1231
  const serviceType = schedule.serviceType;
1177
1232
  const characteristicType = schedule.characteristicType;
1178
- const scheduleService = new serviceType(serviceName, `Schedule ${deviceId} ${i}`);
1233
+ const scheduleService = new serviceType(serviceName, `Schedule Sensor ${deviceId} ${i}`);
1179
1234
  scheduleService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1180
1235
  scheduleService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
1181
1236
  scheduleService.getCharacteristic(characteristicType)
1182
1237
  .onGet(async () => {
1183
1238
  const state = schedule.state;
1184
1239
  return state;
1185
- })
1186
- .onSet(async (state) => {
1187
- try {
1188
- deviceData.ScheduleEnabled = state;
1189
- await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'scheduleenabled');
1190
- if (this.logInfo) this.emit('info', `${state ? 'Set:' : 'Unset:'} ${name}`);
1191
- } catch (error) {
1192
- if (this.logWarn) this.emit('warn', `Set schedule error: ${error}`);
1193
- };
1194
1240
  });
1195
1241
  this.schedulesServices.push(scheduleService);
1196
1242
  accessory.addService(scheduleService);
@@ -1416,7 +1462,7 @@ class DeviceAtw extends EventEmitter {
1416
1462
  const schedulesOnServer = deviceData.Schedule ?? [];
1417
1463
  const presetsOnServer = deviceData.Presets ?? [];
1418
1464
  const holidayModeEnabled = deviceData.HolidayMode?.Enabled;
1419
- const holidayModeActive = deviceData.HolidayMode?.Active;
1465
+ const holidayModeActive = deviceData.HolidayMode?.Active ?? false;
1420
1466
 
1421
1467
  //device info
1422
1468
  const hasHeatPump = ![1, 2, 3, 4, 5, 6, 7, 15].includes(this.hideZone);
@@ -1899,12 +1945,17 @@ class DeviceAtw extends EventEmitter {
1899
1945
  };
1900
1946
  this.accessory = obj;
1901
1947
 
1902
- //update sensors state
1903
- this.holidayModeSensorService?.updateCharacteristic(Characteristic.ContactSensorState, holidayModeActive);
1904
- this.scheduleSensorService?.updateCharacteristic(Characteristic.ContactSensorState, scheduleEnabled);
1948
+ //error sensor
1905
1949
  this.errorService?.updateCharacteristic(Characteristic.ContactSensorState, isInError);
1906
1950
 
1907
- //update presets state
1951
+ //holiday mode
1952
+ if (this.holidayModeSupport && holidayModeEnabled !== null) {
1953
+ this.holidayModeControlService?.updateCharacteristic(Characteristic.On, holidayModeEnabled);
1954
+ this.holidayModeControlSensorService?.updateCharacteristic(Characteristic.ContactSensorState, holidayModeEnabled);
1955
+ this.holidayModeSensorService?.updateCharacteristic(Characteristic.ContactSensorState, holidayModeActive);
1956
+ }
1957
+
1958
+ //presets
1908
1959
  if (this.presets.length > 0) {
1909
1960
  this.presets.forEach((preset, i) => {
1910
1961
  const presetData = presetsOnServer.find(p => p[presetsIdKey] === preset.id);
@@ -1927,18 +1978,22 @@ class DeviceAtw extends EventEmitter {
1927
1978
  });
1928
1979
  };
1929
1980
 
1930
- //update schedules state
1931
- if (this.schedules.length > 0) {
1981
+ //schedules
1982
+ if (this.schedules.length > 0 && scheduleEnabled !== null) {
1932
1983
  this.schedules.forEach((schedule, i) => {
1984
+ //control
1985
+ if (i === 0) this.schedulesControlService?.updateCharacteristic(Characteristic.On, scheduleEnabled);
1986
+
1987
+ //sensors
1933
1988
  const scheduleData = schedulesOnServer.find(s => s[presetsIdKey] === schedule.id);
1934
- schedule.state = scheduleEnabled; //scheduleData.Enabled : false;
1989
+ schedule.state = scheduleEnabled ? scheduleData.Enabled ?? false : false;
1935
1990
 
1936
1991
  const characteristicType = schedule.characteristicType;
1937
1992
  this.schedulesServices?.[i]?.updateCharacteristic(characteristicType, schedule.state);
1938
1993
  });
1939
1994
  };
1940
1995
 
1941
- //update buttons state
1996
+ //buttons
1942
1997
  if (this.buttons.length > 0) {
1943
1998
  this.buttons.forEach((button, i) => {
1944
1999
  const mode = button.mode;
package/src/deviceerv.js CHANGED
@@ -30,9 +30,8 @@ class DeviceErv extends EventEmitter {
30
30
  this.temperatureSensor = device.temperatureSensor || false;
31
31
  this.temperatureOutdoorSensor = device.temperatureOutdoorSensor || false;
32
32
  this.temperatureSupplySensor = device.temperatureSupplySensor || false;
33
- this.holidayModeSensor = device.holidayModeSensor || false;
34
- this.scheduleSensor = device.scheduleSensor || false;
35
33
  this.errorSensor = device.errorSensor || false;
34
+ this.holidayModeSupport = device.holidayModeSupport || false;
36
35
  this.presets = this.accountType === 'melcloud' ? (device.presets || []).filter(preset => (preset.displayType ?? 0) > 0 && preset.id !== '0') : [];
37
36
  this.schedules = this.accountType === 'melcloudhome' ? (device.schedules || []).filter(schedule => (schedule.displayType ?? 0) > 0 && schedule.id !== '0') : [];
38
37
  this.buttons = (device.buttonsSensors || []).filter(button => (button.displayType ?? 0) > 0);
@@ -61,8 +60,8 @@ class DeviceErv extends EventEmitter {
61
60
  //schedules configured
62
61
  for (const schedule of this.schedules) {
63
62
  schedule.name = schedule.name || 'Schedule'
64
- schedule.serviceType = [null, Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][schedule.displayType];
65
- schedule.characteristicType = [null, Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][schedule.displayType];
63
+ schedule.serviceType = [null, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][schedule.displayType];
64
+ schedule.characteristicType = [null, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][schedule.displayType];
66
65
  schedule.state = false;
67
66
  }
68
67
 
@@ -548,7 +547,7 @@ class DeviceErv extends EventEmitter {
548
547
  if (this.logDebug) this.emit('debug', `Prepare room temperature sensor service`);
549
548
  this.roomTemperatureSensorService = new Service.TemperatureSensor(`${serviceName} Room`, `Room Temperature Sensor ${deviceId}`);
550
549
  this.roomTemperatureSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
551
- this.roomTemperatureSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName} Room`);
550
+ this.roomTemperatureSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Room`);
552
551
  this.roomTemperatureSensorService.getCharacteristic(Characteristic.CurrentTemperature)
553
552
  .setProps({
554
553
  minValue: -35,
@@ -567,7 +566,7 @@ class DeviceErv extends EventEmitter {
567
566
  if (this.logDebug) this.emit('debug', `Prepare supply temperature sensor service`);
568
567
  this.supplyTemperatureSensorService = new Service.TemperatureSensor(`${serviceName} Supply`, `Supply Temperature Sensor ${deviceId}`);
569
568
  this.supplyTemperatureSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
570
- this.supplyTemperatureSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName} Supply`);
569
+ this.supplyTemperatureSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Supply`);
571
570
  this.supplyTemperatureSensorService.getCharacteristic(Characteristic.CurrentTemperature)
572
571
  .setProps({
573
572
  minValue: -35,
@@ -586,7 +585,7 @@ class DeviceErv extends EventEmitter {
586
585
  if (this.logDebug) this.emit('debug', `Prepare outdoor temperature sensor service`);
587
586
  this.outdoorTemperatureSensorService = new Service.TemperatureSensor(`${serviceName} Outdoor`, `Outdoor Temperature Sensor ${deviceId}`);
588
587
  this.outdoorTemperatureSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
589
- this.outdoorTemperatureSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName} Outdoor`);
588
+ this.outdoorTemperatureSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Outdoor`);
590
589
  this.outdoorTemperatureSensorService.getCharacteristic(Characteristic.CurrentTemperature)
591
590
  .setProps({
592
591
  minValue: -35,
@@ -604,7 +603,7 @@ class DeviceErv extends EventEmitter {
604
603
  if (this.accessory.coreMaintenanceRequired !== null) {
605
604
  this.coreMaintenanceService = new Service.FilterMaintenance(`${serviceName} Core Maintenance`, `CoreMaintenance ${deviceId}`);
606
605
  this.coreMaintenanceService.addOptionalCharacteristic(Characteristic.ConfiguredName);
607
- this.coreMaintenanceService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName} Core Maintenance`);
606
+ this.coreMaintenanceService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Core Maintenance`);
608
607
  this.coreMaintenanceService.getCharacteristic(Characteristic.FilterChangeIndication)
609
608
  .onGet(async () => {
610
609
  const value = this.accessory.coreMaintenanceRequired;
@@ -620,7 +619,7 @@ class DeviceErv extends EventEmitter {
620
619
  if (this.accessory.filterMaintenanceRequired !== null) {
621
620
  this.filterMaintenanceService = new Service.FilterMaintenance(`${serviceName} Filter Maintenance`, `FilterMaintenance ${deviceId}`);
622
621
  this.filterMaintenanceService.addOptionalCharacteristic(Characteristic.ConfiguredName);
623
- this.filterMaintenanceService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName} Filter Maintenance`);
622
+ this.filterMaintenanceService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Filter Maintenance`);
624
623
  this.filterMaintenanceService.getCharacteristic(Characteristic.FilterChangeIndication)
625
624
  .onGet(async () => {
626
625
  const value = this.accessory.filterMaintenanceRequired;
@@ -636,7 +635,7 @@ class DeviceErv extends EventEmitter {
636
635
  if (hasCO2Sensor) {
637
636
  this.carbonDioxideSensorService = new Service.CarbonDioxideSensor(`${serviceName} CO2 Sensor`, `CO2Sensor ${deviceId}`);
638
637
  this.carbonDioxideSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
639
- this.carbonDioxideSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName} CO2 Sensor`);
638
+ this.carbonDioxideSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} CO2 Sensor`);
640
639
  this.carbonDioxideSensorService.getCharacteristic(Characteristic.CarbonDioxideDetected)
641
640
  .onGet(async () => {
642
641
  const value = this.accessory.roomCO2Detected;
@@ -654,7 +653,7 @@ class DeviceErv extends EventEmitter {
654
653
  if (hasPM25Sensor) {
655
654
  this.airQualitySensorService = new Service.AirQualitySensor(`${serviceName} PM2.5 Sensor`, `PM25Sensor ${deviceId}`);
656
655
  this.airQualitySensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
657
- this.airQualitySensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName} PM2.5 Sensor`);
656
+ this.airQualitySensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} PM2.5 Sensor`);
658
657
  this.airQualitySensorService.getCharacteristic(Characteristic.AirQuality)
659
658
  .onGet(async () => {
660
659
  const value = this.accessory.pM25AirQuality;
@@ -668,34 +667,6 @@ class DeviceErv extends EventEmitter {
668
667
  accessory.addService(this.airQualitySensorService);
669
668
  }
670
669
 
671
- //holiday mode sensor
672
- if (this.holidayModeSensor && this.accessory.holidayModeEnabled !== null) {
673
- if (this.logDebug) this.emit('debug', `Prepare holiday mode service`);
674
- this.holidayModeSensorService = new Service.ContactSensor(`${serviceName} Holiday Mode`, `Holiday Mode Sensor ${deviceId}`);
675
- this.holidayModeSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
676
- this.holidayModeSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Holiday Mode`);
677
- this.holidayModeSensorService.getCharacteristic(Characteristic.ContactSensorState)
678
- .onGet(async () => {
679
- const state = this.accessory.holidayModeActive;
680
- return state;
681
- })
682
- accessory.addService(this.holidayModeSensorService);
683
- }
684
-
685
- //schedule sensor
686
- if (this.scheduleSensor && this.accessory.scheduleEnabled !== null) {
687
- if (this.logDebug) this.emit('debug', `Prepare schedule service`);
688
- this.scheduleSensorService = new Service.ContactSensor(`${serviceName} Schedule`, `Schedule Sensor ${deviceId}`);
689
- this.scheduleSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
690
- this.scheduleSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Schedule`);
691
- this.scheduleSensorService.getCharacteristic(Characteristic.ContactSensorState)
692
- .onGet(async () => {
693
- const state = this.accessory.scheduleEnabled;
694
- return state;
695
- })
696
- accessory.addService(this.scheduleSensorService);
697
- }
698
-
699
670
  //error sensor
700
671
  if (this.errorSensor && this.accessory.isInError !== null) {
701
672
  if (this.logDebug) this.emit('debug', `Prepare error service`);
@@ -710,6 +681,53 @@ class DeviceErv extends EventEmitter {
710
681
  accessory.addService(this.errorService);
711
682
  }
712
683
 
684
+ //holiday mode
685
+ if (this.holidayModeSupport && this.accessory.holidayModeEnabled !== null) {
686
+ //control
687
+ if (this.logDebug) this.emit('debug', `Prepare holiday mode control service`);
688
+ this.holidayModeControlService = new Service.Switch(`${serviceName} Holiday Mode`, `holidayModeControlService${deviceId}`);
689
+ this.holidayModeControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
690
+ this.holidayModeControlService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Holiday Mode`);
691
+ this.holidayModeControlService.getCharacteristic(Characteristic.On)
692
+ .onGet(async () => {
693
+ const state = this.accessory.holidayModeEnabled;
694
+ return state;
695
+ })
696
+ .onSet(async (state) => {
697
+ try {
698
+ deviceData.HolidayMode.Enabled = state;
699
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'holidaymode');
700
+ if (this.logInfo) this.emit('info', `Holiday mode: ${state ? 'Enabled' : 'Disabled'}`);
701
+ } catch (error) {
702
+ if (this.logWarn) this.emit('warn', `Set holiday mode error: ${error}`);
703
+ };
704
+ });
705
+ accessory.addService(this.holidayModeControlService);
706
+
707
+ if (this.logDebug) this.emit('debug', `Prepare holiday mode control sensor service`);
708
+ this.holidayModeControlSensorService = new Service.ContactSensor(`${serviceName} Holiday Mode Control`, `holidayModeControlSensorService${deviceId}`);
709
+ this.holidayModeControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
710
+ this.holidayModeControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Holiday Mode Control`);
711
+ this.holidayModeControlSensorService.getCharacteristic(Characteristic.ContactSensorState)
712
+ .onGet(async () => {
713
+ const state = this.accessory.holidayModeEnabled;
714
+ return state;
715
+ })
716
+ accessory.addService(this.holidayModeControlSensorService);
717
+
718
+ //sensors
719
+ if (this.logDebug) this.emit('debug', `Prepare holiday mode sensor service`);
720
+ this.holidayModeSensorService = new Service.ContactSensor(`${serviceName} Holiday Mode`, `holidayModeSensorService${deviceId}`);
721
+ this.holidayModeSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
722
+ this.holidayModeSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Holiday Mode State`);
723
+ this.holidayModeSensorService.getCharacteristic(Characteristic.ContactSensorState)
724
+ .onGet(async () => {
725
+ const state = this.accessory.holidayModeActive;
726
+ return state;
727
+ })
728
+ accessory.addService(this.holidayModeSensorService);
729
+ }
730
+
713
731
  //presets services
714
732
  if (this.presets.length > 0) {
715
733
  if (this.logDebug) this.emit('debug', `Prepare presets services`);
@@ -766,7 +784,7 @@ class DeviceErv extends EventEmitter {
766
784
  };
767
785
 
768
786
  //schedules services
769
- if (this.schedules.length > 0) {
787
+ if (this.schedules.length > 0 && this.accessory.scheduleEnabled !== null) {
770
788
  if (this.logDebug) this.emit('debug', `Prepare schedules services`);
771
789
  this.schedulesServices = [];
772
790
  this.schedules.forEach((schedule, i) => {
@@ -776,25 +794,52 @@ class DeviceErv extends EventEmitter {
776
794
  //get preset name prefix
777
795
  const namePrefix = schedule.namePrefix;
778
796
 
797
+ //control
798
+ if (i === 0) {
799
+ if (this.logDebug) this.emit('debug', `Prepare schedule control service`);
800
+ const serviceNameSchedule = namePrefix ? `${accessoryName} Schedule Control` : `Schedule Control`;
801
+ this.schedulesControlService = new Service.Switch(serviceNameSchedule, `Schedule Control ${deviceId} ${i}`);
802
+ this.schedulesControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
803
+ this.schedulesControlService.setCharacteristic(Characteristic.ConfiguredName, serviceNameSchedule);
804
+ this.schedulesControlService.getCharacteristic(Characteristic.On)
805
+ .onGet(async () => {
806
+ const state = this.accessory.scheduleEnabled;
807
+ return state;
808
+ })
809
+ .onSet(async (state) => {
810
+ try {
811
+ deviceData.ScheduleEnabled = state;
812
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'schedule');
813
+ if (this.logInfo) this.emit('info', `Schedule: ${state ? 'Enabled' : 'Disabled'}`);
814
+ } catch (error) {
815
+ if (this.logWarn) this.emit('warn', `Set schedule error: ${error}`);
816
+ };
817
+ });
818
+ accessory.addService(this.schedulesControlService);
819
+
820
+ if (this.logDebug) this.emit('debug', `Prepare schedule control sensor service`);
821
+ this.scheduleSensorService = new Service.ContactSensor(serviceNameSchedule, `Schedule Control Sensor ${deviceId}`);
822
+ this.scheduleSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
823
+ this.scheduleSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceNameSchedule);
824
+ this.scheduleSensorService.getCharacteristic(Characteristic.ContactSensorState)
825
+ .onGet(async () => {
826
+ const state = this.accessory.scheduleEnabled;
827
+ return state;
828
+ })
829
+ accessory.addService(this.scheduleSensorService);
830
+ }
831
+
832
+ //sensors
779
833
  const serviceName = namePrefix ? `${accessoryName} ${name}` : name;
780
834
  const serviceType = schedule.serviceType;
781
835
  const characteristicType = schedule.characteristicType;
782
- const scheduleService = new serviceType(serviceName, `Schedule ${deviceId} ${i}`);
836
+ const scheduleService = new serviceType(serviceName, `Schedule Sensor ${deviceId} ${i}`);
783
837
  scheduleService.addOptionalCharacteristic(Characteristic.ConfiguredName);
784
838
  scheduleService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
785
839
  scheduleService.getCharacteristic(characteristicType)
786
840
  .onGet(async () => {
787
841
  const state = schedule.state;
788
842
  return state;
789
- })
790
- .onSet(async (state) => {
791
- try {
792
- deviceData.ScheduleEnabled = state;
793
- await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'scheduleenabled');
794
- if (this.logInfo) this.emit('info', `${state ? 'Set:' : 'Unset:'} ${name}`);
795
- } catch (error) {
796
- if (this.logWarn) this.emit('warn', `Set schedule error: ${error}`);
797
- };
798
843
  });
799
844
  this.schedulesServices.push(scheduleService);
800
845
  accessory.addService(scheduleService);
@@ -962,7 +1007,7 @@ class DeviceErv extends EventEmitter {
962
1007
  const schedulesOnServer = deviceData.Schedule ?? [];
963
1008
  const presetsOnServer = deviceData.Presets ?? [];
964
1009
  const holidayModeEnabled = deviceData.HolidayMode?.Enabled;
965
- const holidayModeActive = deviceData.HolidayMode?.Active;
1010
+ const holidayModeActive = deviceData.HolidayMode?.Active ?? false;
966
1011
 
967
1012
  //device control
968
1013
  const hideRoomTemperature = deviceData.HideRoomTemperature;
@@ -1194,11 +1239,16 @@ class DeviceErv extends EventEmitter {
1194
1239
  .updateCharacteristic(Characteristic.PM2_5Density, pM25Level);
1195
1240
 
1196
1241
  //error sensor
1197
- this.holidayModeSensorService?.updateCharacteristic(Characteristic.ContactSensorState, holidayModeActive);
1198
- this.scheduleSensorService?.updateCharacteristic(Characteristic.ContactSensorState, scheduleEnabled);
1199
1242
  this.errorService?.updateCharacteristic(Characteristic.ContactSensorState, isInError);
1200
1243
 
1201
- //update presets state
1244
+ //holiday mode
1245
+ if (this.holidayModeSupport && holidayModeEnabled !== null) {
1246
+ this.holidayModeControlService?.updateCharacteristic(Characteristic.On, holidayModeEnabled);
1247
+ this.holidayModeControlSensorService?.updateCharacteristic(Characteristic.ContactSensorState, holidayModeEnabled);
1248
+ this.holidayModeSensorService?.updateCharacteristic(Characteristic.ContactSensorState, holidayModeActive);
1249
+ }
1250
+
1251
+ //presets
1202
1252
  if (this.presets.length > 0) {
1203
1253
  this.presets.forEach((preset, i) => {
1204
1254
  const presetData = presetsOnServer.find(p => p[presetsIdKey] === preset.id);
@@ -1214,18 +1264,22 @@ class DeviceErv extends EventEmitter {
1214
1264
  });
1215
1265
  };
1216
1266
 
1217
- //update schedules state
1218
- if (this.schedules.length > 0) {
1267
+ //schedules
1268
+ if (this.schedules.length > 0 && scheduleEnabled !== null) {
1219
1269
  this.schedules.forEach((schedule, i) => {
1270
+ //control
1271
+ if (i === 0) this.schedulesControlService?.updateCharacteristic(Characteristic.On, scheduleEnabled);
1272
+
1273
+ //sensors
1220
1274
  const scheduleData = schedulesOnServer.find(s => s[presetsIdKey] === schedule.id);
1221
- schedule.state = scheduleEnabled; //scheduleData.Enabled : false;
1275
+ schedule.state = scheduleEnabled ? scheduleData.Enabled ?? false : false;
1222
1276
 
1223
1277
  const characteristicType = schedule.characteristicType;
1224
1278
  this.schedulesServices?.[i]?.updateCharacteristic(characteristicType, schedule.state);
1225
1279
  });
1226
1280
  };
1227
1281
 
1228
- //update buttons state
1282
+ //buttons
1229
1283
  if (this.buttons.length > 0) {
1230
1284
  this.buttons.forEach((button, i) => {
1231
1285
  const mode = button.mode;;
package/src/melcloud.js CHANGED
@@ -168,7 +168,7 @@ class MelCloud extends EventEmitter {
168
168
  const loginData = account.LoginData ?? [];
169
169
  const contextKey = loginData.ContextKey;
170
170
 
171
- const debugData = {
171
+ const safeConfig = {
172
172
  ...loginData,
173
173
  ContextKey: 'removed',
174
174
  ClientId: 'removed',
@@ -177,7 +177,7 @@ class MelCloud extends EventEmitter {
177
177
  MapLongitude: 'removed',
178
178
  MapLatitude: 'removed'
179
179
  };
180
- if (this.logDebug) this.emit('debug', `MELCloud Info: ${JSON.stringify(debugData, null, 2)}`);
180
+ if (this.logDebug) this.emit('debug', `MELCloud Info: ${JSON.stringify(safeConfig, null, 2)}`);
181
181
 
182
182
  if (!contextKey) {
183
183
  accountInfo.Info = 'Context key missing'