Skip to content

Commit

Permalink
Merge pull request #31 from bitfocus/bug/polling
Browse files Browse the repository at this point in the history
Restore ability to disable polling
  • Loading branch information
istnv authored Jul 5, 2024
2 parents b6a415f + 37e2180 commit e1d13b2
Show file tree
Hide file tree
Showing 6 changed files with 3,138 additions and 2,248 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ package-lock.json
/pkg
/pkg.tgz
DEBUG-INSPECT
DEBUG-PACKAGED
DEBUG-PACKAGED
.yarn/install-state.gz
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tplink-kasasmartplug",
"version": "2.1.5",
"version": "2.1.6",
"main": "src/index.js",
"type": "module",
"scripts": {
Expand All @@ -13,10 +13,10 @@
"url": "git+https://github.com/bitfocus/companion-module-tplink-kasasmartplug.git"
},
"dependencies": {
"@companion-module/base": "^1.7.0"
"@companion-module/base": "^1.8.0"
},
"devDependencies": {
"@companion-module/tools": "^1.3.2",
"@companion-module/tools": "^1.5.0",
"tplink-smarthome-api": "^5.0.0"
},
"prettier": "@companion-module/tools/.prettierrc.json"
Expand Down
17 changes: 12 additions & 5 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ export function getConfigFields() {
id: 'host',
label: 'Plug IP',
default: '',
width: 4,
width: 12,
regex: Regex.IP,
},
{
type: 'static-text',
id: 'poll',
width: 12,
type: 'checkbox',
id: 'polling',
width: 6,
label: 'Polling',
value: 'Polling is necessary for re-connect on error.\n\Since v2.1.4 it is always enabled',
default: true,
},
{
type: 'static-text',
id: 'info2',
width: 6,
label: 'Notice!',
value: 'Disabling Polling will prevent automatic reconnect on error.\nFeedback and variables will not always match the plug state.',
},
]
}
15 changes: 15 additions & 0 deletions src/upgrades.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,19 @@ export default [
updatedFeedbacks: [],
}
},
function (context, props) {
const result = {
updatedConfig: null,
updatedActions: [],
updatedFeedbacks: [],
}

if (props.config) {
if (props.config.polling == undefined || '' == props.config.polling) {
props.config.polling = true
result.updatedConfig = props.config
}
}
return result
},
]
16 changes: 10 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export async function powerToggle(plugId) {
state = plug.state
}
this.log('info', `Toggling ${plugName} Power`)
this.updatePlugState(plug, !state)
plug.togglePowerState()
this.updatePlugState(plug, !state)
} catch (error) {
this.handleError(error)
}
Expand Down Expand Up @@ -171,9 +171,9 @@ export function monitorEvents(plug) {
plug.on('in-use', () => {})
plug.on('not-in-use', () => {})
plug.on('in-use-update', (inUse) => {
//logEvent('in-use-update', device, inUse)
//this.checkFeedbacks()
//this.checkVariables()
// logEvent('in-use-update', device, inUse)
// this.checkFeedbacks()
// this.checkVariables()
})
}

Expand Down Expand Up @@ -207,8 +207,12 @@ export function setupInterval() {

this.config.interval = parseInt(this.config.interval)

this.log('info', 'Starting Update Interval.')
this.INTERVAL = setInterval(this.getInformation.bind(this), this.config.interval)
if (this.config.polling) {
this.log('info', 'Starting Update Interval.')
this.INTERVAL = setInterval(this.getInformation.bind(this), this.config.interval)
} else {
this.getInformation()
}
}
export function stopInterval() {
if (this.INTERVAL) {
Expand Down
Loading

0 comments on commit e1d13b2

Please sign in to comment.