Skip to content

Commit

Permalink
Many fixes for IP address
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTerBeke committed Oct 31, 2024
1 parent 03727ef commit b9cbbe9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
10 changes: 10 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
}
],
"settings": [
{
"id": "discovered_address",
"label": {
"en": "IP Address",
"nl": "IP-adres"
},
"type": "label",
"required": false,
"highlight": true
},
{
"id": "address",
"label": {
Expand Down
17 changes: 12 additions & 5 deletions drivers/uponor/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ class UponorThermostatDevice extends Device {
}

async onDiscoveryAvailable(discoveryResult: DiscoveryResultMAC): Promise<void> {
await this.setSettings({ 'discovered_address': discoveryResult.address })
this._updateAddress(discoveryResult.address, true)
}

async onDiscoveryAddressChanged(discoveryResult: DiscoveryResultMAC): Promise<void> {
await this.setSettings({ 'discovered_address': discoveryResult.address })
this._updateAddress(discoveryResult.address, true)
}

Expand All @@ -42,21 +44,26 @@ class UponorThermostatDevice extends Device {
const settingAddress = this.getSetting('address')
if (settingAddress && isIPv4(settingAddress)) return settingAddress
const storeAddress = this.getStoreValue('address')
if (storeAddress && isIPv4(settingAddress)) return storeAddress
if (storeAddress && isIPv4(storeAddress)) return storeAddress
return undefined
}

private async _updateAddress(newAddress: string, persist = false): Promise<boolean> {
if (newAddress && newAddress.length > 0) {
if (!isIPv4(newAddress)) return false
if (newAddress.length === 0) {
newAddress = await this.getStoreValue('address')
}

if (!isIPv4(newAddress)) {
return false
}

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

await this._init()
return true
if (!this._client) return false
const success = await this._client.updateAddress(newAddress)
return success
}

async _init(): Promise<void> {
Expand Down
10 changes: 10 additions & 0 deletions drivers/uponor/driver.compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
}
],
"settings": [
{
"id": "discovered_address",
"label": {
"en": "IP Address",
"nl": "IP-adres"
},
"type": "label",
"required": false,
"highlight": true
},
{
"id": "address",
"label": {
Expand Down
6 changes: 6 additions & 0 deletions lib/UponorHTTPClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ export class UponorHTTPClient {
}
}

public async updateAddress(newAddress: string): Promise<boolean> {
this._url = `http://${newAddress}/JNAP/`
const success = await this.testConnection()
return success
}

public async testConnection(): Promise<boolean> {
try {
const request = await fetch(this._url, {
Expand Down

0 comments on commit b9cbbe9

Please sign in to comment.