Skip to content

Commit 52b10a8

Browse files
committed
upgrade to companion v3 api
1 parent 9e7b02f commit 52b10a8

File tree

14 files changed

+2671
-569
lines changed

14 files changed

+2671
-569
lines changed

.eslintrc

Lines changed: 0 additions & 11 deletions
This file was deleted.
File renamed without changes.

companion/manifest.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"id": "vizio-smartcast",
3+
"name": "vizio-smartcast",
4+
"shortname": "smartcast",
5+
"description": "VIZIO SmartCast plugin for Companion",
6+
"version": "0.0.0",
7+
"license": "MIT",
8+
"repository": "git+https://github.com/bitfocus/companion-module-vizio-smartcast.git",
9+
"bugs": "https://github.com/bitfocus/companion-module-vizio-smartcast/issues",
10+
"maintainers": [
11+
{
12+
"name": "Jeffrey Davidsz",
13+
"email": "[email protected]"
14+
},
15+
{
16+
"name": "Joseph Adams",
17+
"email": "[email protected]"
18+
}
19+
],
20+
"legacyIds": [],
21+
"runtime": {
22+
"type": "node18",
23+
"api": "nodejs-ipc",
24+
"apiVersion": "0.0.0",
25+
"entrypoint": "../index.js"
26+
},
27+
"manufacturer": "VIZIO",
28+
"products": [
29+
"SmartCast"
30+
],
31+
"keywords": [
32+
"TV"
33+
]
34+
}

index.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const { InstanceBase, InstanceStatus, runEntrypoint } = require('@companion-module/base')
2+
3+
const UpgradeScripts = require('./src/upgrades')
4+
5+
const config = require('./src/config');
6+
const api = require('./src/api');
7+
8+
const actions = require('./src/actions');
9+
const variables = require('./src/variables');
10+
const feedbacks = require('./src/feedbacks');
11+
const presets = require('./src/presets');
12+
13+
class VizioInstance extends InstanceBase {
14+
constructor(internal) {
15+
super(internal)
16+
17+
// Assign the methods from the listed files to this class
18+
Object.assign(this, {
19+
...config,
20+
...api,
21+
...actions,
22+
...variables,
23+
...feedbacks,
24+
...presets,
25+
})
26+
27+
this.POLLING_INTERVAL = null;
28+
29+
this.tv = null;
30+
31+
this.STATUS = {
32+
information: '',
33+
power: 0,
34+
current_input: '',
35+
cast_name: '',
36+
serial_number: '',
37+
model_name: '',
38+
version: '',
39+
cast_version: '',
40+
scpl_version: '',
41+
resolution: ''
42+
};
43+
44+
this.LAST_ERROR = '';
45+
}
46+
47+
async init(config) {
48+
this.configUpdated(config);
49+
}
50+
51+
async configUpdated(config) {
52+
this.config = config
53+
54+
this.initActions();
55+
this.initFeedbacks();
56+
this.initVariables();
57+
this.initPresets();
58+
59+
this.checkVariables();
60+
this.checkFeedbacks();
61+
62+
if (this.config.verbose) {
63+
this.log('debug', 'Verbose mode enabled. Log entries will contain detailed information.');
64+
}
65+
66+
this.updateStatus(InstanceStatus.Connecting);
67+
68+
this.initConnection();
69+
}
70+
71+
async destroy() {
72+
//close out any connections
73+
this.tv = null;
74+
this.stopPolling();
75+
76+
this.debug('destroy', this.id);
77+
}
78+
}
79+
80+
runEntrypoint(VizioInstance, UpgradeScripts);

package.json

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,20 @@
11
{
22
"name": "vizio-smartcast",
3-
"version": "1.2.2",
4-
"api_version": "1.0.0",
5-
"keywords": [
6-
"TV"
7-
],
8-
"manufacturer": "VIZIO",
9-
"product": "SmartCast",
10-
"shortname": "smartcast",
11-
"description": "VIZIO SmartCast plugin for Companion",
12-
"main": "src/index.js",
3+
"version": "2.0.0",
4+
"main": "index.js",
135
"scripts": {
146
"test": "echo \"Error: no test specified\" && exit 1"
157
},
16-
"author": "Jeffrey Davidsz <[email protected]>",
17-
"contributors": [
18-
"Joseph Adams <[email protected]>"
19-
],
208
"license": "MIT",
219
"dependencies": {
22-
"vizio-smart-cast": "^1.3.0"
23-
},
24-
"homepage": "https://github.com/bitfocus/companion-module-vizio-smartcast#readme",
25-
"bugs": {
26-
"url": "https://github.com/bitfocus/companion-module-vizio-smartcast/issues"
10+
"@companion-module/base": "~1.4.1",
11+
"vizio-smart-cast": "^1.4.0"
2712
},
2813
"repository": {
2914
"type": "git",
3015
"url": "git+https://github.com/bitfocus/companion-module-vizio-smartcast.git"
16+
},
17+
"devDependencies": {
18+
"@companion-module/tools": "^1.2.1"
3119
}
3220
}

