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/deviceata.js CHANGED
@@ -29,11 +29,10 @@ class DeviceAta extends EventEmitter {
29
29
  this.displayType = device.displayType;
30
30
  this.temperatureSensor = device.temperatureSensor || false;
31
31
  this.temperatureOutdoorSensor = device.temperatureOutdoorSensor || false;
32
- this.frostProtectionSensor = device.frostProtectionSensor || false;
33
- this.overheatProtectionSensor = device.overheatProtectionSensor || false;
34
- this.holidayModeSensor = device.holidayModeSensor || false;
35
- this.scheduleSensor = device.scheduleSensor || false;
36
32
  this.errorSensor = device.errorSensor || false;
33
+ this.frostProtectionSupport = device.frostProtectionSupport || false;
34
+ this.overheatProtectionSupport = device.overheatProtectionSupport || false;
35
+ this.holidayModeSupport = device.holidayModeSupport || false;
37
36
  this.heatDryFanMode = device.heatDryFanMode || 1; //NONE, HEAT, DRY, FAN
38
37
  this.coolDryFanMode = device.coolDryFanMode || 1; //NONE, COOL, DRY, FAN
39
38
  this.autoDryFanMode = device.autoDryFanMode || 1; //NONE, AUTO, DRY, FAN
@@ -65,8 +64,8 @@ class DeviceAta extends EventEmitter {
65
64
  //schedules configured
66
65
  for (const schedule of this.schedules) {
67
66
  schedule.name = schedule.name || 'Schedule'
68
- schedule.serviceType = [null, Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][schedule.displayType];
69
- schedule.characteristicType = [null, Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][schedule.displayType];
67
+ schedule.serviceType = [null, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][schedule.displayType];
68
+ schedule.characteristicType = [null, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][schedule.displayType];
70
69
  schedule.state = false;
71
70
  }
72
71
 
@@ -619,12 +618,59 @@ class DeviceAta extends EventEmitter {
619
618
  accessory.addService(this.outdoorTemperatureSensorService);
620
619
  };
621
620
 
622
- //frost protection sensor
623
- if (this.frostProtectionSensor && this.accessory.frostProtectionEnabled) {
621
+ //error sensor
622
+ if (this.errorSensor && this.accessory.isInError !== null) {
623
+ if (this.logDebug) this.emit('debug', `Prepare error service`);
624
+ this.errorService = new Service.ContactSensor(`${serviceName} Error`, `Error Sensor ${deviceId}`);
625
+ this.errorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
626
+ this.errorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Error`);
627
+ this.errorService.getCharacteristic(Characteristic.ContactSensorState)
628
+ .onGet(async () => {
629
+ const state = this.accessory.isInError;
630
+ return state;
631
+ })
632
+ accessory.addService(this.errorService);
633
+ }
634
+
635
+ //frost protection
636
+ if (this.frostProtectionSupport && this.accessory.frostProtectionEnabled !== null) {
637
+ //control
638
+ if (this.logDebug) this.emit('debug', `Prepare frost protection control service`);
639
+ this.frostProtectionControlService = new Service.Switch(`${serviceName} Frost Protection`, `frostProtectionControlService${deviceId}`);
640
+ this.frostProtectionControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
641
+ this.frostProtectionControlService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Frost Protection`);
642
+ this.frostProtectionControlService.getCharacteristic(Characteristic.On)
643
+ .onGet(async () => {
644
+ const state = this.accessory.frostProtectionEnabled;
645
+ return state;
646
+ })
647
+ .onSet(async (state) => {
648
+ try {
649
+ deviceData.FrostProtection.Enabled = state;
650
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'frostprotection');
651
+ if (this.logInfo) this.emit('info', `Frost protection: ${state ? 'Enabled' : 'Disabled'}`);
652
+ } catch (error) {
653
+ if (this.logWarn) this.emit('warn', `Set frost protection error: ${error}`);
654
+ };
655
+ });
656
+ accessory.addService(this.frostProtectionControlService);
657
+
658
+ if (this.logDebug) this.emit('debug', `Prepare frost protection control sensor service`);
659
+ this.frostProtectionControlSensorService = new Service.ContactSensor(`${serviceName} Frost Protection Control`, `frostProtectionControlSensorService${deviceId}`);
660
+ this.frostProtectionControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
661
+ this.frostProtectionControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Frost Protection Control`);
662
+ this.frostProtectionControlSensorService.getCharacteristic(Characteristic.ContactSensorState)
663
+ .onGet(async () => {
664
+ const state = this.accessory.frostProtectionEnabled;
665
+ return state;
666
+ })
667
+ accessory.addService(this.frostProtectionControlSensorService);
668
+
669
+ //sensor
624
670
  if (this.logDebug) this.emit('debug', `Prepare frost protection service`);
625
- this.frostProtectionSensorService = new Service.ContactSensor(`${serviceName} Frost Protection`, `Frost Protection Sensor ${deviceId}`);
671
+ this.frostProtectionSensorService = new Service.ContactSensor(`${serviceName} Frost Protection`, `frostProtectionSensorService${deviceId}`);
626
672
  this.frostProtectionSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
627
- this.frostProtectionSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Frost Protection`);
673
+ this.frostProtectionSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Frost Protection State`);
628
674
  this.frostProtectionSensorService.getCharacteristic(Characteristic.ContactSensorState)
629
675
  .onGet(async () => {
630
676
  const state = this.accessory.frostProtectionActive;
@@ -633,12 +679,44 @@ class DeviceAta extends EventEmitter {
633
679
  accessory.addService(this.frostProtectionSensorService);
634
680
  }
635
681
 
636
- //overheat sensor
637
- if (this.overheatProtectionSensor && this.accessory.overheatProtectionEnabled !== null) {
638
- if (this.logDebug) this.emit('debug', `Prepare overheat protection service`);
639
- this.overheatProtectionSensorService = new Service.ContactSensor(`${serviceName} Overheat Protection`, `Overheat Protection Sensor ${deviceId}`);
682
+ //overheat protection
683
+ if (this.overheatProtectionSupport && this.accessory.overheatProtectionEnabled !== null) {
684
+ //control
685
+ if (this.logDebug) this.emit('debug', `Prepare overheat protection control service`);
686
+ this.overheatProtectionControlService = new Service.Switch(`${serviceName} Overheat Protection`, `overheatProtectionControlService${deviceId}`);
687
+ this.overheatProtectionControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
688
+ this.overheatProtectionControlService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Overheat Protection`);
689
+ this.overheatProtectionControlService.getCharacteristic(Characteristic.On)
690
+ .onGet(async () => {
691
+ const state = this.accessory.overheatProtectionEnabled;
692
+ return state;
693
+ })
694
+ .onSet(async (state) => {
695
+ try {
696
+ deviceData.OverheatProtection.Enabled = state;
697
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'overheatprotection');
698
+ if (this.logInfo) this.emit('info', `Overheat protection: ${state ? 'Enabled' : 'Disabled'}`);
699
+ } catch (error) {
700
+ if (this.logWarn) this.emit('warn', `Set overheat protection error: ${error}`);
701
+ };
702
+ });
703
+ accessory.addService(this.overheatProtectionControlService);
704
+
705
+ if (this.logDebug) this.emit('debug', `Prepare overheat protection control sensor service`);
706
+ this.overheatProtectionControlSensorService = new Service.ContactSensor(`${serviceName} Overheat Protection Control`, `overheatProtectionControlSensorService${deviceId}`);
707
+ this.overheatProtectionControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
708
+ this.overheatProtectionControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Overheat Protection Control`);
709
+ this.overheatProtectionControlSensorService.getCharacteristic(Characteristic.ContactSensorState)
710
+ .onGet(async () => {
711
+ const state = this.accessory.overheatProtectionEnabled;
712
+ return state;
713
+ })
714
+ accessory.addService(this.overheatProtectionControlSensorService);
715
+
716
+ if (this.logDebug) this.emit('debug', `Prepare overheat protection sensor service`);
717
+ this.overheatProtectionSensorService = new Service.ContactSensor(`${serviceName} Overheat Protection`, `overheatProtectionSensorService${deviceId}`);
640
718
  this.overheatProtectionSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
641
- this.overheatProtectionSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Overheat Protection`);
719
+ this.overheatProtectionSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Overheat Protection State`);
642
720
  this.overheatProtectionSensorService.getCharacteristic(Characteristic.ContactSensorState)
643
721
  .onGet(async () => {
644
722
  const state = this.accessory.overheatProtectionActive;
@@ -647,46 +725,51 @@ class DeviceAta extends EventEmitter {
647
725
  accessory.addService(this.overheatProtectionSensorService);
648
726
  }
649
727
 
650
- //holiday mode sensor
651
- if (this.holidayModeSensor && this.accessory.holidayModeEnabled !== null) {
652
- if (this.logDebug) this.emit('debug', `Prepare holiday mode service`);
653
- this.holidayModeSensorService = new Service.ContactSensor(`${serviceName} Holiday Mode`, `Holiday Mode Sensor ${deviceId}`);
654
- this.holidayModeSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
655
- this.holidayModeSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Holiday Mode`);
656
- this.holidayModeSensorService.getCharacteristic(Characteristic.ContactSensorState)
728
+ //holiday mode
729
+ if (this.holidayModeSupport && this.accessory.holidayModeEnabled !== null) {
730
+ //control
731
+ if (this.logDebug) this.emit('debug', `Prepare holiday mode control service`);
732
+ this.holidayModeControlService = new Service.Switch(`${serviceName} Holiday Mode`, `holidayModeControlService${deviceId}`);
733
+ this.holidayModeControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
734
+ this.holidayModeControlService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Holiday Mode`);
735
+ this.holidayModeControlService.getCharacteristic(Characteristic.On)
657
736
  .onGet(async () => {
658
- const state = this.accessory.holidayModeActive;
737
+ const state = this.accessory.holidayModeEnabled;
659
738
  return state;
660
739
  })
661
- accessory.addService(this.holidayModeSensorService);
662
- }
663
-
664
- //schedule sensor
665
- if (this.scheduleSensor && this.accessory.scheduleEnabled !== null) {
666
- if (this.logDebug) this.emit('debug', `Prepare schedule service`);
667
- this.scheduleSensorService = new Service.ContactSensor(`${serviceName} Schedule`, `Schedule Sensor ${deviceId}`);
668
- this.scheduleSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
669
- this.scheduleSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Schedule`);
670
- this.scheduleSensorService.getCharacteristic(Characteristic.ContactSensorState)
740
+ .onSet(async (state) => {
741
+ try {
742
+ deviceData.HolidayMode.Enabled = state;
743
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'holidaymode');
744
+ if (this.logInfo) this.emit('info', `Holiday mode: ${state ? 'Enabled' : 'Disabled'}`);
745
+ } catch (error) {
746
+ if (this.logWarn) this.emit('warn', `Set holiday mode error: ${error}`);
747
+ };
748
+ });
749
+ accessory.addService(this.holidayModeControlService);
750
+
751
+ if (this.logDebug) this.emit('debug', `Prepare holiday mode control sensor service`);
752
+ this.holidayModeControlSensorService = new Service.ContactSensor(`${serviceName} Holiday Mode Control`, `holidayModeControlSensorService${deviceId}`);
753
+ this.holidayModeControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
754
+ this.holidayModeControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Holiday Mode Control`);
755
+ this.holidayModeControlSensorService.getCharacteristic(Characteristic.ContactSensorState)
671
756
  .onGet(async () => {
672
- const state = this.accessory.scheduleEnabled;
757
+ const state = this.accessory.holidayModeEnabled;
673
758
  return state;
674
759
  })
675
- accessory.addService(this.scheduleSensorService);
676
- }
760
+ accessory.addService(this.holidayModeControlSensorService);
677
761
 
678
- //error sensor
679
- if (this.errorSensor && this.accessory.isInError !== null) {
680
- if (this.logDebug) this.emit('debug', `Prepare error service`);
681
- this.errorService = new Service.ContactSensor(`${serviceName} Error`, `Error Sensor ${deviceId}`);
682
- this.errorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
683
- this.errorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Error`);
684
- this.errorService.getCharacteristic(Characteristic.ContactSensorState)
762
+ //sensors
763
+ if (this.logDebug) this.emit('debug', `Prepare holiday mode sensor service`);
764
+ this.holidayModeSensorService = new Service.ContactSensor(`${serviceName} Holiday Mode`, `holidayModeSensorService${deviceId}`);
765
+ this.holidayModeSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
766
+ this.holidayModeSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Holiday Mode State`);
767
+ this.holidayModeSensorService.getCharacteristic(Characteristic.ContactSensorState)
685
768
  .onGet(async () => {
686
- const state = this.accessory.isInError;
769
+ const state = this.accessory.holidayModeActive;
687
770
  return state;
688
771
  })
689
- accessory.addService(this.errorService);
772
+ accessory.addService(this.holidayModeSensorService);
690
773
  }
691
774
 
692
775
  //presets services
@@ -747,7 +830,7 @@ class DeviceAta extends EventEmitter {
747
830
  };
748
831
 
749
832
  //schedules services
750
- if (this.schedules.length > 0) {
833
+ if (this.schedules.length > 0 && this.accessory.scheduleEnabled !== null) {
751
834
  if (this.logDebug) this.emit('debug', `Prepare schedules services`);
752
835
  this.schedulesServices = [];
753
836
  this.schedules.forEach((schedule, i) => {
@@ -757,25 +840,52 @@ class DeviceAta extends EventEmitter {
757
840
  //get preset name prefix
758
841
  const namePrefix = schedule.namePrefix;
759
842
 
843
+ //control
844
+ if (i === 0) {
845
+ if (this.logDebug) this.emit('debug', `Prepare schedule control service`);
846
+ const serviceNameSchedule = namePrefix ? `${accessoryName} Schedule Control` : `Schedule Control`;
847
+ this.schedulesControlService = new Service.Switch(serviceNameSchedule, `schedulesControlService${deviceId} ${i}`);
848
+ this.schedulesControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
849
+ this.schedulesControlService.setCharacteristic(Characteristic.ConfiguredName, serviceNameSchedule);
850
+ this.schedulesControlService.getCharacteristic(Characteristic.On)
851
+ .onGet(async () => {
852
+ const state = this.accessory.scheduleEnabled;
853
+ return state;
854
+ })
855
+ .onSet(async (state) => {
856
+ try {
857
+ deviceData.ScheduleEnabled = state;
858
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'schedule');
859
+ if (this.logInfo) this.emit('info', `Schedule: ${state ? 'Enabled' : 'Disabled'}`);
860
+ } catch (error) {
861
+ if (this.logWarn) this.emit('warn', `Set schedule error: ${error}`);
862
+ };
863
+ });
864
+ accessory.addService(this.schedulesControlService);
865
+
866
+ if (this.logDebug) this.emit('debug', `Prepare schedule control sensor service`);
867
+ this.schedulesControlSensorService = new Service.ContactSensor(serviceNameSchedule, `schedulesControlSensorService${deviceId}`);
868
+ this.schedulesControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
869
+ this.schedulesControlSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceNameSchedule);
870
+ this.schedulesControlSensorService.getCharacteristic(Characteristic.ContactSensorState)
871
+ .onGet(async () => {
872
+ const state = this.accessory.scheduleEnabled;
873
+ return state;
874
+ })
875
+ accessory.addService(this.schedulesControlSensorService);
876
+ }
877
+
878
+ //sensors
760
879
  const serviceName = namePrefix ? `${accessoryName} ${name}` : name;
761
880
  const serviceType = schedule.serviceType;
762
881
  const characteristicType = schedule.characteristicType;
763
- const scheduleService = new serviceType(serviceName, `Schedule ${deviceId} ${i}`);
882
+ const scheduleService = new serviceType(serviceName, `scheduleService${deviceId} ${i}`);
764
883
  scheduleService.addOptionalCharacteristic(Characteristic.ConfiguredName);
765
884
  scheduleService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
766
885
  scheduleService.getCharacteristic(characteristicType)
767
886
  .onGet(async () => {
768
887
  const state = schedule.state;
769
888
  return state;
770
- })
771
- .onSet(async (state) => {
772
- try {
773
- deviceData.ScheduleEnabled = state;
774
- await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'scheduleenabled');
775
- if (this.logInfo) this.emit('info', `${state ? 'Set:' : 'Unset:'} ${name}`);
776
- } catch (error) {
777
- if (this.logWarn) this.emit('warn', `Set schedule error: ${error}`);
778
- };
779
889
  });
780
890
  this.schedulesServices.push(scheduleService);
781
891
  accessory.addService(scheduleService);
@@ -1060,8 +1170,6 @@ class DeviceAta extends EventEmitter {
1060
1170
  this.deviceData = deviceData;
1061
1171
 
1062
1172
  //keys
1063
- const presetsIdKey = this.accountType === 'melcloud' ? 'ID' : 'Id';
1064
- const setTempKey = this.accountType === 'melcloud' ? 'SetTemperature' : 'SetPoint';
1065
1173
  const fanKey = this.accountType === 'melcloud' ? 'FanSpeed' : 'SetFanSpeed';
1066
1174
  const tempStepKey = this.accountType === 'melcloud' ? 'TemperatureIncrement' : 'HasHalfDegreeIncrements';
1067
1175
  const errorKey = this.accountType === 'melcloud' ? 'HasError' : 'IsInError';
@@ -1073,19 +1181,18 @@ class DeviceAta extends EventEmitter {
1073
1181
  const supportDryKey = this.accountType === 'melcloud' ? 'ModelSupportsDry' : 'HasDryOperationMode';
1074
1182
  const supportCoolKey = this.accountType === 'melcloud' ? 'ModelSupportsCool' : 'HasCoolOperationMode';
1075
1183
 
1076
- //presets schedule
1184
+ //presets schedules
1077
1185
  const scheduleEnabled = deviceData.ScheduleEnabled;
1078
1186
  const schedulesOnServer = deviceData.Schedule ?? [];
1079
1187
  const presetsOnServer = deviceData.Presets ?? [];
1080
1188
  const holidayModeEnabled = deviceData.HolidayMode?.Enabled;
1081
- const holidayModeActive = deviceData.HolidayMode?.Active;
1082
-
1189
+ const holidayModeActive = deviceData.HolidayMode?.Active ?? false;
1083
1190
 
1084
1191
  //protection
1085
1192
  const frostProtectionEnabled = deviceData.FrostProtection?.Enabled;
1086
- const frostProtectionActive = deviceData.FrostProtection?.Active;
1193
+ const frostProtectionActive = deviceData.FrostProtection?.Active ?? false;
1087
1194
  const overheatProtectionEnabled = deviceData.OverheatProtection?.Enabled;
1088
- const overheatProtectionActive = deviceData.OverheatProtection?.Active;
1195
+ const overheatProtectionActive = deviceData.OverheatProtection?.Active ?? false;
1089
1196
 
1090
1197
  //device control
1091
1198
  const hideVaneControls = deviceData.HideVaneControls ?? false;
@@ -1319,18 +1426,36 @@ class DeviceAta extends EventEmitter {
1319
1426
  };
1320
1427
  this.accessory = obj;
1321
1428
 
1429
+ //senors
1322
1430
  this.roomTemperatureSensorService?.updateCharacteristic(Characteristic.CurrentTemperature, roomTemperature);
1323
1431
  this.outdoorTemperatureSensorService?.updateCharacteristic(Characteristic.CurrentTemperature, outdoorTemperature);
1324
- this.frostProtectionSensorService?.updateCharacteristic(Characteristic.ContactSensorState, frostProtectionActive);
1325
- this.overheatProtectionSensorService?.updateCharacteristic(Characteristic.ContactSensorState, overheatProtectionActive);
1326
- this.holidayModeSensorService?.updateCharacteristic(Characteristic.ContactSensorState, holidayModeActive);
1327
- this.scheduleSensorService?.updateCharacteristic(Characteristic.ContactSensorState, scheduleEnabled);
1328
1432
  this.errorService?.updateCharacteristic(Characteristic.ContactSensorState, isInError);
1329
1433
 
1330
- //update presets state
1434
+ //frost protection
1435
+ if (this.frostProtectionSupport && frostProtectionEnabled !== null) {
1436
+ this.frostProtectionControlService?.updateCharacteristic(Characteristic.On, frostProtectionEnabled);
1437
+ this.frostProtectionControlSensorService?.updateCharacteristic(Characteristic.ContactSensorState, frostProtectionEnabled);
1438
+ this.frostProtectionSensorService?.updateCharacteristic(Characteristic.ContactSensorState, frostProtectionActive);
1439
+ }
1440
+
1441
+ //overheat protection
1442
+ if (this.overheatProtectionSupport && overheatProtectionEnabled !== null) {
1443
+ this.overheatProtectionControlService?.updateCharacteristic(Characteristic.On, overheatProtectionEnabled);
1444
+ this.overheatProtectionControlSensorService?.updateCharacteristic(Characteristic.ContactSensorState, overheatProtectionEnabled);
1445
+ this.overheatProtectionSensorService?.updateCharacteristic(Characteristic.ContactSensorState, overheatProtectionActive);
1446
+ }
1447
+
1448
+ //holiday mode
1449
+ if (this.holidayModeSupport && holidayModeEnabled !== null) {
1450
+ this.holidayModeControlService?.updateCharacteristic(Characteristic.On, holidayModeEnabled);
1451
+ this.holidayModeControlSensorService?.updateCharacteristic(Characteristic.ContactSensorState, holidayModeEnabled);
1452
+ this.holidayModeSensorService?.updateCharacteristic(Characteristic.ContactSensorState, holidayModeActive);
1453
+ }
1454
+
1455
+ //presets
1331
1456
  if (this.presets.length > 0) {
1332
1457
  this.presets.forEach((preset, i) => {
1333
- const presetData = presetsOnServer.find(p => p[presetsIdKey] === preset.id);
1458
+ const presetData = presetsOnServer.find(p => p.ID === preset.id);
1334
1459
 
1335
1460
  preset.state = presetData ? (presetData.Power === power
1336
1461
  && presetData.SetTemperature === setTemperature
@@ -1344,18 +1469,25 @@ class DeviceAta extends EventEmitter {
1344
1469
  });
1345
1470
  };
1346
1471
 
1347
- //update schedules state
1348
- if (this.schedules.length > 0) {
1472
+ //schedules
1473
+ if (this.schedules.length > 0 && scheduleEnabled !== null) {
1349
1474
  this.schedules.forEach((schedule, i) => {
1350
- const scheduleData = schedulesOnServer.find(s => s[presetsIdKey] === schedule.id);
1351
- schedule.state = scheduleEnabled; //scheduleData.Enabled : false;
1475
+ //control
1476
+ if (i === 0) {
1477
+ this.schedulesControlService?.updateCharacteristic(Characteristic.On, scheduleEnabled);
1478
+ this.schedulesControlSensorService?.updateCharacteristic(Characteristic.ContactSensorState, scheduleEnabled);
1479
+ }
1480
+
1481
+ //sensors
1482
+ const scheduleData = schedulesOnServer.find(s => s.Id === schedule.id);
1483
+ schedule.state = scheduleEnabled ? scheduleData.Enabled ?? false : false;
1352
1484
 
1353
1485
  const characteristicType = schedule.characteristicType;
1354
1486
  this.schedulesServices?.[i]?.updateCharacteristic(characteristicType, schedule.state);
1355
1487
  });
1356
1488
  };
1357
1489
 
1358
- //update buttons state
1490
+ //buttons
1359
1491
  if (this.buttons.length > 0) {
1360
1492
  this.buttons.forEach((button, i) => {
1361
1493
  const mode = button.mode;