forked from Koenkk/zigbee2mqtt.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate device options (Koenkk#989)
* Add device options generator * Temp code to remove device specific configuration * Small update for: Temp code to remove device specific configuration * Run docgen only: removes all device type specific configuration * Enable generate options code and remove temp code * Run docgen only: generate options * Custom notes
- Loading branch information
Showing
1,664 changed files
with
8,298 additions
and
16,043 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { strict as assert } from 'assert'; | ||
|
||
function addTrailingDot(text: string) { | ||
text = text.trim(); | ||
return text.endsWith('.') || text.endsWith('`') ? text : text + '.'; | ||
} | ||
|
||
export function generateOptions(definition) { | ||
if (definition.options.length == 0) return ''; | ||
return ` | ||
## Options | ||
*[How to use device type specific configuration](../guide/configuration/devices-groups.md#specific-device-options)* | ||
${definition.options.map((e) => getOptionDocs(e)).join('\n\n')} | ||
`; | ||
} | ||
|
||
function getOptionDocs(option) { | ||
let extra = null; | ||
|
||
if (option.type === 'numeric') { | ||
extra = 'The value must be a number'; | ||
if (option.value_min != null) extra += ` with a minimum value of \`${option.value_min}\``; | ||
if (option.value_min != null && option.value_max != null) extra += ` and with a` | ||
if (option.value_max != null) extra += ` with a maximum value of \`${option.value_max}\``; | ||
} else if (option.type === 'binary') { | ||
extra = `The value must be \`${option.value_on}\` or \`${option.value_off}\``; | ||
} else if (option.type === 'enum') { | ||
extra = `The value must be one of ${option.values.map(v => `\`${v}\``).join(', ')}`; | ||
} else if (option.type === 'list') { | ||
extra = `The value must be a list of ${option.item_type}`; | ||
} else if (option.type === 'composite' && option.property === 'simulated_brightness') { | ||
extra = `Example: | ||
\`\`\`yaml | ||
simulated_brightness: | ||
delta: 20 # delta per interval, default = 20 | ||
interval: 200 # interval in milliseconds, default = 200 | ||
\`\`\` | ||
` | ||
} | ||
|
||
assert(extra != null, `No option doc generator for '${JSON.stringify(option)}'`); | ||
|
||
return `* \`${option.property}\`: ${addTrailingDot(option.description)} ${addTrailingDot(extra)}` | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ pageClass: device-page | |
<!-- Notes END: Do not edit below this line --> | ||
|
||
|
||
|
||
## Exposes | ||
|
||
### Switch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ pageClass: device-page | |
<!-- Notes END: Do not edit below this line --> | ||
|
||
|
||
|
||
## Exposes | ||
|
||
### Switch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.