@fastybird/smart-panel-backend 0.1.0-alpha.6 → 0.2.0-alpha.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.
Files changed (78) hide show
  1. package/dist/migrations/1000000000000-InitialSetup.js +22 -12
  2. package/dist/migrations/1000000000000-InitialSetup.js.map +1 -1
  3. package/dist/modules/system/commands/update-panel.command.js +7 -12
  4. package/dist/modules/system/commands/update-panel.command.js.map +1 -1
  5. package/dist/modules/system/services/update.service.js +1 -1
  6. package/dist/modules/system/services/update.service.js.map +1 -1
  7. package/dist/plugins/devices-shelly-ng/delegates/delegates-manager.service.d.ts +11 -1
  8. package/dist/plugins/devices-shelly-ng/delegates/delegates-manager.service.js +212 -47
  9. package/dist/plugins/devices-shelly-ng/delegates/delegates-manager.service.js.map +1 -1
  10. package/dist/plugins/devices-shelly-ng/devices-shelly-ng.constants.d.ts +5 -0
  11. package/dist/plugins/devices-shelly-ng/devices-shelly-ng.constants.js +10 -1
  12. package/dist/plugins/devices-shelly-ng/devices-shelly-ng.constants.js.map +1 -1
  13. package/dist/plugins/devices-shelly-ng/devices-shelly-ng.plugin.js +9 -1
  14. package/dist/plugins/devices-shelly-ng/devices-shelly-ng.plugin.js.map +1 -1
  15. package/dist/plugins/devices-shelly-ng/dto/create-device.dto.d.ts +0 -1
  16. package/dist/plugins/devices-shelly-ng/dto/create-device.dto.js +0 -14
  17. package/dist/plugins/devices-shelly-ng/dto/create-device.dto.js.map +1 -1
  18. package/dist/plugins/devices-shelly-ng/dto/update-device.dto.d.ts +2 -1
  19. package/dist/plugins/devices-shelly-ng/dto/update-device.dto.js +19 -4
  20. package/dist/plugins/devices-shelly-ng/dto/update-device.dto.js.map +1 -1
  21. package/dist/plugins/devices-shelly-ng/entities/devices-shelly-ng.entity.d.ts +6 -1
  22. package/dist/plugins/devices-shelly-ng/entities/devices-shelly-ng.entity.js +38 -6
  23. package/dist/plugins/devices-shelly-ng/entities/devices-shelly-ng.entity.js.map +1 -1
  24. package/dist/plugins/devices-shelly-ng/entities/shelly-ng-device-address.entity.d.ts +10 -0
  25. package/dist/plugins/devices-shelly-ng/entities/shelly-ng-device-address.entity.js +69 -0
  26. package/dist/plugins/devices-shelly-ng/entities/shelly-ng-device-address.entity.js.map +1 -0
  27. package/dist/plugins/devices-shelly-ng/services/database-discoverer.service.d.ts +3 -1
  28. package/dist/plugins/devices-shelly-ng/services/database-discoverer.service.js +19 -7
  29. package/dist/plugins/devices-shelly-ng/services/database-discoverer.service.js.map +1 -1
  30. package/dist/plugins/devices-shelly-ng/services/device-address.service.d.ts +22 -0
  31. package/dist/plugins/devices-shelly-ng/services/device-address.service.js +149 -0
  32. package/dist/plugins/devices-shelly-ng/services/device-address.service.js.map +1 -0
  33. package/dist/plugins/devices-shelly-ng/services/device-manager.service.d.ts +3 -1
  34. package/dist/plugins/devices-shelly-ng/services/device-manager.service.js +20 -7
  35. package/dist/plugins/devices-shelly-ng/services/device-manager.service.js.map +1 -1
  36. package/dist/plugins/devices-shelly-ng/subscribers/device-entity.subscriber.d.ts +6 -2
  37. package/dist/plugins/devices-shelly-ng/subscribers/device-entity.subscriber.js +75 -6
  38. package/dist/plugins/devices-shelly-ng/subscribers/device-entity.subscriber.js.map +1 -1
  39. package/dist/plugins/devices-zigbee2mqtt/devices-zigbee2mqtt.constants.d.ts +4 -0
  40. package/dist/plugins/devices-zigbee2mqtt/devices-zigbee2mqtt.constants.js +5 -1
  41. package/dist/plugins/devices-zigbee2mqtt/devices-zigbee2mqtt.constants.js.map +1 -1
  42. package/dist/plugins/devices-zigbee2mqtt/devices-zigbee2mqtt.openapi.d.ts +2 -2
  43. package/dist/plugins/devices-zigbee2mqtt/devices-zigbee2mqtt.openapi.js +2 -0
  44. package/dist/plugins/devices-zigbee2mqtt/devices-zigbee2mqtt.openapi.js.map +1 -1
  45. package/dist/plugins/devices-zigbee2mqtt/devices-zigbee2mqtt.plugin.js +11 -6
  46. package/dist/plugins/devices-zigbee2mqtt/devices-zigbee2mqtt.plugin.js.map +1 -1
  47. package/dist/plugins/devices-zigbee2mqtt/dto/update-config.dto.d.ts +10 -0
  48. package/dist/plugins/devices-zigbee2mqtt/dto/update-config.dto.js +117 -3
  49. package/dist/plugins/devices-zigbee2mqtt/dto/update-config.dto.js.map +1 -1
  50. package/dist/plugins/devices-zigbee2mqtt/interfaces/zigbee2mqtt.interface.d.ts +8 -0
  51. package/dist/plugins/devices-zigbee2mqtt/mappings/definitions/covers.yaml +5 -4
  52. package/dist/plugins/devices-zigbee2mqtt/models/config.model.d.ts +10 -0
  53. package/dist/plugins/devices-zigbee2mqtt/models/config.model.js +108 -3
  54. package/dist/plugins/devices-zigbee2mqtt/models/config.model.js.map +1 -1
  55. package/dist/plugins/devices-zigbee2mqtt/platforms/zigbee2mqtt.device.platform.d.ts +3 -4
  56. package/dist/plugins/devices-zigbee2mqtt/platforms/zigbee2mqtt.device.platform.js +11 -22
  57. package/dist/plugins/devices-zigbee2mqtt/platforms/zigbee2mqtt.device.platform.js.map +1 -1
  58. package/dist/plugins/devices-zigbee2mqtt/services/base-client-adapter.d.ts +35 -0
  59. package/dist/plugins/devices-zigbee2mqtt/services/base-client-adapter.js +265 -0
  60. package/dist/plugins/devices-zigbee2mqtt/services/base-client-adapter.js.map +1 -0
  61. package/dist/plugins/devices-zigbee2mqtt/services/device-mapper.service.js +6 -5
  62. package/dist/plugins/devices-zigbee2mqtt/services/device-mapper.service.js.map +1 -1
  63. package/dist/plugins/devices-zigbee2mqtt/services/mqtt-client-adapter.service.d.ts +4 -26
  64. package/dist/plugins/devices-zigbee2mqtt/services/mqtt-client-adapter.service.js +16 -265
  65. package/dist/plugins/devices-zigbee2mqtt/services/mqtt-client-adapter.service.js.map +1 -1
  66. package/dist/plugins/devices-zigbee2mqtt/services/virtual-property.types.js +0 -16
  67. package/dist/plugins/devices-zigbee2mqtt/services/virtual-property.types.js.map +1 -1
  68. package/dist/plugins/devices-zigbee2mqtt/services/ws-client-adapter.service.d.ts +14 -0
  69. package/dist/plugins/devices-zigbee2mqtt/services/ws-client-adapter.service.js +199 -0
  70. package/dist/plugins/devices-zigbee2mqtt/services/ws-client-adapter.service.js.map +1 -0
  71. package/dist/plugins/devices-zigbee2mqtt/services/zigbee2mqtt-config-validator.service.d.ts +2 -0
  72. package/dist/plugins/devices-zigbee2mqtt/services/zigbee2mqtt-config-validator.service.js +69 -0
  73. package/dist/plugins/devices-zigbee2mqtt/services/zigbee2mqtt-config-validator.service.js.map +1 -1
  74. package/dist/plugins/devices-zigbee2mqtt/services/zigbee2mqtt.service.d.ts +8 -1
  75. package/dist/plugins/devices-zigbee2mqtt/services/zigbee2mqtt.service.js +86 -32
  76. package/dist/plugins/devices-zigbee2mqtt/services/zigbee2mqtt.service.js.map +1 -1
  77. package/dist/tsconfig.build.tsbuildinfo +1 -1
  78. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"update-device.dto.js","sourceRoot":"","sources":["../../../../src/plugins/devices-shelly-ng/dto/update-device.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAA2C;AAC3C,qDAAuD;AAEvD,6CAA8E;AAE9E,sFAAiF;AACjF,gFAAwE;AAGjE,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,mCAAe;CAgC3D,CAAA;AAhCY,0DAAuB;AASnC;IARC,IAAA,qBAAW,EAAC;QACZ,WAAW,EAAE,aAAa;QAC1B,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,oDAAsB;QAC/B,OAAO,EAAE,oDAAsB;KAC/B,CAAC;IACD,IAAA,0BAAM,GAAE;IACR,IAAA,0BAAQ,EAAC,EAAE,OAAO,EAAE,wEAAwE,EAAE,CAAC;;qDAC5D;AAUpC;IARC,IAAA,6BAAmB,EAAC;QACpB,WAAW,EAAE,iBAAiB;QAC9B,OAAO,EAAE,aAAa;QACtB,QAAQ,EAAE,IAAI;KACd,CAAC;IACD,IAAA,0BAAM,GAAE;IACR,IAAA,4BAAU,G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AAW,EAAE,2BAA2B;QACxC,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE,eAAe;QACxB,QAAQ,EAAE,IAAI;KACd,CAAC;IACD,IAAA,0BAAM,EAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;IAChC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,EAAC;QACT,OAAO,EAAE,oGAAoG;KAC7G,CAAC;;4DAC0B;AAc5B;IAZC,IAAA,6BAAmB,EAAC;QACpB,WAAW,EAAE,+BAA+B;QAC5C,IAAI,EAAE,kBAAkB;QACxB,OAAO,EAAE,eAAe;QACxB,QAAQ,EAAE,IAAI;KACd,CAAC;IACD,IAAA,0BAAM,EAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC;IACpC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,EAAC;QACT,OAAO,EACN,4GAA4G;KAC7G,CAAC;;gEAC8B;kCA9CpB,uBAAuB;IADnC,IAAA,mBAAS,EAAC,EAAE,IAAI,EAAE,mCAAmC,EAAE,CAAC;GAC5C,uBAAuB,CA+CnC"}
