Skip to content

Commit

Permalink
Implement IP discovery using ARP
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTerBeke committed Apr 24, 2024
1 parent af1b695 commit f129c52
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .homeycompose/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"local"
],
"name": {
"en": "Uponor Smatrix Pulse"
"en": "Uponor"
},
"description": {
"en": "Adds support for Uponor Smatrix Pulse."
"en": "Adds support for Uponor systems."
},
"category": [
"climate"
Expand Down
8 changes: 4 additions & 4 deletions .homeycompose/discovery/uponor.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"mac": {
"manufacturer": [
[
40,
245,
55
54,
206,
75
]
]
},
"id": "{{address}}"
}
}
13 changes: 7 additions & 6 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"local"
],
"name": {
"en": "Uponor Smatrix Pulse"
"en": "Uponor"
},
"description": {
"en": "Adds support for Uponor Smatrix Pulse."
"en": "Adds support for Uponor systems."
},
"category": [
"climate"
Expand All @@ -37,7 +37,7 @@
{
"id": "uponor",
"name": {
"en": "Uponor Smatrix Pulse"
"en": "Uponor Smatrix Pulse R-208"
},
"class": "thermostat",
"capabilities": [
Expand All @@ -50,6 +50,7 @@
"connectivity": [
"lan"
],
"discovery": "uponor",
"images": {
"small": "/drivers/uponor/assets/images/small.png",
"large": "/drivers/uponor/assets/images/large.png"
Expand Down Expand Up @@ -78,9 +79,9 @@
"mac": {
"manufacturer": [
[
40,
245,
55
54,
206,
75
]
]
},
Expand Down
43 changes: 27 additions & 16 deletions drivers/uponor/device.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Device } from 'homey'
import { Device, DiscoveryResult } from 'homey'
import { UponorHTTPClient, Mode } from '../../lib/UponorHTTPClient'
// import { DiscoveryResultMAC } from 'homey/lib/DiscoveryStrategy'
import { DiscoveryResultMAC } from 'homey/lib/DiscoveryStrategy'

// sync thermostat every minute
const POLL_INTERVAL_MS = 1000 * 60 * 1
Expand All @@ -9,17 +9,24 @@ class UponorThermostatDevice extends Device {

private _syncInterval?: NodeJS.Timer
private _client?: UponorHTTPClient

// onDiscoveryResult(discoveryResult: DiscoveryResultMAC) {
// return discoveryResult.id === this.getData().id
// }


async onInit() {
const { IPAddress } = this.getData()
this._client = new UponorHTTPClient(IPAddress)
this._syncInterval = setInterval(this._syncAttributes.bind(this), POLL_INTERVAL_MS)
this.registerCapabilityListener('target_temperature', this._setTargetTemperature.bind(this))
// this.registerCapabilityListener('thermostat_mode', this._setThermostatMode.bind(this))
this._syncInterval = setInterval(this._syncAttributes.bind(this), POLL_INTERVAL_MS)
}

onDiscoveryResult(discoveryResult: DiscoveryResult) {
return this.getData().id.includes(discoveryResult.id)
}

async onDiscoveryAddressChanged(discoveryResult: DiscoveryResultMAC): Promise<void> {
this._client = new UponorHTTPClient(discoveryResult.address)
await this._syncAttributes()
}

async onDiscoveryAvailable(discoveryResult: DiscoveryResultMAC) {
this._client = new UponorHTTPClient(discoveryResult.address)
await this._syncAttributes()
}

Expand All @@ -30,23 +37,27 @@ class UponorThermostatDevice extends Device {
}

private async _syncAttributes() {
await this._client?.syncAttributes()
if (!this._client) return
await this._client.syncAttributes()
const { controllerID, thermostatID } = this.getData()
const data = this._client?.getThermostat(controllerID, thermostatID)
this.setCapabilityValue('measure_temperature', data?.temperature)
this.setCapabilityValue('target_temperature', data?.setPoint)
const data = this._client.getThermostat(controllerID, thermostatID)
if (!data) return
this.setCapabilityValue('measure_temperature', data.temperature)
this.setCapabilityValue('target_temperature', data.setPoint)
// this.setCapabilityValue('thermostat_mode', data?.mode)
}

private async _setTargetTemperature(value: number) {
if (!this._client) return
const { controllerID, thermostatID } = this.getData()
await this._client?.setTargetTemperature(controllerID, thermostatID, value)
await this._client.setTargetTemperature(controllerID, thermostatID, value)
await this._syncAttributes()
}

private async _setThermostatMode(value: Mode) {
if (!this._client) return
const { controllerID, thermostatID } = this.getData()
await this._client?.setMode(controllerID, thermostatID, value)
await this._client.setMode(controllerID, thermostatID, value)
await this._syncAttributes()
}
}
Expand Down
3 changes: 2 additions & 1 deletion drivers/uponor/driver.compose.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "uponor",
"name": {
"en": "Uponor Smatrix Pulse"
"en": "Uponor Smatrix Pulse R-208"
},
"class": "thermostat",
"capabilities": [
Expand All @@ -14,6 +14,7 @@
"connectivity": [
"lan"
],
"discovery": "uponor",
"images": {
"small": "{{driverAssetsPath}}/images/small.png",
"large": "{{driverAssetsPath}}/images/large.png"
Expand Down
36 changes: 18 additions & 18 deletions drivers/uponor/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ import { Thermostat, UponorHTTPClient } from '../../lib/UponorHTTPClient'
class UponorDriver extends Driver {

async onPairListDevices(): Promise<any[]> {
// TODO: fix discoveryResults, MAC search not working?
// const discoveryStrategy = this.getDiscoveryStrategy()
// const discoveryResults = discoveryStrategy.getDiscoveryResults()
// console.log('discoveryResults', discoveryResults)
const client = new UponorHTTPClient('192.168.2.17')
await client.syncAttributes()

const discoveryStrategy = this.getDiscoveryStrategy()
const discoveryResults = discoveryStrategy.getDiscoveryResults()
const devices: any[] = []
const thermostats = client.getThermostats()
thermostats.forEach((thermostat: Thermostat) => {
devices.push({
name: thermostat.name,
data: {
id: thermostat.id,

for await (let discoveryResult of Object.values(discoveryResults)) {
const client = new UponorHTTPClient(discoveryResult.address)
await client.syncAttributes()
const thermostats = client.getThermostats()
thermostats.forEach((thermostat: Thermostat) => {
devices.push({
name: thermostat.name,
IPAddress: '192.168.2.17',
controllerID: thermostat.controllerID,
thermostatID: thermostat.thermostatID,
},
data: {
id: `${discoveryResult.id}_${thermostat.id}`,
name: thermostat.name,
MACAddress: discoveryResult.id,
controllerID: thermostat.controllerID,
thermostatID: thermostat.thermostatID,
},
})
})
})
}

return devices
}
Expand Down

0 comments on commit f129c52

Please sign in to comment.