Skip to content

Commit

Permalink
Fix edge case when setting override IP back to empty (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTerBeke committed Apr 25, 2024
1 parent 5bb37c0 commit c7161ff
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions drivers/uponor/device.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isIPv4 } from 'net'
import { Device, DiscoveryResult } from 'homey'
import { UponorHTTPClient, Mode } from '../../lib/UponorHTTPClient'

Expand Down Expand Up @@ -58,9 +59,13 @@ class UponorThermostatDevice extends Device {
}

private async _updateAddress(newAddress: string): Promise<boolean> {
const client = new UponorHTTPClient(newAddress)
const canConnect = await client.testConnection()
if (!canConnect) return false
if (newAddress.length > 0) {
const isValidIP = isIPv4(newAddress)
if (!isValidIP) return false
const client = new UponorHTTPClient(newAddress)
const canConnect = await client.testConnection()
if (!canConnect) return false
}
this.setStoreValue('address', newAddress)
this._init()
return true
Expand Down

0 comments on commit c7161ff

Please sign in to comment.