Skip to content

Commit

Permalink
fix(platform): ensure dingz accessories have a name
Browse files Browse the repository at this point in the history
- accessory names can't be empty
- if a dingz has an empty name we need to set one based on other info
  • Loading branch information
johannrichard committed Dec 5, 2020
1 parent e4d9306 commit 86b7d07
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/platform.ts
Expand Up @@ -252,11 +252,11 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
// Add one device based on address and name
private async addDingzDevice({
address,
name = 'dingz',
name,
token,
}: {
address: string;
name?: string;
name: string;
token?: string;
}): Promise<boolean> {
// Run a diacovery of changed things every 10 seconds
Expand All @@ -283,7 +283,10 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {

// Fixme: Fetch more info about the Device (particularly Name)
const deviceInfo: DeviceInfo = {
name: dingzConfig.dingz_name,
name:
dingzConfig.dingz_name && dingzConfig.dingz_name !== ''
? dingzConfig.dingz_name
: name,
address: address,
mac: mac.toUpperCase(),
token: token,
Expand Down Expand Up @@ -966,7 +969,10 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
request.connection.remoteAddress &&
isValidHost(request.connection.remoteAddress)
) {
this.addDingzDevice({ address: request.connection.remoteAddress });
this.addDingzDevice({
address: request.connection.remoteAddress,
name: `DINGZ ${mac.substr(6, 6)}`,
});
}
this.eb.emit(
PlatformEvent.ACTION,
Expand Down

0 comments on commit 86b7d07

Please sign in to comment.