Skip to content

Commit

Permalink
feat(platform): consolidate auto-discovery names
Browse files Browse the repository at this point in the history
- auto-discovered devices use MAC suffix in name;
- if the device (dingz only) has its name set in the Web UI, it will prevail;
- manually added device's name override automatic name too
  • Loading branch information
johannrichard committed Dec 5, 2020
1 parent db89298 commit c585395
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/platform.ts
Expand Up @@ -382,7 +382,7 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
}

const deviceInfo: DeviceInfo = {
name: info.name ?? name,
name: name,
address: address,
mac: info.mac.toUpperCase(),
token: token,
Expand Down Expand Up @@ -772,6 +772,7 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {

const t: DeviceTypes = msg[6];
const mac: string = this.byteToHexString(msg.subarray(0, 6));
const deviceSuffix: string = mac.substr(6, 6);

if (!this.discovered.has(mac)) {
switch (t) {
Expand All @@ -785,7 +786,7 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
.execute(() => {
this.addMyStromButtonDevice({
address: remoteInfo.address,
name: 'Button',
name: `Button ${deviceSuffix}`,
token: this.config.globalToken,
mac: mac,
});
Expand All @@ -799,7 +800,7 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
.execute(() => {
this.addMyStromLightbulbDevice({
address: remoteInfo.address,
name: 'LED Strip',
name: `LED Strip ${deviceSuffix}`,
token: this.config.globalToken,
});
})
Expand All @@ -812,7 +813,7 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
.execute(() => {
this.addMyStromLightbulbDevice({
address: remoteInfo.address,
name: 'Lightbulb',
name: `Lightbulb ${deviceSuffix}`,
token: this.config.globalToken,
});
})
Expand All @@ -827,7 +828,7 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
.execute(() => {
this.addMyStromSwitchDevice({
address: remoteInfo.address,
name: 'Switch',
name: `Switch ${deviceSuffix}`,
token: this.config.globalToken,
});
})
Expand All @@ -840,7 +841,7 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
.execute(() => {
this.addMyStromPIRDevice({
address: remoteInfo.address,
name: 'Motion Sensor',
name: `Motion Sensor ${deviceSuffix}`,
token: this.config.globalToken,
});
})
Expand All @@ -853,7 +854,7 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
.execute(() => {
this.addDingzDevice({
address: remoteInfo.address,
name: 'dingz',
name: `DINGZ ${deviceSuffix}`,
token: this.config.globalToken,
});
})
Expand Down

0 comments on commit c585395

Please sign in to comment.