Skip to content

Commit f2a20a6

Browse files
committed
name fix
1 parent dbeca82 commit f2a20a6

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

src/index.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { API } from 'homebridge'
2+
3+
import { describe, expect, it, vi } from 'vitest'
4+
5+
import registerPlatform from './index.js'
6+
import { NoIPPlatform } from './platform.js'
7+
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js'
8+
9+
describe('registerPlatform', () => {
10+
it('should register the platform with homebridge', () => {
11+
const api = {
12+
registerPlatform: vi.fn(),
13+
} as unknown as API
14+
15+
registerPlatform(api)
16+
17+
expect(api.registerPlatform).toHaveBeenCalledWith(PLUGIN_NAME, PLATFORM_NAME, NoIPPlatform)
18+
})
19+
})

src/platform.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ export class NoIPPlatform implements DynamicPlatformPlugin {
174174
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.userDefinedDeviceName)
175175
: await this.validateAndCleanDisplayName(hostname, 'hostname', hostname)
176176

177+
// Ensure displayName is not empty
178+
if (!existingAccessory.displayName) {
179+
existingAccessory.displayName = 'Unnamed Accessory'
180+
}
181+
177182
existingAccessory.context.serialNumber = device.ipv4or6 === 'ipv6' ? await this.publicIPv6(device) : await this.publicIPv4(device)
178183
existingAccessory.context.model = 'DUC'
179184
existingAccessory.context.version = await this.getVersion()
@@ -199,6 +204,12 @@ export class NoIPPlatform implements DynamicPlatformPlugin {
199204
accessory.displayName = device.configDeviceName
200205
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.userDefinedDeviceName)
201206
: await this.validateAndCleanDisplayName(hostname, 'hostname', hostname)
207+
208+
// Ensure displayName is not empty
209+
if (!accessory.displayName) {
210+
accessory.displayName = 'Unnamed Accessory'
211+
}
212+
202213
accessory.context.serialNumber = device.ipv4or6 === 'ipv6' ? await this.publicIPv6(device) : await this.publicIPv4(device)
203214
accessory.context.model = 'DUC'
204215
accessory.context.version = await this.getVersion()

src/settings.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, it } from 'vitest'
2+
3+
import { getmyip_v4, getmyip_v6, ipapi_v4, ipapi_v6, ipify_v4, ipify_v6, ipinfo_v4, ipinfo_v6, myip_v4, myip_v6, noip, PLATFORM_NAME, PLUGIN_NAME } from './settings.js'
4+
5+
describe('settings', () => {
6+
it('should have correct PLATFORM_NAME', () => {
7+
expect(PLATFORM_NAME).toBe('NoIP')
8+
})
9+
10+
it('should have correct PLUGIN_NAME', () => {
11+
expect(PLUGIN_NAME).toBe('homebridge-noip')
12+
})
13+
14+
it('should have correct API URLs', () => {
15+
expect(ipinfo_v4).toBe('https://ipinfo.io/json')
16+
expect(getmyip_v4).toBe('https://ipv4.getmyip.dev')
17+
expect(ipify_v4).toBe('https://api.ipify.org?format=json')
18+
expect(ipapi_v4).toBe('https://ipapi.co/json')
19+
expect(myip_v4).toBe('https://api4.my-ip.io/v2/ip.json')
20+
expect(ipinfo_v6).toBe('https://v6.ipinfo.io/json')
21+
expect(getmyip_v6).toBe('https://ipv6.getmyip.dev')
22+
expect(ipify_v6).toBe('https://api64.ipify.org?format=json')
23+
expect(ipapi_v6).toBe('https://ip6api.co/json')
24+
expect(myip_v6).toBe('https://api6.my-ip.io/v2/ip.txt')
25+
expect(noip).toBe('https://dynupdate.no-ip.com/nic/update')
26+
})
27+
})

0 commit comments

Comments
 (0)