Skip to content

Commit

Permalink
Feature: flow cards (#13)
Browse files Browse the repository at this point in the history
* First iteration of custom flow cards

* Improve reuability of action card code

* Fixes after testing

* Implement flow action card for setting thermostat mode

* comment

* Map temp override to auto mode
  • Loading branch information
ChrisTerBeke authored Jul 17, 2024
1 parent 9223421 commit a0960ac
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 8 deletions.
79 changes: 79 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
30 changes: 23 additions & 7 deletions drivers/remeha/device.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Device } from 'homey'
import { Device, FlowCard } from 'homey'
import { RemehaMobileApi } from '../../lib/RemehaMobileApi'
import { RemehaAuth } from '../../lib/RemehaAuth'

Expand Down Expand Up @@ -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')
}
Expand Down Expand Up @@ -97,10 +99,11 @@ class RemehaThermostatDevice extends Device {
} catch (error) { }
}

private async _addOrRemoveCapability(capability: string, enabled: boolean, listener?: Device.CapabilityCallback): Promise<void> {
private async _addOrRemoveCapability(capability: string, enabled: boolean, listener?: Device.CapabilityCallback, flowActionListener?: FlowCard.RunCallback): Promise<void> {
if (enabled) {
await this.addCapability(capability)
if (listener) this.registerCapabilityListener(capability, listener)
if (flowActionListener) await this._addFlowActionCard(capability, flowActionListener)
} else {
await this.removeCapability(capability)
}
Expand All @@ -112,6 +115,11 @@ class RemehaThermostatDevice extends Device {
}
}

private async _addFlowActionCard(action: string, listener: FlowCard.RunCallback): Promise<void> {
const actionCard = this.homey.flow.getActionCard(action)
actionCard.registerRunListener(listener)
}

private async _setTargetTemperature(value: number): Promise<void> {
await this._refreshAccessToken()
if (!this._client) return this.setUnavailable('No Remeha Home client')
Expand All @@ -136,6 +144,10 @@ class RemehaThermostatDevice extends Device {
}
}

private async _actionMode(args: any, state: any): Promise<void> {
this._setMode(args.mode)
}

private async _setFireplaceMode(value: boolean): Promise<void> {
await this._refreshAccessToken()
if (!this._client) return this.setUnavailable('No Remeha Home client')
Expand All @@ -148,6 +160,10 @@ class RemehaThermostatDevice extends Device {
}
}

private async _actionFireplaceMode(args: any, state: any): Promise<void> {
this._setFireplaceMode(args.enabled)
}

private async _refreshAccessToken(): Promise<void> {
const authorizer = new RemehaAuth()
const { accessToken, refreshToken } = this.getStore()
Expand Down
69 changes: 69 additions & 0 deletions drivers/remeha/driver.flow.compose.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
]
}
2 changes: 1 addition & 1 deletion lib/RemehaMobileApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit a0960ac

Please sign in to comment.