src/actions.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
module.exports = {
2-
// ##########################
3-
// #### Instance Actions ####
4-
// ##########################
5-
setActions: function () {
2+
initActions: function () {
63
let self = this;
74
let actions = {};
85

96
actions.pair = {
10-
label: 'Pair Device',
11-
callback: function(action, bank) {
12-
self.tv.pairing.initiate();
7+
name: 'Pair Device',
8+
options: [],
9+
callback: async function(action) {
10+
self.log('debug', `Attempting to initiate pairing`);
11+
self.tv.pairing.initiate()
12+
.catch(response => {
13+
self.log('debug', `Pairing failed: ${response}`);
14+
});
1315
}
1416
};
1517

1618
actions.pin = {
17-
label: 'Enter PIN Code',
19+
name: 'Enter PIN Code',
1820
options: [
1921
{
2022
type: 'textinput',
@@ -23,7 +25,7 @@ module.exports = {
2325
regex: self.REGEX_NUMBER
2426
}
2527
],
26-
callback: function(action, bank) {
28+
callback: async function(action) {
2729
self.debug(`Attempting to pair with PIN [${action.options.pin}]`);
2830

2931
self.tv.pairing.pair(action.options.pin).then(response => {
@@ -47,7 +49,7 @@ module.exports = {
4749
};
4850

4951
actions.power = {
50-
label: 'Power State',
52+
name: 'Power State',
5153
options: [
5254
{
5355
type: 'dropdown',
@@ -61,7 +63,7 @@ module.exports = {
6163
]
6264
}
6365
],
64-
callback: function(action, bank) {
66+
callback: async function(action) {
6567
if (action.options.power === 'power_off') {
6668
self.tv.control.power.off();
6769
}
@@ -75,7 +77,7 @@ module.exports = {
7577
};
7678

7779
actions.input = {
78-
label: 'Active Input',
80+
name: 'Active Input',
7981
options: [
8082
{
8183
type: 'dropdown',
@@ -84,27 +86,27 @@ module.exports = {
8486
choices: self.INPUTS
8587
}
8688
],
87-
callback: function(action, bank) {
89+
callback: async function(action) {
8890
self.tv.input.set(action.options.input);
8991
}
9092
};
9193

9294
actions.input_manual = {
93-
label: 'Active Input - Manual',
95+
name: 'Active Input - Manual',
9496
options: [
9597
{
9698
type: 'textinput',
9799
label: 'Enter name of the input to make active',
98100
id: 'input-manual'
99101
}
100102
],
101-
callback: function(action, bank) {
103+
callback: async function(action) {
102104
self.tv.input.set(action.options.input);
103105
}
104106
};
105107

106108
actions.mute = {
107-
label: 'Set Mute State',
109+
name: 'Set Mute State',
108110
options: [
109111
{
110112
type: 'dropdown',
@@ -114,7 +116,7 @@ module.exports = {
114116
choices: [{ label: 'Mute On', id: 'mute_on' }, { label: 'Mute Off', id: 'mute_off' }]
115117
}
116118
],
117-
callback: function(action, bank) {
119+
callback: async function(action) {
118120
if (action.options.mute === 'mute_off') {
119121
self.tv.control.volume.unmute();
120122
}
@@ -125,7 +127,7 @@ module.exports = {
125127
};
126128

127129
actions.volume = {
128-
label: 'Set Volume Level',
130+
name: 'Set Volume Level',
129131
options: [
130132
{
131133
type: 'number',
@@ -137,11 +139,11 @@ module.exports = {
137139
required: true
138140
}
139141
],
140-
callback: function(action, bank) {
142+
callback: async function(action) {
141143
self.tv.control.volume.set(action.options.volume);
142144
}
143145
}
144146

145-
return actions
147+
self.setActionDefinitions(actions);
146148
}
147149
}

0 commit comments

Comments
 (0)