-
-
Notifications
You must be signed in to change notification settings - Fork 628
/
Copy pathTV_accessory.ts
140 lines (112 loc) · 4.99 KB
/
TV_accessory.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import {
AccessControlEvent,
AccessControlManagement,
AccessLevel,
Accessory,
Categories,
Characteristic,
CharacteristicEventTypes,
CharacteristicSetCallback,
CharacteristicValue,
Service,
uuid,
} from "..";
// Generate a consistent UUID for TV that will remain the same even when
// restarting our server. We use the `uuid.generate` helper function to create a deterministic
// UUID based on an arbitrary "namespace" and the word "tv".
const tvUUID = uuid.generate("hap-nodejs:accessories:tv");
// This is the Accessory that we'll return to HAP-NodeJS.
const tv = exports.accessory = new Accessory("TV", tvUUID);
// Add properties for publishing (in case we're using Core.js and not BridgedCore.js)
// @ts-expect-error: Core/BridgeCore API
tv.username = "A3:FB:3D:4D:2E:AC";
// @ts-expect-error: Core/BridgeCore API
tv.pincode = "031-45-154";
tv.category = Categories.TELEVISION;
// Add the actual TV Service and listen for change events from iOS.
const televisionService = tv.addService(Service.Television, "Television", "Television");
televisionService
.setCharacteristic(Characteristic.ConfiguredName, "Television");
televisionService
.setCharacteristic(
Characteristic.SleepDiscoveryMode,
Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE,
);
televisionService
.getCharacteristic(Characteristic.Active)!
.on(CharacteristicEventTypes.SET, (newValue: CharacteristicValue, callback: CharacteristicSetCallback) => {
console.log("set Active => setNewValue: " + newValue);
callback(null);
});
televisionService
.setCharacteristic(Characteristic.ActiveIdentifier, 1);
televisionService
.getCharacteristic(Characteristic.ActiveIdentifier)!
.on(CharacteristicEventTypes.SET, (newValue: CharacteristicValue, callback: CharacteristicSetCallback) => {
console.log("set Active Identifier => setNewValue: " + newValue);
callback(null);
});
televisionService
.getCharacteristic(Characteristic.RemoteKey)!
.on(CharacteristicEventTypes.SET, (newValue: CharacteristicValue, callback: CharacteristicSetCallback) => {
console.log("set Remote Key => setNewValue: " + newValue);
callback(null);
});
televisionService
.getCharacteristic(Characteristic.PictureMode)!
.on(CharacteristicEventTypes.SET, (newValue: CharacteristicValue, callback: CharacteristicSetCallback) => {
console.log("set PictureMode => setNewValue: " + newValue);
callback(null);
});
televisionService
.getCharacteristic(Characteristic.PowerModeSelection)!
.on(CharacteristicEventTypes.SET, (newValue: CharacteristicValue, callback: CharacteristicSetCallback) => {
console.log("set PowerModeSelection => setNewValue: " + newValue);
callback(null);
});
// Speaker
const speakerService = tv.addService(Service.TelevisionSpeaker);
speakerService
.setCharacteristic(Characteristic.Active, Characteristic.Active.ACTIVE)
.setCharacteristic(Characteristic.VolumeControlType, Characteristic.VolumeControlType.ABSOLUTE);
speakerService.getCharacteristic(Characteristic.VolumeSelector)!
.on(CharacteristicEventTypes.SET, (newValue: CharacteristicValue, callback: CharacteristicSetCallback) => {
console.log("set VolumeSelector => setNewValue: " + newValue);
callback(null);
});
// HDMI 1
const inputHDMI1 = tv.addService(Service.InputSource, "hdmi1", "HDMI 1");
inputHDMI1
.setCharacteristic(Characteristic.Identifier, 1)
.setCharacteristic(Characteristic.ConfiguredName, "HDMI 1")
.setCharacteristic(Characteristic.IsConfigured, Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(Characteristic.InputSourceType, Characteristic.InputSourceType.HDMI);
// HDMI 2
const inputHDMI2 = tv.addService(Service.InputSource, "hdmi2", "HDMI 2");
inputHDMI2
.setCharacteristic(Characteristic.Identifier, 2)
.setCharacteristic(Characteristic.ConfiguredName, "HDMI 2")
.setCharacteristic(Characteristic.IsConfigured, Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(Characteristic.InputSourceType, Characteristic.InputSourceType.HDMI);
// Netflix
const inputNetflix = tv.addService(Service.InputSource, "netflix", "Netflix");
inputNetflix
.setCharacteristic(Characteristic.Identifier, 3)
.setCharacteristic(Characteristic.ConfiguredName, "Netflix")
.setCharacteristic(Characteristic.IsConfigured, Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(Characteristic.InputSourceType, Characteristic.InputSourceType.APPLICATION);
televisionService.addLinkedService(inputHDMI1);
televisionService.addLinkedService(inputHDMI2);
televisionService.addLinkedService(inputNetflix);
const accessControl = new AccessControlManagement(true);
accessControl.on(AccessControlEvent.ACCESS_LEVEL_UPDATED, (level: AccessLevel) => {
console.log("New access control level of " + level);
});
accessControl.on(AccessControlEvent.PASSWORD_SETTING_UPDATED, (password: string | undefined, passwordRequired: boolean) => {
if (passwordRequired) {
console.log("A required password was specified");
} else {
console.log("No password set!");
}
});
tv.addService(accessControl.getService());