forked from SphtKr/homebridge-itunes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHomeKitMediaTypes.js
300 lines (266 loc) · 13.3 KB
/
HomeKitMediaTypes.js
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
var inherits = require('util').inherits;
var Service, Characteristic;
module.exports = function(homebridge) {
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
var HomeKitMediaTypes = {};
// Characteristics
HomeKitMediaTypes.AudioVolume = function() {
Characteristic.call(this, 'Audio Volume', HomeKitMediaTypes.AudioVolume.UUID);
this.setProps({
format: Characteristic.Formats.UINT8,
unit: Characteristic.Units.PERCENTAGE,
maxValue: 100,
minValue: 0,
minStep: 1,
perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.AudioVolume.UUID = '00001001-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.AudioVolume, Characteristic);
HomeKitMediaTypes.Muting = function() {
Characteristic.call(this, 'Muting', HomeKitMediaTypes.Muting.UUID);
this.setProps({
format: Characteristic.Formats.UINT8,
perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.Muting.UUID = '00001002-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.Muting, Characteristic);
HomeKitMediaTypes.PlaybackState = function() {
Characteristic.call(this, 'Playback State', HomeKitMediaTypes.PlaybackState.UUID);
this.setProps({
format: Characteristic.Formats.UINT8,
perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.PlaybackState.UUID = '00002001-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.PlaybackState, Characteristic);
HomeKitMediaTypes.PlaybackState.PLAYING = 0;
HomeKitMediaTypes.PlaybackState.PAUSED = 1;
HomeKitMediaTypes.PlaybackState.STOPPED = 2;
HomeKitMediaTypes.SkipForward = function() {
Characteristic.call(this, 'Skip Forward', HomeKitMediaTypes.SkipForward.UUID);
this.setProps({
format: Characteristic.Formats.BOOL,
perms: [Characteristic.Perms.WRITE]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.SkipForward.UUID = '00002002-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.SkipForward, Characteristic);
HomeKitMediaTypes.SkipBackward = function() {
Characteristic.call(this, 'Skip Backward', HomeKitMediaTypes.SkipBackward.UUID);
this.setProps({
format: Characteristic.Formats.BOOL,
perms: [Characteristic.Perms.WRITE]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.SkipBackward.UUID = '00002003-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.SkipBackward, Characteristic);
HomeKitMediaTypes.ShuffleMode = function() {
Characteristic.call(this, 'Shuffle Mode', HomeKitMediaTypes.ShuffleMode.UUID);
this.setProps({
format: Characteristic.Formats.UINT8,
perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.ShuffleMode.UUID = '00002004-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.ShuffleMode, Characteristic);
//NOTE: If GROUP or SET is not supported, accessories should coerce to ALBUM.
// If ALBUM is not supported, coerce to ITEM.
// In general, it is recommended for apps to only assume OFF, ITEM, and ALBUM
// are supported unless it is known that the accessory supports other settings.
HomeKitMediaTypes.ShuffleMode.OFF = 0;
//NOTE: INDIVIDUAL is deprecated.
HomeKitMediaTypes.ShuffleMode.ITEM = HomeKitMediaTypes.ShuffleMode.INDIVIDUAL = 1;
HomeKitMediaTypes.ShuffleMode.GROUP = 2; // e.g. iTunes "Groupings"
HomeKitMediaTypes.ShuffleMode.ALBUM = 3; // e.g. album or season
HomeKitMediaTypes.ShuffleMode.SET = 4; // e.g. T.V. Series or album box set
HomeKitMediaTypes.RepeatMode = function() {
Characteristic.call(this, 'Repeat Mode', HomeKitMediaTypes.RepeatMode.UUID);
this.setProps({
format: Characteristic.Formats.UINT8,
perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.RepeatMode.UUID = '00002005-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.RepeatMode, Characteristic);
HomeKitMediaTypes.RepeatMode.OFF = 0;
HomeKitMediaTypes.RepeatMode.ONE = 1;
HomeKitMediaTypes.RepeatMode.ALL = 2;
HomeKitMediaTypes.PlaybackSpeed = function() {
Characteristic.call(this, 'Playback Speed', HomeKitMediaTypes.PlaybackSpeed.UUID);
this.setProps({
format: Characteristic.Formats.FLOAT,
perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.PlaybackSpeed.UUID = '00002006-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.PlaybackSpeed, Characteristic);
HomeKitMediaTypes.MediaCurrentPosition = function() {
Characteristic.call(this, 'Media Current Position', HomeKitMediaTypes.MediaCurrentPosition.UUID);
this.setProps({
format: Characteristic.Formats.FLOAT, // In seconds
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.MediaCurrentPosition.UUID = '00002007-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.MediaCurrentPosition, Characteristic);
HomeKitMediaTypes.MediaItemName = function() {
Characteristic.call(this, 'Media Name', HomeKitMediaTypes.MediaItemName.UUID);
this.setProps({
format: Characteristic.Formats.STRING,
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.MediaItemName.UUID = '00003001-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.MediaItemName, Characteristic);
HomeKitMediaTypes.MediaItemAlbumName = function() {
Characteristic.call(this, 'Media Album Name', HomeKitMediaTypes.MediaItemAlbumName.UUID);
this.setProps({
format: Characteristic.Formats.STRING,
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.MediaItemAlbumName.UUID = '00003002-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.MediaItemAlbumName, Characteristic);
HomeKitMediaTypes.MediaItemArtist = function() {
Characteristic.call(this, 'Media Artist', HomeKitMediaTypes.MediaItemArtist.UUID);
this.setProps({
format: Characteristic.Formats.STRING,
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.MediaItemArtist.UUID = '00003003-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.MediaItemArtist, Characteristic);
HomeKitMediaTypes.MediaItemDuration = function() {
Characteristic.call(this, 'Media Duration', HomeKitMediaTypes.MediaItemDuration.UUID);
this.setProps({
format: Characteristic.Formats.FLOAT, // In seconds
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.MediaItemDuration.UUID = '00003005-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.MediaItemDuration, Characteristic);
HomeKitMediaTypes.StillImage = function() {
Characteristic.call(this, 'Still Image', HomeKitMediaTypes.StillImage.UUID);
this.setProps({
format: Characteristic.Formats.DATA,
perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.StillImage.UUID = '00004001-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.StillImage, Characteristic);
// Also known as MIME type...
HomeKitMediaTypes.MediaTypeIdentifier = function() {
Characteristic.call(this, 'Media Type Identifier', HomeKitMediaTypes.MediaTypeIdentifier.UUID);
this.setProps({
format: Characteristic.Formats.STRING,
perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
});
this.value = null;
};
HomeKitMediaTypes.MediaTypeIdentifier.UUID = '00004002-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.MediaTypeIdentifier, Characteristic);
HomeKitMediaTypes.MediaWidth = function() {
Characteristic.call(this, 'Media Width', HomeKitMediaTypes.MediaWidth.UUID);
this.setProps({
format: Characteristic.Formats.UINT32,
perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.MediaWidth.UUID = '00004003-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.MediaWidth, Characteristic);
HomeKitMediaTypes.MediaHeight = function() {
Characteristic.call(this, 'Media Width', HomeKitMediaTypes.MediaHeight.UUID);
this.setProps({
format: Characteristic.Formats.UINT32,
perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
HomeKitMediaTypes.MediaHeight.UUID = '00004004-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.MediaHeight, Characteristic);
// Services
HomeKitMediaTypes.AudioDeviceService = function(displayName, subtype) {
Service.call(this, displayName, HomeKitMediaTypes.AudioDeviceService.UUID, subtype);
// Required Characteristics
this.addCharacteristic(HomeKitMediaTypes.AudioVolume);
// Optional Characteristics
this.addOptionalCharacteristic(HomeKitMediaTypes.Muting);
this.addOptionalCharacteristic(Characteristic.Name);
};
HomeKitMediaTypes.AudioDeviceService.UUID = '00000001-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.AudioDeviceService, Service);
HomeKitMediaTypes.PlaybackDeviceService = function(displayName, subtype) {
Service.call(this, displayName, HomeKitMediaTypes.PlaybackDeviceService.UUID, subtype);
// Required Characteristics
this.addCharacteristic(HomeKitMediaTypes.PlaybackState);
// Optional Characteristics
this.addOptionalCharacteristic(HomeKitMediaTypes.SkipForward);
this.addOptionalCharacteristic(HomeKitMediaTypes.SkipBackward);
this.addOptionalCharacteristic(HomeKitMediaTypes.ShuffleMode);
this.addOptionalCharacteristic(HomeKitMediaTypes.RepeatMode);
this.addOptionalCharacteristic(HomeKitMediaTypes.PlaybackSpeed);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaCurrentPosition);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaItemName);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaItemAlbumName);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaItemArtist);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaItemDuration);
this.addOptionalCharacteristic(Characteristic.Name);
// Artwork characteristics...would be better reported in a separate service?
this.addOptionalCharacteristic(HomeKitMediaTypes.StillImage);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaTypeIdentifier);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaWidth);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaHeight);
};
HomeKitMediaTypes.PlaybackDeviceService.UUID = '00000002-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.PlaybackDeviceService, Service);
// A media information service that has no playback controls, for e.g. DAB radio...
HomeKitMediaTypes.MediaInformationService = function(displayName, subtype) {
Service.call(this, displayName, HomeKitMediaTypes.MediaInformationService.UUID, subtype);
// Required Characteristics
this.addCharacteristic(HomeKitMediaTypes.MediaItemName);
// Optional Characteristics
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaItemAlbumName);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaItemArtist);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaItemDuration);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaCurrentPosition);
this.addOptionalCharacteristic(Characteristic.Name);
// Artwork characteristics...would be better reported in a separate service?
this.addOptionalCharacteristic(HomeKitMediaTypes.StillImage);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaTypeIdentifier);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaWidth);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaHeight);
};
HomeKitMediaTypes.MediaInformationService.UUID = '00000003-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.MediaInformationService, Service);
HomeKitMediaTypes.StillImageService = function(displayName, subtype) {
Service.call(this, displayName, HomeKitMediaTypes.StillImageService.UUID, subtype);
// Required Characteristics
this.addCharacteristic(HomeKitMediaTypes.StillImage);
this.addCharacteristic(HomeKitMediaTypes.MediaTypeIdentifier);
// Optional Characteristics
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaWidth);
this.addOptionalCharacteristic(HomeKitMediaTypes.MediaHeight);
this.addOptionalCharacteristic(Characteristic.Name);
};
HomeKitMediaTypes.StillImageService.UUID = '00000004-0000-1000-8000-135D67EC4377';
inherits(HomeKitMediaTypes.StillImageService, Service);
return HomeKitMediaTypes;
};