Skip to content

Commit

Permalink
Bug fix for exactPositionUrl if object is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
dxdc committed Jun 1, 2022
1 parent f991410 commit a6071b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
31 changes: 20 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,25 +382,34 @@ BlindsHTTPAccessory.prototype.replaceUrlPosition = function (url, pos) {
return exp.test(url) ? url.replace(exp, pos) : false;
}

if (Object.prototype.hasOwnProperty.call(url, 'url') && typeof url.url.valueOf() === 'string') {
let shallowObj = Object.assign({}, url);
if (!Object.prototype.hasOwnProperty.call(url, 'url') || typeof url.url.valueOf() !== 'string') {
this.log.error(`Missing url property or non-string property for: ${url}`);
return false;
}

let shallowObj = Object.assign({}, url);
const exactPosUrl = exp.test(shallowObj.url);
if (exactPosUrl) {
shallowObj.url = shallowObj.url.replace(exp, pos);
}

if (shallowObj.body) {
if (typeof shallowObj.body === 'string') {
let exactPosBody = false;
if (shallowObj.body) {
if (typeof shallowObj.body === 'string') {
exactPosBody = exp.test(shallowObj.body);
if (exactPosBody) {
shallowObj.body = shallowObj.body.replace(exp, pos);
} else {
shallowObj.body = JSON.parse(JSON.stringify(shallowObj.body).replace(exp, pos));
}
} else {
const body = JSON.stringify(shallowObj.body);
exactPosBody = exp.test(body);
if (exactPosBody) {
shallowObj.body = JSON.parse(body.replace(exp, pos));
}
}

return shallowObj;
} else {
this.log.error(`Missing url property or non-string property for: ${url}`);
}

return false;
return exactPosUrl || exactPosBody ? shallowObj : false;
};

BlindsHTTPAccessory.prototype.setTargetPosition = function (pos, callback) {
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-blinds",
"version": "1.3.26",
"version": "1.3.27",
"description": "A homebridge plugin to control my blinds",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -36,14 +36,14 @@
"jsonata": "^1.8.6",
"node-persist": "^2.1.0",
"request": "^2.88.2",
"requestretry": "^7.0.1",
"requestretry": "^7.1.0",
"selfsigned": "^1.10.11"
},
"devDependencies": {
"eslint": "^8.8.0",
"eslint": "^8.16.0",
"eslint-plugin-json": "^3.1.0",
"markdown-spellcheck": "^1.3.1",
"prettier": "^2.5.1",
"prettier": "^2.6.2",
"rimraf": "^3.0.2"
}
}

0 comments on commit a6071b6

Please sign in to comment.