Skip to content

Commit

Permalink
Add thermostat hold switch invert support (#430)
Browse files Browse the repository at this point in the history
Signed-off-by: jsetton <[email protected]>
  • Loading branch information
jsetton authored Dec 7, 2021
1 parent aca3b0a commit 6c8d832
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
21 changes: 12 additions & 9 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1549,10 +1549,13 @@ Items that represent the hold setting of a thermostat. This needs to be paired w
* Supported item types:
* Number [OFF=0, ON=1]
* String [OFF="schedule", ON="hold"]
* Switch [OFF="OFF", ON="ON"]
* Switch (on/off control)
* Supported metadata parameters:
* OFF=`<state>`
* ON=`<state>`
* OFF=`<state>` (Number/String only)
* ON=`<state>` (Number/String only)
* inverted=`<boolean>` (Switch only)
* set to true to invert item state
* defaults to false
* requiresSetpointHold=`<boolean>`
* set to true to require thermostat hold to be set on setpoint requests
* defaults to false
Expand Down Expand Up @@ -1687,12 +1690,12 @@ Items that represent components of a device that are characterized by numbers wi
* predefined [asset ids](#asset-catalog)
* list of text-based names [not allowed](#capability-names-not-allowed)
* defaults to `@Setting.RangeValue` if [single endpoint](#single-endpoint), otherwise item label and synonyms metadata if part of [group endpoint](#group-endpoint)
* nonControllable=`<boolean>`
* set to true for state reporting support only
* defaults to item state description read only property if defined, otherwise false
* inverted=`<boolean>`
* set to true to invert item state
* defaults to true for Rollershutter, otherwise false for other supported item types.
* nonControllable=`<boolean>`
* set to true for state reporting support only
* defaults to item state description read only property if defined, otherwise false
* supportedCommands=`<commands>` (Dimmer/Rollershutter only)
* each command formatted as:
* default name => `<command>` (e.g. `supportedCommands="INCREASE,DECREASE"`)
Expand Down Expand Up @@ -1774,12 +1777,12 @@ Items that represent components of a device that can be toggled on or off. Multi
* predefined [asset ids](#asset-catalog)
* list of text-based names [not allowed](#capability-names-not-allowed)
* defaults to `@Setting.ToggleState` if [single endpoint](#single-endpoint), otherwise item label and synonyms metadata if part of [group endpoint](#group-endpoint)
* inverted=`<boolean>` (Switch only)
* set to true to invert item state
* defaults to false
* nonControllable=`<boolean>`
* set to true for state reporting support only
* defaults to item state description read only property if defined, otherwise false
* inverted=`<boolean>`
* set to true to invert item state
* defaults to false
* language=`<code>`
* text-based name language support
* two-letter language code: `de`, `en`, `es`, `fr`, `hi`, `it`, `ja`, `pt`
Expand Down
24 changes: 24 additions & 0 deletions lambda/alexa/smarthome/properties/thermostatHold.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ThermostatHold extends AlexaProperty {
*/
get supportedParameters() {
return {
[Parameter.INVERTED]: ParameterType.BOOLEAN,
[Parameter.REQUIRES_SETPOINT_HOLD]: ParameterType.BOOLEAN
};
}
Expand Down Expand Up @@ -92,13 +93,36 @@ class ThermostatHold extends AlexaProperty {
}
}

/**
* Returns inverted based on parameter
* @return {Boolean}
*/
get inverted() {
return this.parameters[Parameter.INVERTED] === true;
}

/**
* Returns if requires setpoint hold based on parameter
* @return {Boolean}
*/
get requiresSetpointHold() {
return this.parameters[Parameter.REQUIRES_SETPOINT_HOLD] === true;
}

/**
* Returns openhab command
* @param {String} value
* @return {String}
*/
getCommand(value) {
// Invert command value if property inverted and switch item type
if (this.inverted && this.item.type === ItemType.SWITCH) {
value = value === ThermostatHold.OFF ? ThermostatHold.ON : ThermostatHold.OFF;
}

// Return command map value from parent method
return super.getCommand(value);
}
}

module.exports = ThermostatHold;
4 changes: 2 additions & 2 deletions lambda/test/alexa/cases/thermostatControllerMode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ module.exports = [
{
name: 'ThermostatController',
property: 'thermostatHold',
parameters: {},
parameters: { inverted: true },
item: { name: 'thermostatHold', type: 'Switch' }
}
])
Expand Down Expand Up @@ -409,7 +409,7 @@ module.exports = [
}
}
},
openhab: [{ name: 'thermostatHold', value: 'OFF' }]
openhab: [{ name: 'thermostatHold', value: 'ON' }]
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ module.exports = [
{
name: 'ThermostatController',
property: 'thermostatHold',
parameters: { requiresSetpointHold: true },
parameters: { inverted: true, requiresSetpointHold: true },
item: { name: 'thermostatHold', type: 'Switch' }
},
{
Expand Down Expand Up @@ -648,7 +648,7 @@ module.exports = [
}
},
openhab: [
{ name: 'thermostatHold', value: 'ON' },
{ name: 'thermostatHold', value: 'OFF' },
{ name: 'targetTemperature', value: 70 }
]
}
Expand Down

0 comments on commit 6c8d832

Please sign in to comment.