-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
83 lines (68 loc) · 2.32 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { InstanceBase, runEntrypoint, InstanceStatus, type CompanionVariableDefinition, type CompanionVariableValues, type CompanionActionDefinition, type CompanionActionDefinitions, type CompanionFeedbackDefinitions, type OSCSomeArguments, type OSCMetaArgument, type OSCArgument } from '@companion-module/base'
import { Regex, type SomeCompanionConfigField } from '@companion-module/base'
import { ResiApi } from './resi_api.js'
import { getActions } from './actions.js'
import { getFeedbacks } from './feedbacks.js'
export class ModuleInstance extends InstanceBase<any> {
resiApi: any;
constructor(internal: any) {
super(internal)
this.log('debug', 'ok')
}
async init(config: any) {
if (config && config.username && config.password) {
await this.createAPI(config)
} else
this.updateStatus(InstanceStatus.BadConfig, 'No username or password')
}
// When module gets deleted
async destroy() {
this.log('debug', 'destroy')
}
async configUpdated(config: any) {
await this.createAPI(config)
}
// Return config fields for web config
getConfigFields(): SomeCompanionConfigField[] {
return [
{
type: 'textinput',
id: 'username',
label: 'Resi Username',
tooltip: 'Email address used to login to Resi',
width: 6,
regex: Regex.SOMETHING
},
{
type: 'textinput',
id: 'password',
label: 'Resi Password',
tooltip: 'Password used to login to Resi',
width: 6,
regex: Regex.SOMETHING
}
]
}
async createAPI(config: any) {
this.log('debug', 'Creating API client')
try {
this.updateStatus(InstanceStatus.Connecting);
this.resiApi = new ResiApi(config.username, config.password);
this.log('debug', 'Getting token')
await this.resiApi.getToken();
this.log('debug', 'Getting user data')
await this.resiApi.getMe();
this.log('debug', 'API client created')
this.log('debug', 'Getting actions')
this.setActionDefinitions(await getActions(this))
this.log('debug', 'Got actions')
this.log('debug', 'Getting feedbacks')
this.setFeedbackDefinitions(await getFeedbacks(this))
this.log('debug', 'Got feedbacks')
this.updateStatus(this.resiApi.needsUserData() ? InstanceStatus.ConnectionFailure : InstanceStatus.Ok)
} catch (e) {
this.updateStatus(InstanceStatus.ConnectionFailure, e.message)
}
}
}
runEntrypoint(ModuleInstance, [])