Skip to content

Commit

Permalink
Restrict range value read only attribute presets support (#651)
Browse files Browse the repository at this point in the history
Signed-off-by: jsetton <jeremy.setton@gmail.com>
  • Loading branch information
jsetton authored Jan 30, 2024
1 parent 14ac403 commit 53770ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lambda/alexa/smarthome/properties/rangeValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ export default class RangeValue extends Generic {
// Define presets as follow:
// 1) using parameter values if defined
// 2) using item state options if available
// 3) empty object
const presets = parameters[Parameter.PRESETS]
// 3) empty object if non-controllable property
const presets = !this.isNonControllable
? parameters[Parameter.PRESETS]
: item.stateDescription?.options
? Object.fromEntries(item.stateDescription.options.map((option) => [option.value, option.label]))
: {};
? parameters[Parameter.PRESETS]
: Object.fromEntries(item.stateDescription?.options?.map((option) => [option.value, option.label]) || [])
: {};
// Update presets parameter, removing duplicate labels and entries
// with out of range values, not multiple of range precision, or with no valid labels
parameters[Parameter.PRESETS] = Object.entries(presets)
Expand Down
6 changes: 2 additions & 4 deletions lambda/test/alexa/cases/discovery/other.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ export default {
type: 'Number:Dimensionless',
name: 'range3',
label: 'Range Value 3',
stateDescription: {
pattern: '%d %unit%' // Unit placeholder in state presentation
},
metadata: {
alexa: {
value: 'RangeValue',
Expand Down Expand Up @@ -172,7 +169,8 @@ export default {
value: 'RangeValue',
config: {
nonControllable: true,
// No action mappings support if non controllable
// No presets or action mappings support if non controllable
presets: '0=@Value.Close',
actionMappings: 'Close=0'
}
}
Expand Down

0 comments on commit 53770ab

Please sign in to comment.