Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): support conditional settings with "$if" #1810

Merged
merged 8 commits into from
Feb 19, 2021

Conversation

AlCalzone
Copy link
Member

This PR introduces conditional config settings to cut down on repetition for devices that only slighly change between firmware versions or hardware revisions. The "$if" property accepts a string with logic inside, e.g.

{
	"$if": "firmwareVersion >= 1.0 && productType === 0x1234"
	// ... other settings
}

The logic supports the JavaScript operators <, <=, >, >= and ===, as well as &&, || and (...). Available variables are manufacturerId, productType, productId and firmwareVersion.

You can use "$if" in the following locations:

  • Inside association groups
  • Inside config parameters
  • Inside config parameter options

It is also possible to select one of multiple variants of a config parameter by specifying an array. In this case "$if" is mandatory in each parameter, except the last one. The first matching definition will be used, the others don't apply.

@robertsLando
Copy link
Member

Awesome!

@blhoward2
Copy link
Collaborator

blhoward2 commented Feb 18, 2021

Looks great to me. I'm not sure when we'd differentiate by more than firmware version but it could come up, so makes sense to include it.

Does this (or could this) also apply to association groups? I noticed recently that the Kwikset locks seems to gain a group over time but I'm not actually sure it's even definable as they use the same everything else. It may come up again though.

) {
this.parameterNumber = parameterNumber;
this.valueBitMask = valueBitMask;

if (typeof definition.label !== "string") {
throwInvalidConfig(
"devices",
`packages/config/config/devices/${filename}:
`packages/config/config/devices/${parent.filename}:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are plenty of parent.filename here. Maybe a new var could be useful

@AlCalzone
Copy link
Member Author

Yeah you can use it for the individual association groups just not with the array notation of parameters.

@AlCalzone AlCalzone merged commit dddd4d7 into master Feb 19, 2021
@AlCalzone AlCalzone deleted the config-conditions branch February 19, 2021 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants