Skip to content

Commit

Permalink
Merge pull request #19 from bitfocus/chore/libs
Browse files Browse the repository at this point in the history
Refactor for new upstream library
  • Loading branch information
josephdadams authored Feb 1, 2024
2 parents 26f3848 + da137b4 commit c232bb6
Show file tree
Hide file tree
Showing 11 changed files with 1,179 additions and 1,196 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ node_modules/
package-lock.json
.DS_Store
/pkg
/pkg.tz
/pkg.tgz
DEBUG-INSPECT
DEBUG-PACKAGED
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "tplink-kasasmartplug",
"version": "2.0.2",
"version": "2.1.0",
"main": "src/index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"format": "prettier -w ."
Expand All @@ -12,11 +13,11 @@
"url": "git+https://github.com/bitfocus/companion-module-tplink-kasasmartplug.git"
},
"dependencies": {
"@companion-module/base": "~1.4.1",
"tplink-smarthome-api": "^4.2.0"
"@companion-module/base": "1.4.3"
},
"devDependencies": {
"@companion-module/tools": "^1.2.0"
"@companion-module/tools": "^1.3.2",
"tplink-smarthome-api": "^5.0.0"
},
"prettier": "@companion-module/tools/.prettierrc.json"
}
146 changes: 72 additions & 74 deletions src/actions.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,83 @@
module.exports = {
initActions: function () {
let self = this
let actions = {}
export function initActions() {
let self = this
let actions = {}

if (self.SINGLEPLUGMODE) {
actions.on = {
name: 'Power On',
options: [],
callback: async function (action) {
await self.power(1, 1)
},
}
if (self.SINGLEPLUGMODE) {
actions.on = {
name: 'Power On',
options: [],
callback: async function (action) {
await self.power(1, 1)
},
}

actions.off = {
name: 'Power Off',
options: [],
callback: async function (action) {
await self.power(1, 0)
},
}
actions.off = {
name: 'Power Off',
options: [],
callback: async function (action) {
await self.power(1, 0)
},
}

actions.toggle = {
name: 'Power Toggle',
options: [],
callback: async function (action) {
await self.powerToggle(1)
},
}
} else {
actions.powerOn = {
name: 'Power On',
options: [
{
type: 'dropdown',
label: 'Plug',
id: 'plug',
default: self.CHOICES_PLUGS[0].id,
choices: self.CHOICES_PLUGS,
tooltip: 'The plug on the device to control',
},
],
callback: async function (action) {
await self.power(action.options.plug, 1)
actions.toggle = {
name: 'Power Toggle',
options: [],
callback: async function (action) {
await self.powerToggle(1)
},
}
} else {
actions.powerOn = {
name: 'Power On',
options: [
{
type: 'dropdown',
label: 'Plug',
id: 'plug',
default: self.CHOICES_PLUGS[0].id,
choices: self.CHOICES_PLUGS,
tooltip: 'The plug on the device to control',
},
}
],
callback: async function (action) {
await self.power(action.options.plug, 1)
},
}

actions.powerOff = {
name: 'Power Off',
options: [
{
type: 'dropdown',
label: 'Plug',
id: 'plug',
default: self.CHOICES_PLUGS[0].id,
choices: self.CHOICES_PLUGS,
tooltip: 'The plug on the device to control',
},
],
callback: async function (action) {
await self.power(action.options.plug, 0)
actions.powerOff = {
name: 'Power Off',
options: [
{
type: 'dropdown',
label: 'Plug',
id: 'plug',
default: self.CHOICES_PLUGS[0].id,
choices: self.CHOICES_PLUGS,
tooltip: 'The plug on the device to control',
},
}
],
callback: async function (action) {
await self.power(action.options.plug, 0)
},
}

actions.powerToggle = {
name: 'Power Toggle',
options: [
{
type: 'dropdown',
label: 'Plug',
id: 'plug',
default: self.CHOICES_PLUGS[0].id,
choices: self.CHOICES_PLUGS,
tooltip: 'The plug on the device to control',
},
],
callback: async function (action) {
await self.powerToggle(action.options.plug)
actions.powerToggle = {
name: 'Power Toggle',
options: [
{
type: 'dropdown',
label: 'Plug',
id: 'plug',
default: self.CHOICES_PLUGS[0].id,
choices: self.CHOICES_PLUGS,
tooltip: 'The plug on the device to control',
},
}
],
callback: async function (action) {
await self.powerToggle(action.options.plug)
},
}
}

self.setActionDefinitions(actions)
},
self.setActionDefinitions(actions)
}
88 changes: 43 additions & 45 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
const { Regex } = require('@companion-module/base')
import { Regex } from '@companion-module/base'

module.exports = {
getConfigFields() {
return [
{
type: 'static-text',
id: 'info',
width: 12,
label: 'Information',
value: 'This module controls TP-Link Kasa Smart Plugs. It supports both single plug and multi plug devices.',
},
{
type: 'textinput',
id: 'host',
label: 'Plug IP',
default: '192.168.0.5',
width: 4,
regex: Regex.IP,
},
{
type: 'checkbox',
id: 'polling',
label: 'Enable Polling',
default: false,
width: 12,
},
{
type: 'static-text',
id: 'intervalInfo',
width: 12,
label: 'Update Interval',
value:
'Please enter the amount of time in milliseconds to request new information from the device. Set to 0 to disable. Do not use an interval less than 2000 or the device may stop responding.',
isVisible: (configValues) => configValues.polling === true,
},
{
type: 'textinput',
id: 'interval',
label: 'Update Interval',
width: 3,
default: 2000,
isVisible: (configValues) => configValues.polling === true,
},
]
},
export function getConfigFields() {
return [
{
type: 'static-text',
id: 'info',
width: 12,
label: 'Information',
value: 'This module controls TP-Link Kasa Smart Plugs. It supports both single plug and multi plug devices.',
},
{
type: 'textinput',
id: 'host',
label: 'Plug IP',
default: '192.168.0.5',
width: 4,
regex: Regex.IP,
},
{
type: 'checkbox',
id: 'polling',
label: 'Enable Polling',
default: false,
width: 12,
},
{
type: 'static-text',
id: 'intervalInfo',
width: 12,
label: 'Update Interval',
value: 'Please enter the amount of time in milliseconds to request new information from the device. Set to 0 to disable. Less than 2000 will overrun the device.',
isVisible: (configValues) => configValues.polling === true,
},
{
type: 'textinput',
id: 'interval',
label: 'Update Interval',
width: 3,
default: 2000,
min: 2000,
isVisible: (configValues) => configValues.polling === true,
},
]
}
Loading

0 comments on commit c232bb6

Please sign in to comment.