@@ -1,8 +1,13 @@
1
1
  import { ChannelEntity, ChannelPropertyEntity, DeviceEntity } from '../../../modules/devices/entities/devices.entity';
2
+ import { ShellyNgDeviceAddressEntity } from './shelly-ng-device-address.entity';
2
3
  export declare class ShellyNgDeviceEntity extends DeviceEntity {
3
4
  get type(): string;
4
5
  password: string | null;
5
- hostname: string | null;
6
+ canonicalMac: string | null;
7
+ hasEthernet: boolean;
8
+ wifiAddress?: string | null;
9
+ ethernetAddress?: string | null;
10
+ addresses: ShellyNgDeviceAddressEntity[];
6
11
  toString(): string;
7
12
  }
8
13
  export declare class ShellyNgChannelEntity extends ChannelEntity {
@@ -16,11 +16,13 @@ const typeorm_1 = require("typeorm");
16
16
  const swagger_1 = require("@nestjs/swagger");
17
17
  const devices_entity_1 = require("../../../modules/devices/entities/devices.entity");
18
18
  const devices_shelly_ng_constants_1 = require("../devices-shelly-ng.constants");
19
+ const shelly_ng_device_address_entity_1 = require("./shelly-ng-device-address.entity");
19
20
  let ShellyNgDeviceEntity = class ShellyNgDeviceEntity extends devices_entity_1.DeviceEntity {
20
21
  constructor() {
21
22
  super(...arguments);
22
23
  this.password = null;
23
- this.hostname = null;
24
+ this.canonicalMac = null;
25
+ this.hasEthernet = false;
24
26
  }
25
27
  get type() {
26
28
  return devices_shelly_ng_constants_1.DEVICES_SHELLY_NG_TYPE;
@@ -56,17 +58,47 @@ __decorate([
56
58
  ], ShellyNgDeviceEntity.prototype, "password", void 0);
57
59
  __decorate([
58
60
  (0, swagger_1.ApiPropertyOptional)({
59
- description: 'Device hostname or IP address',
61
+ description: 'Canonical MAC address from Shelly device info, used for deduplication of multi-interface devices',
62
+ name: 'canonical_mac',
60
63
  type: 'string',
61
- example: '192.168.1.100',
64
+ example: 'A8032ABE5084',
62
65
  nullable: true,
63
66
  }),
64
- (0, class_transformer_1.Expose)(),
67
+ (0, class_transformer_1.Expose)({ name: 'canonical_mac' }),
65
68
  (0, class_validator_1.IsOptional)(),
66
69
  (0, class_validator_1.IsString)(),
67
- (0, typeorm_1.Column)({ nullable: true, default: null }),
70
+ (0, typeorm_1.Column)({ nullable: true, default: null, unique: true }),
68
71
  __metadata("design:type", String)
69
- ], ShellyNgDeviceEntity.prototype, "hostname", void 0);
72
+ ], ShellyNgDeviceEntity.prototype, "canonicalMac", void 0);
73
+ __decorate([
74
+ (0, swagger_1.ApiProperty)({
75
+ description: 'Whether the device has an Ethernet interface (Pro devices)',
76
+ name: 'has_ethernet',
77
+ type: 'boolean',
78
+ example: false,
79
+ }),
80
+ (0, class_transformer_1.Expose)({ name: 'has_ethernet' }),
81
+ (0, class_validator_1.IsBoolean)(),
82
+ (0, typeorm_1.Column)({ type: 'boolean', default: false }),
83
+ __metadata("design:type", Boolean)
84
+ ], ShellyNgDeviceEntity.prototype, "hasEthernet", void 0);
85
+ __decorate([
86
+ (0, class_transformer_1.Expose)({ name: 'wifi_address' }),
87
+ (0, class_validator_1.IsOptional)(),
88
+ (0, class_validator_1.IsString)(),
89
+ __metadata("design:type", String)
90
+ ], ShellyNgDeviceEntity.prototype, "wifiAddress", void 0);
91
+ __decorate([
92
+ (0, class_transformer_1.Expose)({ name: 'ethernet_address' }),
93
+ (0, class_validator_1.IsOptional)(),
94
+ (0, class_validator_1.IsString)(),
95
+ __metadata("design:type", String)
96
+ ], ShellyNgDeviceEntity.prototype, "ethernetAddress", void 0);
97
+ __decorate([
98
+ (0, class_transformer_1.Expose)(),
99
+ (0, typeorm_1.OneToMany)(() => shelly_ng_device_address_entity_1.ShellyNgDeviceAddressEntity, (addr) => addr.device, { eager: true }),
100
+ __metadata("design:type", Array)
101
+ ], ShellyNgDeviceEntity.prototype, "addresses", void 0);
70
102
  exports.ShellyNgDeviceEntity = ShellyNgDeviceEntity = __decorate([
71
103
  (0, swagger_1.ApiSchema)({ name: 'DevicesShellyNgPluginDataDevice' }),
72
104
  (0, typeorm_1.ChildEntity)()
@@ -1 +1 @@
1
- {"version":3,"file":"devices-shelly-ng.entity.js","sourceRoot":"","sources":["../../../../src/plugins/devices-shelly-ng/entities/devices-shelly-ng.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAA2C;AAC3C,qDAAuD;AACvD,qCAA8C;AAE9C,6CAA8E;AAE9E,qFAAsH;AACtH,gFAAwE;AAIjE,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,6BAAY;IAA/C;;QAsBN,aAAQ,GAAkB,IAAI,CAAC;QAY/B,aAAQ,GAAkB,IAAI,CAAC;IAKhC,CAAC;IAtCA,IAOI,IAAI;QACP,OAAO,oDAAsB,CAAC;IAC/B,CAAC;IA0BD,QAAQ;QACP,OAAO,kBAAkB,IAAI,CAAC,UAAU,mBAAmB,IAAI,CAAC,EAAE,GAAG,CAAC;IACvE,CAAC;CACD,CAAA;AAvCY,oDAAoB;AAChC;IAAC,IAAA,qBAAW,EAAC;QACZ,WAAW,EAAE,aAAa;QAC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O,EAAE,oDAAsB;KAC/B,CAAC;IACD,IAAA,0BAAM,GAAE;;;iDAGR;gCAVW,qBAAqB;IAFjC,IAAA,mBAAS,EAAC,EAAE,IAAI,EAAE,kCAAkC,EAAE,CAAC;IACvD,IAAA,qBAAW,GAAE;GACD,qBAAqB,CAejC;AAIM,IAAM,6BAA6B,GAAnC,MAAM,6BAA8B,SAAQ,sCAAqB;IACvE,IAOI,IAAI;QACP,OAAO,oDAAsB,CAAC;IAC/B,CAAC;IAED,QAAQ;QACP,OAAO,+BAA+B,IAAI,CAAC,UAAU,6BAA6B,IAAI,CAAC,EAAE,GAAG,CAAC;IAC9F,CAAC;CACD,CAAA;AAfY,sEAA6B;AACzC;IAAC,IAAA,qBAAW,EAAC;QACZ,WAAW,EAAE,uBAAuB;QACpC,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,oDAAsB;QAC/B,OAAO,EAAE,oDAAsB;KAC/B,CAAC;IACD,IAAA,0BAAM,GAAE;;;yDAGR;wCAVW,6BAA6B;IAFzC,IAAA,mBAAS,EAAC,EAAE,IAAI,EAAE,0CAA0C,EAAE,CAAC;IAC/D,IAAA,qBAAW,GAAE;GACD,6BAA6B,CAezC"}
1
+ {"version":3,"file":"devices-shelly-ng.entity.js","sourceRoot":"","sources":["../../../../src/plugins/devices-shelly-ng/entities/devices-shelly-ng.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAA2C;AAC3C,qDAAkE;AAClE,qCAAyD;AAEzD,6CAA8E;AAE9E,qFAAsH;AACtH,gFAAwE;AAExE,uFAAgF;AAIzE,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,6BAAY;IAA/C;;QAsBN,aAAQ,GAAkB,IAAI,CAAC;QAsB/B,iBAAY,GAAkB,IAAI,CAAC;QAWnC,gBAAW,GAAY,KAAK,CAAC;IAwB9B,CAAC;IA9EA,IAOI,IAAI;QACP,OAAO,oDAAsB,CAAC;IAC/B,CAAC;IAkED,QAAQ;QACP,OAA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nC,MAAM,6BAA8B,SAAQ,sCAAqB;IACvE,IAOI,IAAI;QACP,OAAO,oDAAsB,CAAC;IAC/B,CAAC;IAED,QAAQ;QACP,OAAO,+BAA+B,IAAI,CAAC,UAAU,6BAA6B,IAAI,CAAC,EAAE,GAAG,CAAC;IAC9F,CAAC;CACD,CAAA;AAfY,sEAA6B;AACzC;IAAC,IAAA,qBAAW,EAAC;QACZ,WAAW,EAAE,uBAAuB;QACpC,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,oDAAsB;QAC/B,OAAO,EAAE,oDAAsB;KAC/B,CAAC;IACD,IAAA,0BAAM,GAAE;;;yDAGR;wCAVW,6BAA6B;IAFzC,IAAA,mBAAS,EAAC,EAAE,IAAI,EAAE,0CAA0C,EAAE,CAAC;IAC/D,IAAA,qBAAW,GAAE;GACD,6BAA6B,CAezC"}
@@ -0,0 +1,10 @@
1
+ import { BaseEntity } from '../../../common/entities/base.entity';
2
+ import { AddressType } from '../devices-shelly-ng.constants';
3
+ import { ShellyNgDeviceEntity } from './devices-shelly-ng.entity';
4
+ export declare class ShellyNgDeviceAddressEntity extends BaseEntity {
5
+ deviceId: string;
6
+ device: ShellyNgDeviceEntity;
7
+ interfaceType: AddressType;
8
+ address: string;
9
+ toString(): string;
10
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ShellyNgDeviceAddressEntity = void 0;
13
+ const class_transformer_1 = require("class-transformer");
14
+ const class_validator_1 = require("class-validator");
15
+ const typeorm_1 = require("typeorm");
16
+ const swagger_1 = require("@nestjs/swagger");
17
+ const base_entity_1 = require("../../../common/entities/base.entity");
18
+ const devices_shelly_ng_constants_1 = require("../devices-shelly-ng.constants");
19
+ const devices_shelly_ng_entity_1 = require("./devices-shelly-ng.entity");
20
+ let ShellyNgDeviceAddressEntity = class ShellyNgDeviceAddressEntity extends base_entity_1.BaseEntity {
21
+ toString() {
22
+ return `Shelly Address [${this.interfaceType}:${this.address}] -> Device [${this.deviceId}]`;
23
+ }
24
+ };
25
+ exports.ShellyNgDeviceAddressEntity = ShellyNgDeviceAddressEntity;
26
+ __decorate([
27
+ (0, swagger_1.ApiProperty)({
28
+ description: 'Device ID this address belongs to',
29
+ type: 'string',
30
+ format: 'uuid',
31
+ }),
32
+ (0, class_transformer_1.Expose)({ name: 'device_id' }),
33
+ (0, class_validator_1.IsString)(),
34
+ (0, typeorm_1.Column)({ type: 'varchar' }),
35
+ __metadata("design:type", String)
36
+ ], ShellyNgDeviceAddressEntity.prototype, "deviceId", void 0);
37
+ __decorate([
38
+ (0, typeorm_1.ManyToOne)(() => devices_shelly_ng_entity_1.ShellyNgDeviceEntity, (device) => device.addresses, { onDelete: 'CASCADE' }),
39
+ (0, typeorm_1.JoinColumn)({ name: 'deviceId' }),
40
+ __metadata("design:type", devices_shelly_ng_entity_1.ShellyNgDeviceEntity)
41
+ ], ShellyNgDeviceAddressEntity.prototype, "device", void 0);
42
+ __decorate([
43
+ (0, swagger_1.ApiProperty)({
44
+ description: 'Network interface type',
45
+ enum: devices_shelly_ng_constants_1.AddressType,
46
+ example: devices_shelly_ng_constants_1.AddressType.ETHERNET,
47
+ }),
48
+ (0, class_transformer_1.Expose)({ name: 'interface_type' }),
49
+ (0, class_validator_1.IsEnum)(devices_shelly_ng_constants_1.AddressType),
50
+ (0, typeorm_1.Column)({ type: 'varchar' }),
51
+ __metadata("design:type", String)
52
+ ], ShellyNgDeviceAddressEntity.prototype, "interfaceType", void 0);
53
+ __decorate([
54
+ (0, swagger_1.ApiProperty)({
55
+ description: 'IP address of the device on this interface',
56
+ type: 'string',
57
+ example: '192.168.1.100',
58
+ }),
59
+ (0, class_transformer_1.Expose)(),
60
+ (0, class_validator_1.IsString)(),
61
+ (0, typeorm_1.Column)({ type: 'varchar' }),
62
+ __metadata("design:type", String)
63
+ ], ShellyNgDeviceAddressEntity.prototype, "address", void 0);
64
+ exports.ShellyNgDeviceAddressEntity = ShellyNgDeviceAddressEntity = __decorate([
65
+ (0, swagger_1.ApiSchema)({ name: 'DevicesShellyNgPluginDataDeviceAddress' }),
66
+ (0, typeorm_1.Entity)('devices_shelly_ng_addresses'),
67
+ (0, typeorm_1.Unique)('UQ_shelly_ng_device_interface', ['deviceId', 'interfaceType'])
68
+ ], ShellyNgDeviceAddressEntity);
69
+ //# sourceMappingURL=shelly-ng-device-address.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shelly-ng-device-address.entity.js","sourceRoot":"","sources":["../../../../src/plugins/devices-shelly-ng/entities/shelly-ng-device-address.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAA2C;AAC3C,qDAAmD;AACnD,qCAAwE;AAExE,6CAAyD;AAEzD,sEAAkE;AAClE,gFAA6D;AAE7D,yEAAkE;AAK3D,IAAM,2BAA2B,GAAjC,MAAM,2BAA4B,SAAQ,wBAAU;IAmC1D,QAAQ;QACP,OAAO,mBAAmB,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,OAAO,gBAAgB,IAAI,CAAC,QAAQ,GAAG,CAAC;IAC9F,CAAC;CACD,CAAA;AAtCY,kEAA2B;AASvC;IARC,IAAA,qBAAW,EAAC;QACZ,WAAW,EAAE,mCAAmC;QAChD,IAAI,EAAE,QAAQ;QACd,MAAM,EAAE,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ers } from 'shellies-ds9';
2
2
  import { DevicesService } from '../../../modules/devices/services/devices.service';
3
+ import { DeviceAddressService } from './device-address.service';
3
4
  export declare class DatabaseDiscovererService extends DeviceDiscoverer {
4
5
  private readonly devicesService;
6
+ private readonly deviceAddressService;
5
7
  private readonly logger;
6
8
  private readonly emitInterval;
7
- constructor(devicesService: DevicesService);
9
+ constructor(devicesService: DevicesService, deviceAddressService: DeviceAddressService);
8
10
  run(): Promise<void>;
9
11
  protected emitDevice(identifiers: DeviceIdentifiers): Promise<void>;
10
12
  }
@@ -15,25 +15,36 @@ const common_1 = require("@nestjs/common");
15
15
  const logger_1 = require("../../../common/logger");
16
16
  const devices_service_1 = require("../../../modules/devices/services/devices.service");
17
17
  const devices_shelly_ng_constants_1 = require("../devices-shelly-ng.constants");
18
+ const device_address_service_1 = require("./device-address.service");
18
19
  let DatabaseDiscovererService = class DatabaseDiscovererService extends shellies_ds9_1.DeviceDiscoverer {
19
- constructor(devicesService) {
20
+ constructor(devicesService, deviceAddressService) {
20
21
  super();
21
22
  this.devicesService = devicesService;
23
+ this.deviceAddressService = deviceAddressService;
22
24
  this.logger = (0, logger_1.createExtensionLogger)(devices_shelly_ng_constants_1.DEVICES_SHELLY_NG_PLUGIN_NAME, 'DatabaseDiscovererService');
23
25
  this.emitInterval = 20;
24
26
  }
25
27
  async run() {
26
- for (const d of await this.devicesService.findAll(devices_shelly_ng_constants_1.DEVICES_SHELLY_NG_TYPE)) {
27
- if (d.enabled === false) {
28
- continue;
29
- }
28
+ const devices = await this.devicesService.findAll(devices_shelly_ng_constants_1.DEVICES_SHELLY_NG_TYPE);
29
+ const enabledDevices = devices.filter((d) => {
30
+ if (d.enabled === false)
31
+ return false;
30
32
  if (d.identifier === null) {
31
33
  this.logger.error(`Failed to prepare device to be managed by Shelly manager. Missing identifier for device=${d.id}`);
34
+ return false;
35
+ }
36
+ return true;
37
+ });
38
+ const preferredAddresses = await this.deviceAddressService.getPreferredAddresses(enabledDevices.map((d) => d.id));
39
+ for (const d of enabledDevices) {
40
+ const hostname = preferredAddresses.get(d.id) ?? (await this.deviceAddressService.getPreferredAddressOrMigrate(d.id));
41
+ if (hostname === null) {
42
+ this.logger.warn(`No address found for device=${d.id}, skipping discovery emit`);
32
43
  continue;
33
44
  }
34
45
  await this.emitDevice({
35
46
  deviceId: d.identifier,
36
- hostname: d.hostname,
47
+ hostname,
37
48
  });
38
49
  }
39
50
  }
@@ -49,6 +60,7 @@ let DatabaseDiscovererService = class DatabaseDiscovererService extends shellies
49
60
  exports.DatabaseDiscovererService = DatabaseDiscovererService;
50
61
  exports.DatabaseDiscovererService = DatabaseDiscovererService = __decorate([
51
62
  (0, common_1.Injectable)(),
52
- __metadata("design:paramtypes", [devices_service_1.DevicesService])
63
+ __metadata("design:paramtypes", [devices_service_1.DevicesService,
64
+ device_address_service_1.DeviceAddressService])
53
65
  ], DatabaseDiscovererService);
54
66
  //# sourceMappingURL=database-discoverer.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"database-discoverer.service.js","sourceRoot":"","sources":["../../../../src/plugins/devices-shelly-ng/services/database-discoverer.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAmE;AAEnE,2CAA4C;AAE5C,mDAAuF;AACvF,uFAAmF;AACnF,gFAAuG;AAIhG,IAAM,yBAAyB,GAA/B,MAAM,yBAA0B,SAAQ,+BAAgB;IAQ9D,YAA6B,cAA8B;QAC1D,KAAK,EAAE,CAAC;QADoB,mBAAc,GAAd,cAAc,CAAgB;QAP1C,WAAM,GAA2B,IAAA,8BAAqB,EACtE,2DAA6B,EAC7B,2BAA2B,CAC3B,CAAC;QAEe,iBAAY,GAAG,EAAE,CAAC;IAInC,CAAC;IAED,KAAK,CAAC,GAAG;QACR,KAAK,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAuB,oDAAsB,CAAC,EAAE,CAAC;YACjG,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;gBACzB,SAAS;YACV,CAAC;YAED,IAAI,CAAC,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;gBAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAChB,2FAA2F,CAAC,CAAC,EAAE,EAAE,CACjG,CAAC;gBAEF,SAAS;YACV,CAAC;YAED,MAAM,IAAI,CAAC,UAAU,CAAC;gBACrB,QAAQ,EAAE,CAAC,CAAC,UAAU;gBACtB,QAAQ,EAAE,CAAC,CAAC,QAAQ;aACpB,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAKS,UAAU,CAAC,WAA8B;QAClD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9B,UAAU,CAAC,GAAG,EAAE;gBACf,IAAI,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAC;gBAEzC,OAAO,EAAE,CAAC;YACX,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AA7CY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;qCASiC,gCAAc;GAR/C,yBAAyB,CA6CrC"}
1
+ {"version":3,"file":"database-discoverer.service.js","sourceRoot":"","sources":["../../../../src/plugins/devices-shelly-ng/services/database-discoverer.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAmE;AAEnE,2CAA4C;AAE5C,mDAAuF;AACvF,uFAAmF;AACnF,gFAAuG;AAGvG,qEAAgE;AAGzD,IAAM,yBAAyB,GAA/B,MAAM,yBAA0B,SAAQ,+BAAgB;IAQ9D,YACkB,cAA8B,EAC9B,oBAA0C;QAE3D,KAAK,EAAE,CAAC;QAHS,mBAAc,GAAd,cAAc,CAAgB;QAC9B,yBAAoB,GAApB,oBAAoB,CAAsB;QAT3C,WAAM,GAA2B,IAAA,8BAAqB,EACtE,2DAA6B,EAC7B,2BAA2B,CAC3B,CAAC;QAEe,iBAAY,GAAG,EAAE,CAAC;IAOnC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E;YAC9B,UAAU,CAAC,GAAG,EAAE;gBACf,IAAI,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAC;gBAEzC,OAAO,EAAE,CAAC;YACX,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AAjEY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;qCAUsB,gCAAc;QACR,6CAAoB;GAVhD,yBAAyB,CAiErC"}
@@ -0,0 +1,22 @@
1
+ import { Repository } from 'typeorm';
2
+ import { AddressType } from '../devices-shelly-ng.constants';
3
+ import { ShellyNgDeviceEntity } from '../entities/devices-shelly-ng.entity';
4
+ import { ShellyNgDeviceAddressEntity } from '../entities/shelly-ng-device-address.entity';
5
+ export declare function normalizeMac(mac: string): string;
6
+ export declare class DeviceAddressService {
7
+ private readonly addressRepository;
8
+ private readonly deviceRepository;
9
+ private readonly logger;
10
+ constructor(addressRepository: Repository<ShellyNgDeviceAddressEntity>, deviceRepository: Repository<ShellyNgDeviceEntity>);
11
+ upsertAddress(deviceId: string, interfaceType: AddressType, address: string): Promise<void>;
12
+ removeAddress(deviceId: string, interfaceType: AddressType): Promise<void>;
13
+ syncAddresses(deviceId: string, wifiIp: string | null, ethernetIp: string | null): Promise<void>;
14
+ getPreferredAddressOrMigrate(deviceId: string): Promise<string | null>;
15
+ getPreferredAddress(deviceId: string): Promise<string | null>;
16
+ getPreferredAddresses(deviceIds: string[]): Promise<Map<string, string>>;
17
+ getAddresses(deviceId: string): Promise<ShellyNgDeviceAddressEntity[]>;
18
+ findDeviceByCanonicalMac(canonicalMac: string): Promise<ShellyNgDeviceEntity | null>;
19
+ setCanonicalMac(deviceId: string, canonicalMac: string): Promise<void>;
20
+ setHasEthernet(deviceId: string, hasEthernet: boolean): Promise<void>;
21
+ getLegacyHostname(deviceId: string): Promise<string | null>;
22
+ }
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DeviceAddressService = void 0;
16
+ exports.normalizeMac = normalizeMac;
17
+ const typeorm_1 = require("typeorm");
18
+ const common_1 = require("@nestjs/common");
19
+ const typeorm_2 = require("@nestjs/typeorm");
20
+ const logger_1 = require("../../../common/logger");
21
+ const devices_shelly_ng_constants_1 = require("../devices-shelly-ng.constants");
22
+ const devices_shelly_ng_entity_1 = require("../entities/devices-shelly-ng.entity");
23
+ const shelly_ng_device_address_entity_1 = require("../entities/shelly-ng-device-address.entity");
24
+ function normalizeMac(mac) {
25
+ return mac.replace(/[:-]/g, '').toUpperCase();
26
+ }
27
+ let DeviceAddressService = class DeviceAddressService {
28
+ constructor(addressRepository, deviceRepository) {
29
+ this.addressRepository = addressRepository;
30
+ this.deviceRepository = deviceRepository;
31
+ this.logger = (0, logger_1.createExtensionLogger)(devices_shelly_ng_constants_1.DEVICES_SHELLY_NG_PLUGIN_NAME, 'DeviceAddressService');
32
+ }
33
+ async upsertAddress(deviceId, interfaceType, address) {
34
+ const existing = await this.addressRepository.findOne({
35
+ where: { deviceId, interfaceType },
36
+ });
37
+ if (existing) {
38
+ if (existing.address !== address) {
39
+ existing.address = address;
40
+ await this.addressRepository.save(existing);
41
+ this.logger.log(`Updated ${interfaceType} address to ${address} for device=${deviceId}`, {
42
+ resource: deviceId,
43
+ });
44
+ }
45
+ }
46
+ else {
47
+ try {
48
+ const entity = this.addressRepository.create({
49
+ deviceId,
50
+ interfaceType,
51
+ address,
52
+ });
53
+ await this.addressRepository.save(entity);
54
+ this.logger.log(`Stored ${interfaceType} address ${address} for device=${deviceId}`, {
55
+ resource: deviceId,
56
+ });
57
+ }
58
+ catch {
59
+ await this.addressRepository.update({ deviceId, interfaceType }, { address });
60
+ }
61
+ }
62
+ }
63
+ async removeAddress(deviceId, interfaceType) {
64
+ const result = await this.addressRepository.delete({ deviceId, interfaceType });
65
+ if (result.affected) {
66
+ this.logger.log(`Removed ${interfaceType} address for device=${deviceId}`, { resource: deviceId });
67
+ }
68
+ }
69
+ async syncAddresses(deviceId, wifiIp, ethernetIp) {
70
+ if (ethernetIp) {
71
+ await this.upsertAddress(deviceId, devices_shelly_ng_constants_1.AddressType.ETHERNET, ethernetIp);
72
+ }
73
+ if (wifiIp) {
74
+ await this.upsertAddress(deviceId, devices_shelly_ng_constants_1.AddressType.WIFI, wifiIp);
75
+ }
76
+ }
77
+ async getPreferredAddressOrMigrate(deviceId) {
78
+ const preferred = await this.getPreferredAddress(deviceId);
79
+ if (preferred !== null) {
80
+ return preferred;
81
+ }
82
+ const legacyHostname = await this.getLegacyHostname(deviceId);
83
+ if (legacyHostname) {
84
+ await this.upsertAddress(deviceId, devices_shelly_ng_constants_1.AddressType.WIFI, legacyHostname);
85
+ this.logger.log(`Migrated legacy hostname=${legacyHostname} to address table for device=${deviceId}`, {
86
+ resource: deviceId,
87
+ });
88
+ return legacyHostname;
89
+ }
90
+ return null;
91
+ }
92
+ async getPreferredAddress(deviceId) {
93
+ const addresses = await this.addressRepository.find({
94
+ where: { deviceId },
95
+ });
96
+ if (addresses.length === 0) {
97
+ return null;
98
+ }
99
+ addresses.sort((a, b) => (devices_shelly_ng_constants_1.ADDRESS_PRIORITY[a.interfaceType] ?? 99) - (devices_shelly_ng_constants_1.ADDRESS_PRIORITY[b.interfaceType] ?? 99));
100
+ return addresses[0].address;
101
+ }
102
+ async getPreferredAddresses(deviceIds) {
103
+ if (deviceIds.length === 0) {
104
+ return new Map();
105
+ }
106
+ const addresses = await this.addressRepository.find({
107
+ where: { deviceId: (0, typeorm_1.In)(deviceIds) },
108
+ });
109
+ const byDevice = new Map();
110
+ for (const addr of addresses) {
111
+ const list = byDevice.get(addr.deviceId) ?? [];
112
+ list.push(addr);
113
+ byDevice.set(addr.deviceId, list);
114
+ }
115
+ const result = new Map();
116
+ for (const [deviceId, addrs] of byDevice) {
117
+ addrs.sort((a, b) => (devices_shelly_ng_constants_1.ADDRESS_PRIORITY[a.interfaceType] ?? 99) - (devices_shelly_ng_constants_1.ADDRESS_PRIORITY[b.interfaceType] ?? 99));
118
+ result.set(deviceId, addrs[0].address);
119
+ }
120
+ return result;
121
+ }
122
+ async getAddresses(deviceId) {
123
+ return this.addressRepository.find({ where: { deviceId } });
124
+ }
125
+ async findDeviceByCanonicalMac(canonicalMac) {
126
+ return this.deviceRepository.findOne({
127
+ where: { canonicalMac: normalizeMac(canonicalMac) },
128
+ });
129
+ }
130
+ async setCanonicalMac(deviceId, canonicalMac) {
131
+ await this.deviceRepository.update(deviceId, { canonicalMac: normalizeMac(canonicalMac) });
132
+ }
133
+ async setHasEthernet(deviceId, hasEthernet) {
134
+ await this.deviceRepository.update(deviceId, { hasEthernet });
135
+ }
136
+ async getLegacyHostname(deviceId) {
137
+ const result = await this.deviceRepository.query('SELECT "hostname" FROM "devices_module_devices" WHERE "id" = ?', [deviceId]);
138
+ return result[0]?.hostname ?? null;
139
+ }
140
+ };
141
+ exports.DeviceAddressService = DeviceAddressService;
142
+ exports.DeviceAddressService = DeviceAddressService = __decorate([
143
+ (0, common_1.Injectable)(),
144
+ __param(0, (0, typeorm_2.InjectRepository)(shelly_ng_device_address_entity_1.ShellyNgDeviceAddressEntity)),
145
+ __param(1, (0, typeorm_2.InjectRepository)(devices_shelly_ng_entity_1.ShellyNgDeviceEntity)),
146
+ __metadata("design:paramtypes", [typeorm_1.Repository,
147
+ typeorm_1.Repository])
148
+ ], DeviceAddressService);
149
+ //# sourceMappingURL=device-address.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device-address.service.js","sourceRoot":"","sources":["../../../../src/plugins/devices-shelly-ng/services/device-address.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAcA,oCAEC;AAhBD,qCAAyC;AAEzC,2CAA4C;AAC5C,6CAAmD;AAEnD,mDAAuF;AACvF,gFAA8G;AAC9G,mFAA4E;AAC5E,iGAA0F;AAM1F,SAAgB,YAAY,CAAC,GAAW;IACvC,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AAC/C,CAAC;AAGM,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAMhC,YAEC,iBAA2E,EAE3E,gBAAmE;QAFlD,sBAAiB,GAAjB,iBAAiB,CAAyC;QAE1D,qBAAgB,GAAhB,gBAAgB,CAAkC;QATnD,WAAM,GAA2B,IAAA,8BAAqB,EACtE,2DAA6B,EAC7B,sBAAsB,CACtB,CAAC;IAOC,CAAC;IAKJ,KAAK,CAAC,aAAa,CAAC,QAAgB,EAAE,aAA0B,EAAE,OAAe;QAChF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC;YACrD,KAAK,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE;SAClC,CAAC,CAAC;QAEH,IAAI,QAAQ,EAAE,CAAC;YACd,IAAI,QAAQ,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;gBAClC,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;gBAE3B,MAAM,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAE5C,IAAI,CAAC,MAAM,C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AC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC7D,CAAC;IAQD,KAAK,CAAC,wBAAwB,CAAC,YAAoB;QAClD,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;YACpC,KAAK,EAAE,EAAE,YAAY,EAAE,YAAY,CAAC,YAAY,CAAC,EAAE;SACnD,CAAC,CAAC;IACJ,CAAC;IAKD,KAAK,CAAC,eAAe,CAAC,QAAgB,EAAE,YAAoB;QAC3D,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,YAAY,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IAC5F,CAAC;IAMD,KAAK,CAAC,cAAc,CAAC,QAAgB,EAAE,WAAoB;QAC1D,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;IAC/D,CAAC;IAQD,KAAK,CAAC,iBAAiB,CAAC,QAAgB;QACvC,MAAM,MAAM,GAAkC,MAAM,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAC9E,gEAAgE,EAChE,CAAC,QAAQ,CAAC,CACV,CAAC;QAEF,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,IAAI,IAAI,CAAC;IACpC,CAAC;CACD,CAAA;AA3MY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAQV,WAAA,IAAA,0BAAgB,EAAC,6DAA2B,CAAC,CAAA;IAE7C,WAAA,IAAA,0BAAgB,EAAC,+CAAoB,CAAC,CAAA;qCADH,oBAAU;QAEX,oBAAU;GAVlC,oBAAoB,CA2MhC"}
@@ -4,6 +4,7 @@ import { DeviceProvisionQueueService } from '../../../modules/devices/services/d
4
4
  import { DevicesService } from '../../../modules/devices/services/devices.service';
5
5
  import { ShellyNgDeviceEntity } from '../entities/devices-shelly-ng.entity';
6
6
  import { MappingLoaderService, PropertyMappingStorageService, TransformerRegistry } from '../mappings';
7
+ import { DeviceAddressService } from './device-address.service';
7
8
  import { ShellyRpcClientService } from './shelly-rpc-client.service';
8
9
  export declare class DeviceManagerService {
9
10
  private readonly shellyRpcClientService;
@@ -14,12 +15,13 @@ export declare class DeviceManagerService {
14
15
  private readonly transformerRegistry;
15
16
  private readonly propertyMappingStorage;
16
17
  private readonly provisionQueue;
18
+ private readonly deviceAddressService;
17
19
  private readonly logger;
18
20
  private readonly defaultManager;
19
21
  private readonly strictSchema;
20
22
  private timeoutSec;
21
23
  private rpcConcurrency;
22
- constructor(shellyRpcClientService: ShellyRpcClientService, devicesService: DevicesService, channelsService: ChannelsService, channelsPropertiesService: ChannelsPropertiesService, mappingLoaderService: MappingLoaderService, transformerRegistry: TransformerRegistry, propertyMappingStorage: PropertyMappingStorageService, provisionQueue: DeviceProvisionQueueService);
24
+ constructor(shellyRpcClientService: ShellyRpcClientService, devicesService: DevicesService, channelsService: ChannelsService, channelsPropertiesService: ChannelsPropertiesService, mappingLoaderService: MappingLoaderService, transformerRegistry: TransformerRegistry, propertyMappingStorage: PropertyMappingStorageService, provisionQueue: DeviceProvisionQueueService, deviceAddressService: DeviceAddressService);
23
25
  getDeviceInfo(hostname: string, password: string | undefined): Promise<{
24
26
  id: string;
25
27
  name: string | null | undefined;
@@ -25,9 +25,10 @@ const devices_shelly_ng_exceptions_1 = require("../devices-shelly-ng.exceptions"
25
25
  const mappings_1 = require("../mappings");
26
26
  const transformers_1 = require("../mappings/transformers/transformers");
27
27
  const transform_utils_2 = require("../utils/transform.utils");
28
+ const device_address_service_1 = require("./device-address.service");
28
29
  const shelly_rpc_client_service_1 = require("./shelly-rpc-client.service");
29
30
  let DeviceManagerService = class DeviceManagerService {
30
- constructor(shellyRpcClientService, devicesService, channelsService, channelsPropertiesService, mappingLoaderService, transformerRegistry, propertyMappingStorage, provisionQueue) {
31
+ constructor(shellyRpcClientService, devicesService, channelsService, channelsPropertiesService, mappingLoaderService, transformerRegistry, propertyMappingStorage, provisionQueue, deviceAddressService) {
31
32
  this.shellyRpcClientService = shellyRpcClientService;
32
33
  this.devicesService = devicesService;
33
34
  this.channelsService = channelsService;
@@ -36,6 +37,7 @@ let DeviceManagerService = class DeviceManagerService {
36
37
  this.transformerRegistry = transformerRegistry;
37
38
  this.propertyMappingStorage = propertyMappingStorage;
38
39
  this.provisionQueue = provisionQueue;
40
+ this.deviceAddressService = deviceAddressService;
39
41
  this.logger = (0, logger_1.createExtensionLogger)(devices_shelly_ng_constants_1.DEVICES_SHELLY_NG_PLUGIN_NAME, 'DeviceManagerService');
40
42
  this.defaultManager = (() => {
41
43
  const candidate = this.channelsService.dataSource?.manager ??
@@ -81,10 +83,20 @@ let DeviceManagerService = class DeviceManagerService {
81
83
  if (device === null) {
82
84
  throw new devices_shelly_ng_exceptions_1.DevicesShellyNgException('Device not found.');
83
85
  }
84
- const deviceInfo = await this.getDeviceInfo(device.hostname, device.password);
86
+ const hostname = await this.deviceAddressService.getPreferredAddressOrMigrate(device.id);
87
+ if (hostname === null) {
88
+ this.logger.debug(`No network address found yet for device=${device.id}, skipping provision`);
89
+ return device;
90
+ }
91
+ const deviceInfo = await this.getDeviceInfo(hostname, device.password);
85
92
  const deviceSpec = this.getSpecification(deviceInfo.model);
86
93
  if (deviceSpec === null) {
87
- throw new devices_shelly_ng_exceptions_1.DevicesShellyNgException(`Provided device is not supported hostname=${device.hostname} model=${deviceInfo.model}`);
94
+ throw new devices_shelly_ng_exceptions_1.DevicesShellyNgException(`Provided device is not supported hostname=${hostname} model=${deviceInfo.model}`);
95
+ }
96
+ const specHasEthernet = deviceSpec.system.some((s) => s.type === devices_shelly_ng_constants_1.ComponentType.ETHERNET);
97
+ if (device.hasEthernet !== specHasEthernet) {
98
+ device.hasEthernet = specHasEthernet;
99
+ await this.deviceAddressService.setHasEthernet(device.id, specHasEthernet);
88
100
  }
89
101
  const channelsIds = [];
90
102
  const deviceInformation = await this.ensureChannel(device, 'category', devices_constants_1.ChannelCategory.DEVICE_INFORMATION, devices_constants_1.ChannelCategory.DEVICE_INFORMATION, 'Device information');
@@ -97,7 +109,7 @@ let DeviceManagerService = class DeviceManagerService {
97
109
  format: [devices_constants_1.ConnectionState.CONNECTED, devices_constants_1.ConnectionState.DISCONNECTED, devices_constants_1.ConnectionState.UNKNOWN],
98
110
  });
99
111
  try {
100
- const wifiInfo = await this.shellyRpcClientService.getWifiStatus(device.hostname, {
112
+ const wifiInfo = await this.shellyRpcClientService.getWifiStatus(hostname, {
101
113
  password: device.password,
102
114
  });
103
115
  await this.ensureProperty(deviceInformation, devices_constants_1.PropertyCategory.LINK_QUALITY, 'category', devices_constants_1.PropertyCategory.LINK_QUALITY, (0, transform_utils_2.rssiToQuality)(wifiInfo.rssi));
@@ -109,7 +121,7 @@ let DeviceManagerService = class DeviceManagerService {
109
121
  return acc;
110
122
  }, {});
111
123
  const limit = (0, http_utils_1.pLimit)(this.rpcConcurrency);
112
- const host = device.hostname;
124
+ const host = hostname;
113
125
  const password = device.password;
114
126
  for (const [type, ids] of Object.entries(deviceComponents)) {
115
127
  if (type === String(devices_shelly_ng_constants_1.ComponentType.SWITCH) &&
@@ -613,7 +625,7 @@ let DeviceManagerService = class DeviceManagerService {
613
625
  for (const key of ids) {
614
626
  let devicePowerStatus;
615
627
  try {
616
- devicePowerStatus = await this.shellyRpcClientService.getDevicePowerStatus(device.hostname, key, {
628
+ devicePowerStatus = await this.shellyRpcClientService.getDevicePowerStatus(host, key, {
617
629
  password: device.password,
618
630
  });
619
631
  }
@@ -1112,6 +1124,7 @@ exports.DeviceManagerService = DeviceManagerService = __decorate([
1112
1124
  mappings_1.MappingLoaderService,
1113
1125
  mappings_1.TransformerRegistry,
1114
1126
  mappings_1.PropertyMappingStorageService,
1115
- device_provision_queue_service_1.DeviceProvisionQueueService])
1127
+ device_provision_queue_service_1.DeviceProvisionQueueService,
1128
+ device_address_service_1.DeviceAddressService])
1116
1129
  ], DeviceManagerService);
1117
1130
  //# sourceMappingURL=device-manager.service.js.map