eufy-security-client 2.2.1 → 2.2.3

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.
@@ -125,6 +125,7 @@ export interface HTTPApiEvents {
125
125
  "houses": (houses: Houses) => void;
126
126
  "connect": () => void;
127
127
  "close": () => void;
128
+ "connection error": (error: Error) => void;
128
129
  "tfa request": () => void;
129
130
  "captcha request": (id: string, captcha: string) => void;
130
131
  "auth token invalidated": () => void;
@@ -175,6 +176,7 @@ export interface DeviceEvents {
175
176
  "pet detected": (device: Device, state: boolean) => void;
176
177
  "sound detected": (device: Device, state: boolean) => void;
177
178
  "crying detected": (device: Device, state: boolean) => void;
179
+ "vehicle detected": (device: Device, state: boolean) => void;
178
180
  "rings": (device: Device, state: boolean) => void;
179
181
  "locked": (device: Device, state: boolean) => void;
180
182
  "open": (device: Device, state: boolean) => void;
@@ -18,7 +18,12 @@ class ParameterHelper {
18
18
  type === types_1.CommandType.ARM_DELAY_CUS3 ||
19
19
  type === types_1.CommandType.ARM_DELAY_OFF) {
20
20
  try {
21
- return JSON.parse((0, utils_1.decodeBase64)(value).toString("utf8"));
21
+ if (typeof value === "string") {
22
+ return JSON.parse((0, utils_1.decodeBase64)(value).toString("utf8"));
23
+ }
24
+ else {
25
+ return value; //return object
26
+ }
22
27
  }
23
28
  catch (error) {
24
29
  log.error(`Error readValue param ${type} `, error, type, value);
@@ -1 +1 @@
1
- {"version":3,"file":"parameter.js","sourceRoot":"","sources":["../../src/http/parameter.ts"],"names":[],"mappings":";;;AAEA,wCAA2C;AAC3C,wCAA4C;AAC5C,mCAAoC;AAEpC,MAAa,eAAe;IAEjB,MAAM,CAAC,SAAS,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW;QAC5D,IAAI,KAAK,EAAE;YACP,IAAI,IAAI,KAAK,iBAAS,CAAC,WAAW;gBAC9B,IAAI,KAAK,iBAAS,CAAC,mBAAmB;gBACtC,IAAI,KAAK,mBAAW,CAAC,oCA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OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,MAAM,CAAC,UAAU,CAAC,IAAY,EAAE,KAAa;QAChD,IAAI,KAAK,EAAE;YACP,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YACrC,IAAI,IAAI,KAAK,iBAAS,CAAC,WAAW;gBAC9B,IAAI,KAAK,iBAAS,CAAC,mBAAmB;gBACtC,IAAI,KAAK,mBAAW,CAAC,oCAAoC;gBACzD,IAAI,KAAK,mBAAW,CAAC,8BAA8B,EAAE;gBACrD,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;aACjD;YACD,OAAO,MAAM,CAAC;SACjB;QACD,OAAO,EAAE,CAAC;IACd,CAAC;CAEJ;AA/DD,0CA+DC"}
@@ -30,6 +30,7 @@ export declare class Station extends TypedEmitter<StationEvents> {
30
30
  update(station: StationListResponse, cloudOnlyProperties?: boolean): void;
31
31
  updateProperty(name: string, value: PropertyValue): boolean;
32
32
  updateRawProperties(values: RawValues): void;
33
+ protected handlePropertyChange(metadata: PropertyMetadataAny, oldValue: PropertyValue, newValue: PropertyValue): void;
33
34
  updateRawProperty(type: number, value: string): boolean;
34
35
  protected convertRawPropertyValue(property: PropertyMetadataAny, value: string): PropertyValue;
35
36
  getPropertyMetadata(name: string): PropertyMetadataAny;
@@ -113,9 +113,21 @@ class Station extends tiny_typed_emitter_1.TypedEmitter {
113
113
  updateProperty(name, value) {
114
114
  if ((this.properties[name] !== undefined && this.properties[name] !== value)
115
115
  || this.properties[name] === undefined) {
116
+ const oldValue = this.properties[name];
116
117
  this.properties[name] = value;
117
118
  if (this.ready)
118
119
  this.emit("property changed", this, name, value);
120
+ try {
121
+ this.handlePropertyChange(this.getPropertyMetadata(name), oldValue, this.properties[name]);
122
+ }
123
+ catch (error) {
124
+ if (error instanceof error_2.InvalidPropertyError) {
125
+ this.log.error(`Invalid Property ${name} error`, error);
126
+ }
127
+ else {
128
+ this.log.error(`Property ${name} error`, error);
129
+ }
130
+ }
119
131
  return true;
120
132
  }
121
133
  return false;
@@ -126,6 +138,31 @@ class Station extends tiny_typed_emitter_1.TypedEmitter {
126
138
  this.updateRawProperty(param_type, values[param_type]);
127
139
  });
128
140
  }
141
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
142
+ handlePropertyChange(metadata, oldValue, newValue) {
143
+ if (metadata.name === types_1.PropertyName.StationCurrentMode) {
144
+ //TODO: Finish implementation!
145
+ if (newValue === types_1.AlarmMode.DISARMED) {
146
+ if (this.hasProperty(types_1.PropertyName.StationAlarmArmed)) {
147
+ this.updateProperty(types_1.PropertyName.StationAlarmArmed, false);
148
+ }
149
+ if (this.hasProperty(types_1.PropertyName.StationAlarmDelay)) {
150
+ this.updateProperty(types_1.PropertyName.StationAlarmDelay, 0);
151
+ }
152
+ if (this.hasProperty(types_1.PropertyName.StationAlarmDelayType)) {
153
+ this.updateProperty(types_1.PropertyName.StationAlarmDelayType, 0);
154
+ }
155
+ if (this.hasProperty(types_1.PropertyName.StationAlarm)) {
156
+ this.updateProperty(types_1.PropertyName.StationAlarm, false);
157
+ }
158
+ if (this.hasProperty(types_1.PropertyName.StationAlarmType)) {
159
+ this.updateProperty(types_1.PropertyName.StationAlarmType, 0);
160
+ }
161
+ } /*else if (this.hasProperty(PropertyName.StationAlarmArmed)) { //TODO: Type !== HB3 or STATION
162
+ this.updateProperty(PropertyName.StationAlarmArmed, this.isAlarmArmable(newValue as AlarmMode));
163
+ }*/
164
+ }
165
+ }
129
166
  updateRawProperty(type, value) {
130
167
  const parsedValue = parameter_1.ParameterHelper.readValue(type, value, this.log);
131
168
  if ((this.rawProperties[type] !== undefined && this.rawProperties[type] !== parsedValue)
@@ -452,12 +489,67 @@ class Station extends tiny_typed_emitter_1.TypedEmitter {
452
489
  }
453
490
  onAlarmDelay(alarmDelayEvent, alarmDelay) {
454
491
  this.emit("alarm delay event", this, alarmDelayEvent, alarmDelay);
492
+ if (this.hasProperty(types_1.PropertyName.StationAlarmDelay)) {
493
+ this.updateProperty(types_1.PropertyName.StationAlarmDelay, alarmDelay);
494
+ }
495
+ if (this.hasProperty(types_1.PropertyName.StationAlarmDelayType)) {
496
+ this.updateProperty(types_1.PropertyName.StationAlarmDelayType, alarmDelayEvent);
497
+ }
455
498
  }
456
499
  onAlarmArmed() {
457
500
  this.emit("alarm armed event", this);
501
+ if (this.hasProperty(types_1.PropertyName.StationAlarmArmDelay)) {
502
+ this.updateProperty(types_1.PropertyName.StationAlarmArmDelay, 0);
503
+ }
504
+ /*if (this.hasProperty(PropertyName.StationAlarmArmed) && this.hasProperty(PropertyName.StationCurrentMode)) {
505
+ this.updateProperty(PropertyName.StationAlarmArmed, this.isAlarmArmable(this.getPropertyValue(PropertyName.StationCurrentMode) as AlarmMode));
506
+ }*/
507
+ if (this.hasProperty(types_1.PropertyName.StationAlarmArmed)) {
508
+ this.updateProperty(types_1.PropertyName.StationAlarmArmed, true);
509
+ }
510
+ if (this.hasProperty(types_1.PropertyName.StationAlarmDelay)) {
511
+ this.updateProperty(types_1.PropertyName.StationAlarmDelay, 0);
512
+ }
513
+ if (this.hasProperty(types_1.PropertyName.StationAlarmDelayType)) {
514
+ this.updateProperty(types_1.PropertyName.StationAlarmDelayType, 0);
515
+ }
516
+ if (this.hasProperty(types_1.PropertyName.StationAlarm)) {
517
+ this.updateProperty(types_1.PropertyName.StationAlarm, false);
518
+ }
519
+ if (this.hasProperty(types_1.PropertyName.StationAlarmType)) {
520
+ this.updateProperty(types_1.PropertyName.StationAlarmType, 0);
521
+ }
458
522
  }
459
523
  onAlarmEvent(alarmEvent) {
460
524
  this.emit("alarm event", this, alarmEvent);
525
+ if (this.hasProperty(types_1.PropertyName.StationAlarmDelay)) {
526
+ this.updateProperty(types_1.PropertyName.StationAlarmDelay, 0);
527
+ }
528
+ if (this.hasProperty(types_1.PropertyName.StationAlarmDelayType)) {
529
+ this.updateProperty(types_1.PropertyName.StationAlarmDelayType, 0);
530
+ }
531
+ switch (alarmEvent) {
532
+ case types_2.AlarmEvent.DEV_STOP:
533
+ case types_2.AlarmEvent.HUB_STOP:
534
+ case types_2.AlarmEvent.HUB_STOP_BY_APP:
535
+ case types_2.AlarmEvent.HUB_STOP_BY_HAND:
536
+ case types_2.AlarmEvent.HUB_STOP_BY_KEYPAD:
537
+ if (this.hasProperty(types_1.PropertyName.StationAlarm)) {
538
+ this.updateProperty(types_1.PropertyName.StationAlarm, false);
539
+ }
540
+ if (this.hasProperty(types_1.PropertyName.StationAlarmType)) {
541
+ this.updateProperty(types_1.PropertyName.StationAlarmType, 0);
542
+ }
543
+ break;
544
+ default:
545
+ if (this.hasProperty(types_1.PropertyName.StationAlarm)) {
546
+ this.updateProperty(types_1.PropertyName.StationAlarm, true);
547
+ }
548
+ if (this.hasProperty(types_1.PropertyName.StationAlarmType)) {
549
+ this.updateProperty(types_1.PropertyName.StationAlarmType, alarmEvent);
550
+ }
551
+ break;
552
+ }
461
553
  }
462
554
  async setGuardMode(mode) {
463
555
  const propertyData = {
@@ -524,11 +616,35 @@ class Station extends tiny_typed_emitter_1.TypedEmitter {
524
616
  const armDelay = this.getArmDelay(mode);
525
617
  if (armDelay > 0) {
526
618
  this.emit("alarm arm delay event", this, armDelay);
619
+ if (this.hasProperty(types_1.PropertyName.StationAlarmArmDelay)) {
620
+ this.updateProperty(types_1.PropertyName.StationAlarmArmDelay, armDelay);
621
+ }
622
+ }
623
+ if (mode === types_1.AlarmMode.DISARMED) {
624
+ if (this.hasProperty(types_1.PropertyName.StationAlarmArmDelay)) {
625
+ this.updateProperty(types_1.PropertyName.StationAlarmArmDelay, 0);
626
+ }
627
+ if (this.hasProperty(types_1.PropertyName.StationAlarmArmed)) {
628
+ this.updateProperty(types_1.PropertyName.StationAlarmArmed, false);
629
+ }
630
+ if (this.hasProperty(types_1.PropertyName.StationAlarmDelay)) {
631
+ this.updateProperty(types_1.PropertyName.StationAlarmDelay, 0);
632
+ }
633
+ if (this.hasProperty(types_1.PropertyName.StationAlarmDelayType)) {
634
+ this.updateProperty(types_1.PropertyName.StationAlarmDelayType, 0);
635
+ }
636
+ if (this.hasProperty(types_1.PropertyName.StationAlarm)) {
637
+ this.updateProperty(types_1.PropertyName.StationAlarm, false);
638
+ }
639
+ if (this.hasProperty(types_1.PropertyName.StationAlarmType)) {
640
+ this.updateProperty(types_1.PropertyName.StationAlarmType, 0);
641
+ }
527
642
  }
528
643
  // Trigger refresh Guard Mode
529
644
  await this.getCameraInfo();
530
645
  }
531
646
  getArmDelay(mode) {
647
+ var _a, _b, _c;
532
648
  let propertyName;
533
649
  switch (mode) {
534
650
  case types_1.AlarmMode.HOME:
@@ -549,12 +665,53 @@ class Station extends tiny_typed_emitter_1.TypedEmitter {
549
665
  }
550
666
  if (propertyName !== undefined && this.hasPropertyValue(propertyName) && this.getPropertyValue(propertyName) !== "") {
551
667
  const settings = this.getPropertyValue(propertyName);
552
- if (settings.count_down_arm.channel_list.length > 0 && settings.count_down_arm.delay_time > 0) {
553
- return settings.count_down_arm.delay_time;
668
+ try {
669
+ if (((_b = (_a = settings.count_down_arm) === null || _a === void 0 ? void 0 : _a.channel_list) === null || _b === void 0 ? void 0 : _b.length) > 0 && ((_c = settings.count_down_arm) === null || _c === void 0 ? void 0 : _c.delay_time) > 0) {
670
+ return settings.count_down_arm.delay_time;
671
+ }
672
+ }
673
+ catch (error) {
674
+ this.log.debug(`Station ${this.getSerial()} - getArmDelay - Error`, { error: error, mode: mode, propertyName: propertyName, settings: settings });
554
675
  }
555
676
  }
556
677
  return 0;
557
678
  }
679
+ /*private getGuardModeActionSetting(mode: AlarmMode): number {
680
+ //TODO: This settings are only available on the device properties...
681
+ let value = 0;
682
+ try {
683
+ switch (mode) {
684
+ case AlarmMode.HOME:
685
+ value = Number.parseInt(this.getRawProperty(CommandType.CMD_GET_HOME_ACTION));
686
+ break;
687
+ case AlarmMode.AWAY:
688
+ value = Number.parseInt(this.getRawProperty(CommandType.CMD_GET_AWAY_ACTION));
689
+ break;
690
+ case AlarmMode.CUSTOM1:
691
+ value = Number.parseInt(this.getRawProperty(CommandType.CMD_GET_CUSTOM1_ACTION));
692
+ break;
693
+ case AlarmMode.CUSTOM2:
694
+ value = Number.parseInt(this.getRawProperty(CommandType.CMD_GET_CUSTOM2_ACTION));
695
+ break;
696
+ case AlarmMode.CUSTOM3:
697
+ value = Number.parseInt(this.getRawProperty(CommandType.CMD_GET_CUSTOM3_ACTION));
698
+ break;
699
+ }
700
+ } catch (error) {
701
+ this.log.debug(`Station ${this.getSerial()} - getGuardModeActionSetting - Error`, { error: error, mode: mode });
702
+ }
703
+ return value;
704
+ }
705
+
706
+ private isAlarmArmable(mode: AlarmMode): boolean {
707
+ const action = this.getGuardModeActionSetting(mode);
708
+ if ((action & GuardModeSecuritySettingsAction.CAMERA_ALARM) == GuardModeSecuritySettingsAction.CAMERA_ALARM ||
709
+ (action & GuardModeSecuritySettingsAction.HOMEBASE_ALARM) == GuardModeSecuritySettingsAction.HOMEBASE_ALARM ||
710
+ (action & GuardModeSecuritySettingsAction.LIGHT_ALARM) == GuardModeSecuritySettingsAction.LIGHT_ALARM) {
711
+ return true;
712
+ }
713
+ return false;
714
+ }*/
558
715
  _getDeviceSerial(channel) {
559
716
  if (this.rawStation.devices)
560
717
  for (const device of this.rawStation.devices) {