diff --git a/app.json b/app.json index b1d2312..120502b 100644 --- a/app.json +++ b/app.json @@ -34,6 +34,85 @@ "url": "https://github.com/ChrisTerBeke/homey-remeha/issues" }, "homeyCommunityTopicId": 109529, + "flow": { + "actions": [ + { + "id": "mode", + "title": { + "en": "Set mode to ...", + "nl": "Zet modus op ..." + }, + "titleFormatted": { + "en": "Set mode to [[mode]]", + "nl": "Zet modus op [[mode]]" + }, + "args": [ + { + "type": "device", + "name": "device", + "filter": "driver_id=remeha" + }, + { + "type": "dropdown", + "name": "mode", + "title": { + "en": "Mode", + "nl": "Modus" + }, + "values": [ + { + "id": "off", + "title": { + "en": "Off", + "nl": "Uit" + } + }, + { + "id": "auto", + "title": { + "en": "Auto (schedule)", + "nl": "Automatisch (schema)" + } + }, + { + "id": "manual", + "title": { + "en": "Manual", + "nl": "Handmatig" + } + } + ] + } + ] + }, + { + "id": "fireplace_mode", + "title": { + "en": "Set fireplace mode to ...", + "nl": "Zet openhaardmodus op ..." + }, + "titleFormatted": { + "en": "Set fireplace mode to [[enabled]]", + "nl": "Zet openhaardmodus op [[enabled]]" + }, + "args": [ + { + "type": "device", + "name": "device", + "filter": "driver_id=remeha" + }, + { + "type": "checkbox", + "name": "enabled", + "title": { + "en": "Enabled", + "nl": "Ingeschakeld" + } + } + ] + } + ] + }, "drivers": [ { "name": { diff --git a/drivers/remeha/device.ts b/drivers/remeha/device.ts index 3b0d08a..233fa17 100644 --- a/drivers/remeha/device.ts +++ b/drivers/remeha/device.ts @@ -1,4 +1,4 @@ -import { Device } from 'homey' +import { Device, FlowCard } from 'homey' import { RemehaMobileApi } from '../../lib/RemehaMobileApi' import { RemehaAuth } from '../../lib/RemehaAuth' @@ -46,18 +46,20 @@ class RemehaThermostatDevice extends Device { // required capabilities await this.addCapability('measure_temperature') - await this.addCapability('target_temperature') - this.registerCapabilityListener('target_temperature', this._setTargetTemperature.bind(this)) await this.addCapability('measure_pressure') await this.addCapability('alarm_water') - await this.addCapability('mode') - this.registerCapabilityListener('mode', this._setMode.bind(this)) + + // required capabilities with listeners + await this._addOrRemoveCapability('mode', true, this._setMode.bind(this), this._actionMode.bind(this)) + await this._addOrRemoveCapability('target_temperature', true, this._setTargetTemperature.bind(this)) // optional capabilities await this._addOrRemoveCapability('measure_temperature_water', capabilities.hotWaterZone) await this._addOrRemoveCapability('target_temperature_water', capabilities.hotWaterZone) await this._addOrRemoveCapability('measure_temperature_outside', capabilities.outdoorTemperature) - await this._addOrRemoveCapability('fireplace_mode', capabilities.fireplaceMode, this._setFireplaceMode.bind(this)) + + // optional capabilities with listeners + await this._addOrRemoveCapability('fireplace_mode', capabilities.fireplaceMode, this._setFireplaceMode.bind(this), this._actionFireplaceMode.bind(this)) } catch (error) { this.setUnavailable('Could not find capabilities') } @@ -97,10 +99,11 @@ class RemehaThermostatDevice extends Device { } catch (error) { } } - private async _addOrRemoveCapability(capability: string, enabled: boolean, listener?: Device.CapabilityCallback): Promise { + private async _addOrRemoveCapability(capability: string, enabled: boolean, listener?: Device.CapabilityCallback, flowActionListener?: FlowCard.RunCallback): Promise { if (enabled) { await this.addCapability(capability) if (listener) this.registerCapabilityListener(capability, listener) + if (flowActionListener) await this._addFlowActionCard(capability, flowActionListener) } else { await this.removeCapability(capability) } @@ -112,6 +115,11 @@ class RemehaThermostatDevice extends Device { } } + private async _addFlowActionCard(action: string, listener: FlowCard.RunCallback): Promise { + const actionCard = this.homey.flow.getActionCard(action) + actionCard.registerRunListener(listener) + } + private async _setTargetTemperature(value: number): Promise { await this._refreshAccessToken() if (!this._client) return this.setUnavailable('No Remeha Home client') @@ -136,6 +144,10 @@ class RemehaThermostatDevice extends Device { } } + private async _actionMode(args: any, state: any): Promise { + this._setMode(args.mode) + } + private async _setFireplaceMode(value: boolean): Promise { await this._refreshAccessToken() if (!this._client) return this.setUnavailable('No Remeha Home client') @@ -148,6 +160,10 @@ class RemehaThermostatDevice extends Device { } } + private async _actionFireplaceMode(args: any, state: any): Promise { + this._setFireplaceMode(args.enabled) + } + private async _refreshAccessToken(): Promise { const authorizer = new RemehaAuth() const { accessToken, refreshToken } = this.getStore() diff --git a/drivers/remeha/driver.flow.compose.json b/drivers/remeha/driver.flow.compose.json new file mode 100644 index 0000000..9d3ae6a --- /dev/null +++ b/drivers/remeha/driver.flow.compose.json @@ -0,0 +1,69 @@ +{ + "actions": [ + { + "id": "mode", + "title": { + "en": "Set mode to ...", + "nl": "Zet modus op ..." + }, + "titleFormatted": { + "en": "Set mode to [[mode]]", + "nl": "Zet modus op [[mode]]" + }, + "args": [ + { + "type": "dropdown", + "name": "mode", + "title": { + "en": "Mode", + "nl": "Modus" + }, + "values": [ + { + "id": "off", + "title": { + "en": "Off", + "nl": "Uit" + } + }, + { + "id": "auto", + "title": { + "en": "Auto (schedule)", + "nl": "Automatisch (schema)" + } + }, + { + "id": "manual", + "title": { + "en": "Manual", + "nl": "Handmatig" + } + } + ] + } + ] + }, + { + "id": "fireplace_mode", + "title": { + "en": "Set fireplace mode to ...", + "nl": "Zet openhaardmodus op ..." + }, + "titleFormatted": { + "en": "Set fireplace mode to [[enabled]]", + "nl": "Zet openhaardmodus op [[enabled]]" + }, + "args": [ + { + "type": "checkbox", + "name": "enabled", + "title": { + "en": "Enabled", + "nl": "Ingeschakeld" + } + } + ] + } + ] +} diff --git a/lib/RemehaMobileApi.ts b/lib/RemehaMobileApi.ts index eba730b..fe5b1cc 100644 --- a/lib/RemehaMobileApi.ts +++ b/lib/RemehaMobileApi.ts @@ -192,7 +192,7 @@ export class RemehaMobileApi { private static _mapResponseModeToHomeyMode(mode: string): string { switch (mode) { case 'Manual': return 'manual' - case 'TemporaryOverride': return 'manual' + case 'TemporaryOverride': return 'auto' case 'Scheduling': return 'auto' case 'FrostProtection': return 'off' default: return 'off'