Skip to content

Commit

Permalink
5.2.2 replacing executeAction for player
Browse files Browse the repository at this point in the history
  • Loading branch information
hklages committed Aug 5, 2021
1 parent 496e0ba commit be625b6
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 177 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ All notable changes to this project are documented in this file.

- universal node: typo in DesiredFirstTrackNumberEnqueued

- internal: player.* replaced executeActionV6 with ts node sonos direct commands

### [5.2.0] 2021-08-03

#### Added
Expand Down
108 changes: 60 additions & 48 deletions docs/Helper.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,21 @@ <h1 class="page-title">Source: Helper.js</h1>

/** Validates and converts msg[propertyName] to number (integer).
*
* If defaultValue is NOT given then msg[propertyName] is required! Throws error if missing.
* If defaultValue is given then msg[propertyName] is not required and default value is only used
* in case msg[propertyName] is not "isValidProperty" (undefined, null, NaN).
* The defaultValue is not used in case of wrong type, not in range.
* defaultValue should be in range min max (not checked).
*
* min, max should be in range -9999 to REQUESTED_COUNT_ML_MAXIMUM
* as that correspondent to REGEX check 4 signed digits
*
* Exactly in that case, when the msg[propertyName] is optional, the defaultValue must be given:
* - No defaultValue (= msg[propertyName] required): msg[propertyName] is returned (if valid)
* - defaultValue exist: if msg[propertyName] exist it is used, otherwise defaultValue
*
* min, max should be in range VALIDATION_INTEGER_MINIMUM to VALIDATION_INTEGER_MAXIMUM
* as that correspondent to REGEX check 4 signed digits
* defaultValue and msg[propertyName] must be in range [min, max]
* Exeception: defaultValue may also be -1 and out of range: used for volume control
*
* @param {object} msg Node-RED message
* @param {(string|number)} msg.propertyName item, to be validated, converted
* @param {string} propertyName property name
* @param {number} min minimum, not greater 9999
* @param {number} max maximum, not less -9999, max > min
* @param {string} propertyMeaning additional information, including in error message
* @param {string} propertyMeaning additional information, being included in error message
* @param {number} [defaultValue] integer, specifies the default value.
*
* @returns {number} integer in range [min,max] or defaultValue
Expand All @@ -187,54 +187,66 @@ <h1 class="page-title">Source: Helper.js</h1>
throw new Error(`${PACKAGE_PREFIX} ${propertyMeaning} max is not greater then min`)
}

// if defaultValue exists, check value
const requiredProperty = (typeof defaultValue === 'undefined')
if (!requiredProperty) {
if (typeof defaultValue !== 'number' || defaultValue > VALIDATION_INTEGER_MAXIMUM
|| defaultValue &lt; VALIDATION_INTEGER_MINIMUM) {
// eslint-disable-next-line max-len
throw new Error(`${PACKAGE_PREFIX} ${propertyMeaning} defaultValue is not type number or out of range`)
// if defaultValue is not given then msg[propertyName] is required and being used
// else if msg[propertyName] exist then it is being used
// else default is being used
const txtPrefix = `${PACKAGE_PREFIX} ${propertyMeaning} (msg.${propertyName})`

// does defaultValue exist? if yes validate
const isPropertyRequired = (typeof defaultValue === 'undefined')
if (!isPropertyRequired) {
if (typeof defaultValue !== 'number') {
throw new Error(`${PACKAGE_PREFIX} ${propertyMeaning} defaultValue is not type number`)
}
if (!Number.isInteger(defaultValue)) {
throw new Error(`${PACKAGE_PREFIX} ${propertyMeaning} defaultValue is not integer`)
}
if (!((defaultValue >= min &amp;&amp; defaultValue &lt;= max) || defaultValue === -1)) {
throw new Error(`${txtPrefix} >>${defaultValue} is out of range`)
}
}
// if defaultValue is missing an error will be throw in case property is not defined or missing

// does propertyName exist? if yes validate and store in integerValue
const path = []
path.push(propertyName)
if (!module.exports.isTruthyProperty(msg, path)) {
if (requiredProperty) {
throw new Error(`${PACKAGE_PREFIX} ${propertyMeaning} (${propertyName}) is missing/invalid`)
} else {
// use defaultValue but check if valid
if (typeof defaultValue !== 'number') {
throw new Error(`${PACKAGE_PREFIX} ${propertyMeaning} defaultValue is not type number`)
}
if (!Number.isInteger(defaultValue)) {
throw new Error(`${PACKAGE_PREFIX} ${propertyMeaning} defaultValue is not integer`)
const propertyNameExists = module.exports.isTruthyProperty(msg, path)
let validValue
if (propertyNameExists) {
const value = msg[propertyName]
if (typeof value !== 'string' &amp;&amp; typeof value !== 'number') {
throw new Error(`${txtPrefix} is not type string/number`)
}
if (typeof value === 'string') {
if (!REGEX_4DIGITSSIGN.test(value)) {
throw new Error(`${txtPrefix} >>${value}) is not 4 signed digits only`)
}
// no check in range to allow such as -1 to indicate no value given
return defaultValue
validValue = parseInt(value)
} else { // must be number
validValue = value
}
}
let value = msg[propertyName]
const txtPrefix = `${PACKAGE_PREFIX} ${propertyMeaning} (msg.${propertyName})`

if (typeof value !== 'number' &amp;&amp; typeof value !== 'string') {
throw new Error(`${txtPrefix} is not type string/number`)
}
if (typeof value === 'number') {
if (!Number.isInteger(value)) {
if (!Number.isInteger(validValue)) {
throw new Error(`${txtPrefix} is not integer`)
}
} else {
// it is a string - allow signed/unsigned
if (!REGEX_4DIGITSSIGN.test(value)) {
throw new Error(`${txtPrefix} >>${value}) is not 4 signed digits only`)
if (!(validValue >= min &amp;&amp; validValue &lt;= max)) {
throw new Error(`${txtPrefix} >>${value} is out of range`)
}
value = parseInt(value)
}
if (!(value >= min &amp;&amp; value &lt;= max)) {
throw new Error(`${txtPrefix} >>${value}) is out of range`)
// if exist then integerValue is valid integer (otherwise errors have been thrown)

if (isPropertyRequired) {
if (propertyNameExists) {
return validValue
} else {
throw new Error(`${PACKAGE_PREFIX} ${propertyMeaning} (${propertyName}) is missing/invalid`)
}
} else {
if (propertyNameExists) {
return validValue
} else {
return defaultValue // is valid because errors are thrown
}
}
return value

},

/** Validates msg[propertyName] against regex and returns that value or a default value.
Expand Down Expand Up @@ -445,7 +457,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Co
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Wed Aug 04 2021 16:16:20 GMT+0200 (Central European Summer Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Thu Aug 05 2021 08:52:00 GMT+0200 (Central European Summer Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Co
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Wed Aug 04 2021 16:16:20 GMT+0200 (Central European Summer Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Thu Aug 05 2021 08:52:00 GMT+0200 (Central European Summer Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Co
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Wed Aug 04 2021 16:16:20 GMT+0200 (Central European Summer Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Thu Aug 05 2021 08:52:00 GMT+0200 (Central European Summer Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-MySonos.html
Original file line number Diff line number Diff line change
Expand Up @@ -2591,7 +2591,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Co
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Wed Aug 04 2021 16:16:20 GMT+0200 (Central European Summer Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Thu Aug 05 2021 08:52:00 GMT+0200 (Central European Summer Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
6 changes: 3 additions & 3 deletions docs/module-Sonos-Commands.html
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ <h5>Returns:</h5>



<h4 class="name" id=".getMusicLibraryItems"><span class="type-signature">(static) </span>getMusicLibraryItems<span class="signature">(category, searchString<span class="signature-attributes">opt</span>, requestedCount, tsPlayer)</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;<a href="global.html#exportedItem">exportedItem</a>>>}</span></h4>
<h4 class="name" id=".getMusicLibraryItems"><span class="type-signature">(static) </span>getMusicLibraryItems<span class="signature">(type, searchString<span class="signature-attributes">opt</span>, requestedCount, tsPlayer)</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;<a href="global.html#exportedItem">exportedItem</a>>>}</span></h4>



Expand Down Expand Up @@ -1277,7 +1277,7 @@ <h5>Parameters:</h5>

<tr>

<td class="name"><code>category</code></td>
<td class="name"><code>type</code></td>


<td class="type">
Expand Down Expand Up @@ -3160,7 +3160,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Co
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Wed Aug 04 2021 16:16:20 GMT+0200 (Central European Summer Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Thu Aug 05 2021 08:52:00 GMT+0200 (Central European Summer Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
Loading

0 comments on commit be625b6

Please sign in to comment.