Skip to content

Commit

Permalink
name fix
Browse files Browse the repository at this point in the history
  • Loading branch information
donavanbecker committed Jan 19, 2025
1 parent dbeca82 commit e5c8e24
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { API } from 'homebridge'

import { describe, expect, it, vi } from 'vitest'

import registerPlatform from './index.js'
import { NoIPPlatform } from './platform.js'
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js'

describe('registerPlatform', () => {
it('should register the platform with homebridge', () => {
const api = {
registerPlatform: vi.fn(),
} as unknown as API

registerPlatform(api)

expect(api.registerPlatform).toHaveBeenCalledWith(PLUGIN_NAME, PLATFORM_NAME, NoIPPlatform)
})
})
11 changes: 11 additions & 0 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ export class NoIPPlatform implements DynamicPlatformPlugin {
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.userDefinedDeviceName)
: await this.validateAndCleanDisplayName(hostname, 'hostname', hostname)

// Ensure displayName is not empty
if (!existingAccessory.displayName) {
existingAccessory.displayName = 'Unnamed Accessory'
}

existingAccessory.context.serialNumber = device.ipv4or6 === 'ipv6' ? await this.publicIPv6(device) : await this.publicIPv4(device)
existingAccessory.context.model = 'DUC'
existingAccessory.context.version = await this.getVersion()
Expand All @@ -199,6 +204,12 @@ export class NoIPPlatform implements DynamicPlatformPlugin {
accessory.displayName = device.configDeviceName
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.userDefinedDeviceName)
: await this.validateAndCleanDisplayName(hostname, 'hostname', hostname)

// Ensure displayName is not empty
if (!accessory.displayName) {
accessory.displayName = 'Unnamed Accessory'
}

accessory.context.serialNumber = device.ipv4or6 === 'ipv6' ? await this.publicIPv6(device) : await this.publicIPv4(device)
accessory.context.model = 'DUC'
accessory.context.version = await this.getVersion()
Expand Down
27 changes: 27 additions & 0 deletions src/settings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, expect, it } from 'vitest'

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'

describe('settings', () => {
it('should have correct PLATFORM_NAME', () => {
expect(PLATFORM_NAME).toBe('NoIP')
})

it('should have correct PLUGIN_NAME', () => {
expect(PLUGIN_NAME).toBe('homebridge-noip')
})

it('should have correct API URLs', () => {
expect(ipinfo_v4).toBe('https://ipinfo.io/json')
expect(getmyip_v4).toBe('https://ipv4.getmyip.dev')
expect(ipify_v4).toBe('https://api.ipify.org?format=json')
expect(ipapi_v4).toBe('https://ipapi.co/json')
expect(myip_v4).toBe('https://api4.my-ip.io/v2/ip.json')
expect(ipinfo_v6).toBe('https://v6.ipinfo.io/json')
expect(getmyip_v6).toBe('https://ipv6.getmyip.dev')
expect(ipify_v6).toBe('https://api64.ipify.org?format=json')
expect(ipapi_v6).toBe('https://ip6api.co/json')
expect(myip_v6).toBe('https://api6.my-ip.io/v2/ip.txt')
expect(noip).toBe('https://dynupdate.no-ip.com/nic/update')
})
})

0 comments on commit e5c8e24

Please sign in to comment.