Skip to content

Commit

Permalink
Ensure random ID every time a new device is added with custom IP
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTerBeke committed Apr 25, 2024
1 parent 782d749 commit c8a3fde
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 6 additions & 7 deletions drivers/uponor/device.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Device, DiscoveryResult } from 'homey'
import { UponorHTTPClient, Mode } from '../../lib/UponorHTTPClient'
import { DiscoveryResultMAC } from 'homey/lib/DiscoveryStrategy'

// sync thermostat every minute
const POLL_INTERVAL_MS = 1000 * 60 * 1
Expand Down Expand Up @@ -28,16 +27,16 @@ class UponorThermostatDevice extends Device {
return this.getData().id.includes(discoveryResult.id)
}

async onDiscoveryAvailable(discoveryResult: DiscoveryResultMAC): Promise<void> {
this._updateAddress(discoveryResult.address)
async onDiscoveryAvailable(discoveryResult: DiscoveryResult): Promise<void> {
this._updateAddress(discoveryResult.id)
}

async onDiscoveryAddressChanged(discoveryResult: DiscoveryResultMAC): Promise<void> {
this._updateAddress(discoveryResult.address)
async onDiscoveryAddressChanged(discoveryResult: DiscoveryResult): Promise<void> {
this._updateAddress(discoveryResult.id)
}

async onDiscoveryLastSeenChanged(discoveryResult: DiscoveryResultMAC): Promise<void> {
this._updateAddress(discoveryResult.address)
async onDiscoveryLastSeenChanged(discoveryResult: DiscoveryResult): Promise<void> {
this._updateAddress(discoveryResult.id)
}

async onSettings({ newSettings }: { newSettings: { [key: string]: any } }): Promise<void> {
Expand Down
13 changes: 6 additions & 7 deletions drivers/uponor/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ class UponorDriver extends Driver {
}

if (driver._customIpAddress) {
// TODO: find actual MAC address for custom IP
return await driver._findDevices(driver._customIpAddress, 'custom')
const time = new Date().getTime()
return await driver._findDevices(driver._customIpAddress, `custom_${time}`)
}

return []
})
}

private async _findDevices(ip: string, mac: string): Promise<any[]> {
private async _findDevices(ipAddress: string, systemID: string): Promise<any[]> {
const devices: any[] = []
const client = new UponorHTTPClient(ip)
const client = new UponorHTTPClient(ipAddress)
const connected = await client.testConnection()
if (!connected) return devices

Expand All @@ -42,13 +42,12 @@ class UponorDriver extends Driver {
devices.push({
name: thermostat.name,
data: {
id: `${mac}_${thermostat.id}`,
MACAddress: mac,
id: `${systemID}_${thermostat.id}`,
controllerID: thermostat.controllerID,
thermostatID: thermostat.thermostatID,
},
store: {
address: ip,
address: ipAddress,
}
})
})
Expand Down

0 comments on commit c8a3fde

Please sign in to comment.