diff --git a/app.json b/app.json index f6b6cc1..884b358 100644 --- a/app.json +++ b/app.json @@ -79,6 +79,16 @@ } ], "settings": [ + { + "id": "discovered_address", + "label": { + "en": "IP Address", + "nl": "IP-adres" + }, + "type": "label", + "required": false, + "highlight": true + }, { "id": "address", "label": { diff --git a/drivers/uponor/device.ts b/drivers/uponor/device.ts index 46dd903..210f775 100644 --- a/drivers/uponor/device.ts +++ b/drivers/uponor/device.ts @@ -26,10 +26,12 @@ class UponorThermostatDevice extends Device { } async onDiscoveryAvailable(discoveryResult: DiscoveryResultMAC): Promise { + await this.setSettings({ 'discovered_address': discoveryResult.address }) this._updateAddress(discoveryResult.address, true) } async onDiscoveryAddressChanged(discoveryResult: DiscoveryResultMAC): Promise { + await this.setSettings({ 'discovered_address': discoveryResult.address }) this._updateAddress(discoveryResult.address, true) } @@ -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 { - 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 { diff --git a/drivers/uponor/driver.compose.json b/drivers/uponor/driver.compose.json index b572fae..da7b742 100644 --- a/drivers/uponor/driver.compose.json +++ b/drivers/uponor/driver.compose.json @@ -42,6 +42,16 @@ } ], "settings": [ + { + "id": "discovered_address", + "label": { + "en": "IP Address", + "nl": "IP-adres" + }, + "type": "label", + "required": false, + "highlight": true + }, { "id": "address", "label": { diff --git a/lib/UponorHTTPClient.ts b/lib/UponorHTTPClient.ts index 5b46c2f..ee6a780 100644 --- a/lib/UponorHTTPClient.ts +++ b/lib/UponorHTTPClient.ts @@ -69,6 +69,12 @@ export class UponorHTTPClient { } } + public async updateAddress(newAddress: string): Promise { + this._url = `http://${newAddress}/JNAP/` + const success = await this.testConnection() + return success + } + public async testConnection(): Promise { try { const request = await fetch(this._url, {