Skip to content

Commit

Permalink
Do not create client twice when address changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTerBeke committed Jul 2, 2024
1 parent 13f61be commit ab4c4b6
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions drivers/uponor/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,14 @@ class UponorThermostatDevice extends Device {

private async _updateAddress(newAddress: string, persist = false): Promise<boolean> {
if (newAddress && newAddress.length > 0) {
const isValidIP = isIPv4(newAddress)
if (!isValidIP) return false
const client = new UponorHTTPClient(newAddress)
try {
const canConnect = await client.testConnection()
if (!canConnect) return false
} catch (error) {
return false
}
if (!isIPv4(newAddress)) return false
}

if (persist) {
this.setStoreValue('address', newAddress)
await this.setStoreValue('address', newAddress)
}

this._init()
await this._init()
return true
}

Expand Down

0 comments on commit ab4c4b6

Please sign in to comment.