Skip to content

Commit

Permalink
Add more capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierZal committed Nov 20, 2023
1 parent cc669f8 commit 332ca53
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
23 changes: 23 additions & 0 deletions .homeycompose/capabilities/mode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "enum",
"title": {
"en": "Mode"
},
"getable": true,
"setable": true,
"uiComponent": "picker",
"values": [
{
"id": "manual",
"title": {
"en": "Manual"
}
},
{
"id": "auto",
"title": {
"en": "Automatic"
}
}
]
}
22 changes: 20 additions & 2 deletions drivers/nuos/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import type {

const initialData: Data['data'] = { plantData: {}, viewModel: {} }

enum Mode {
manual = 1,
auto = 2,
}

enum OperationMode {
green = 0,
comfort = 1,
Expand Down Expand Up @@ -127,6 +132,12 @@ class NuosDevice extends withAPI(Device) {
this.#data.viewModel.on = value as boolean
}
break
case 'onoff.boost':
this.#data.plantData.boostOn = this.getCapabilityValue(
'onoff.boost',
) as boolean
this.#data.viewModel.boostOn = value as boolean
break
case 'operation_mode':
this.#data.plantData.opMode =
OperationMode[
Expand All @@ -143,6 +154,11 @@ class NuosDevice extends withAPI(Device) {
) as number
this.#data.viewModel.comfortTemp = value as number
break
case 'mode':
this.#data.plantData.mode =
Mode[this.getCapabilityValue('mode') as keyof typeof Mode]
this.#data.viewModel.plantMode = Mode[value as keyof typeof Mode]
break
default:
}
this.applySyncToDevice()
Expand Down Expand Up @@ -192,9 +208,11 @@ class NuosDevice extends withAPI(Device) {
if (!newPlantData) {
return
}
const { on, opMode, comfortTemp, waterTemp } = newPlantData
const { boostOn, mode, on, opMode, comfortTemp, waterTemp } = newPlantData
await this.setCapabilityValue('measure_temperature', waterTemp)
await this.setCapabilityValue('mode', Mode[mode])
await this.setCapabilityValue('onoff', on)
await this.setCapabilityValue('onoff.boost', boostOn)
await this.setCapabilityValue('operation_mode', OperationMode[opMode])
await this.setCapabilityValue('target_temperature', comfortTemp)
}
Expand Down Expand Up @@ -226,7 +244,7 @@ class NuosDevice extends withAPI(Device) {
this.#syncTimeout = this.homey.setTimeout(async (): Promise<void> => {
const plantData: PlantData | null = await this.plantData(true)
await this.sync(plantData)
}, 10000)
}, 1000)
this.log('Next sync in 1 second')
}

Expand Down
9 changes: 8 additions & 1 deletion drivers/nuos/driver.compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@
"capabilities": [
"measure_temperature",
"onoff",
"onoff.boost",
"operation_mode",
"target_temperature"
"target_temperature",
"mode"
],
"capabilitiesOptions": {
"onoff.boost": {
"title": {
"en": "Boost"
}
},
"target_temperature": {
"min": 40,
"max": 65,
Expand Down
10 changes: 8 additions & 2 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type HomeyClass = new (...args: any[]) => Loggable & {
}
/* eslint-enable @typescript-eslint/no-explicit-any */

export type CapabilityValue = boolean | number | string
export type CapabilityValue = boolean | number | string | null

type ValueOf<T> = T[keyof T]

Expand Down Expand Up @@ -62,14 +62,20 @@ export interface Data {
readonly data: {
readonly plantData: {
on?: boolean
waterTemp?: number
boostOn?: boolean
comfortTemp?: number
holidayUntil?: string | null
mode?: number
opMode?: number
waterTemp?: number
}
readonly viewModel: {
on?: boolean
boostOn?: boolean
comfortTemp?: number
holidayUntil?: string | null
opMode?: number
plantMode?: number
}
}
}
Expand Down

0 comments on commit 332ca53

Please sign in to comment.