homebridge-plugin-utils 1.6.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/service.js +23 -12
- package/dist/service.js.map +1 -1
- package/package.json +2 -2
package/dist/service.js
CHANGED
|
@@ -14,23 +14,39 @@
|
|
|
14
14
|
* @category Accessory
|
|
15
15
|
*/
|
|
16
16
|
export function acquireService(hap, accessory, serviceType, name, subtype, onServiceCreate) {
|
|
17
|
+
// Services that do not need the Name characteristic added as an optional characteristic.
|
|
18
|
+
const configuredNameRequiredServices = [hap.Service.InputSource, hap.Service.Television, hap.Service.WiFiRouter];
|
|
17
19
|
// Services that need the ConfiguredName characteristic added and maintained.
|
|
18
|
-
const configuredNameServices = [hap.Service.
|
|
20
|
+
const configuredNameServices = [hap.Service.AccessoryInformation, hap.Service.ContactSensor, hap.Service.Lightbulb, hap.Service.MotionSensor,
|
|
21
|
+
hap.Service.OccupancySensor, hap.Service.SmartSpeaker, hap.Service.Switch, hap.Service.Valve];
|
|
22
|
+
// Services that do not need the Name characteristic added as an optional characteristic.
|
|
23
|
+
const nameRequiredServices = [hap.Service.AccessoryInformation, hap.Service.Assistant, hap.Service.InputSource];
|
|
19
24
|
// Services that need the Name characteristic maintained.
|
|
20
|
-
const nameServices = [hap.Service.
|
|
21
|
-
hap.Service.
|
|
25
|
+
const nameServices = [hap.Service.AirPurifier, hap.Service.AirQualitySensor, hap.Service.Battery, hap.Service.CarbonDioxideSensor,
|
|
26
|
+
hap.Service.CarbonMonoxideSensor, hap.Service.ContactSensor, hap.Service.Door, hap.Service.Doorbell, hap.Service.Fan, hap.Service.Fanv2, hap.Service.Faucet,
|
|
27
|
+
hap.Service.FilterMaintenance, hap.Service.GarageDoorOpener, hap.Service.HeaterCooler, hap.Service.HumidifierDehumidifier, hap.Service.HumiditySensor,
|
|
28
|
+
hap.Service.IrrigationSystem, hap.Service.LeakSensor, hap.Service.Lightbulb, hap.Service.LightSensor, hap.Service.LockMechanism, hap.Service.MotionSensor,
|
|
29
|
+
hap.Service.OccupancySensor, hap.Service.Outlet, hap.Service.SecuritySystem, hap.Service.Slats, hap.Service.SmartSpeaker, hap.Service.SmokeSensor,
|
|
30
|
+
hap.Service.StatefulProgrammableSwitch, hap.Service.StatelessProgrammableSwitch, hap.Service.Switch, hap.Service.TargetControl, hap.Service.Television,
|
|
31
|
+
hap.Service.TemperatureSensor, hap.Service.Thermostat, hap.Service.Valve, hap.Service.Window, hap.Service.WindowCovering];
|
|
22
32
|
// Find the service, if it exists.
|
|
23
33
|
let service = subtype ? accessory.getServiceById(serviceType, subtype) : accessory.getService(serviceType);
|
|
24
34
|
// Add the service to the accessory, if needed.
|
|
25
35
|
if (!service) {
|
|
26
|
-
// @ts-expect-error TypeScript tries to associate this with an overloaded version of the addService method. However, Homebridge/HAP-NodeJS isn't exporting
|
|
27
|
-
// a version of the method that implements the unexposed interface that's been defined for each service class (e.g. Lightbulb). The constructor on the
|
|
28
|
-
// service-type-specific version of the service takes the following arguments: constructor(displayName?: string, subtype?: string). We're safe, but because
|
|
29
|
-
// the type definitions are missing, we need to override it here.
|
|
30
36
|
service = new serviceType(name, subtype);
|
|
31
37
|
if (!service) {
|
|
32
38
|
return null;
|
|
33
39
|
}
|
|
40
|
+
// Add the Configured Name characteristic if we don't already have it and it's available to us.
|
|
41
|
+
if (!configuredNameRequiredServices.includes(serviceType) && configuredNameServices.includes(serviceType) &&
|
|
42
|
+
!service.optionalCharacteristics.some(x => (x.UUID === hap.Characteristic.ConfiguredName.UUID))) {
|
|
43
|
+
service.addOptionalCharacteristic(hap.Characteristic.ConfiguredName);
|
|
44
|
+
}
|
|
45
|
+
// Add the Name characteristic if we don't already have it and it's available to us.
|
|
46
|
+
if (!nameRequiredServices.includes(serviceType) && nameServices.includes(serviceType) &&
|
|
47
|
+
!service.optionalCharacteristics.some(x => (x.UUID === hap.Characteristic.Name.UUID))) {
|
|
48
|
+
service.addOptionalCharacteristic(hap.Characteristic.Name);
|
|
49
|
+
}
|
|
34
50
|
accessory.addService(service);
|
|
35
51
|
if (onServiceCreate) {
|
|
36
52
|
onServiceCreate(service);
|
|
@@ -39,11 +55,6 @@ export function acquireService(hap, accessory, serviceType, name, subtype, onSer
|
|
|
39
55
|
// Update our name.
|
|
40
56
|
service.displayName = name;
|
|
41
57
|
if (configuredNameServices.includes(serviceType)) {
|
|
42
|
-
// Add the characteristic if we don't already have it. We do this here instead of at service creation to ensure we catch legacy situations where we may have
|
|
43
|
-
// already created the service previously without adding the optional characteristics we want.
|
|
44
|
-
if (!service.optionalCharacteristics.some(x => (x.UUID === hap.Characteristic.ConfiguredName.UUID))) {
|
|
45
|
-
service.addOptionalCharacteristic(hap.Characteristic.ConfiguredName);
|
|
46
|
-
}
|
|
47
58
|
service.updateCharacteristic(hap.Characteristic.ConfiguredName, name);
|
|
48
59
|
}
|
|
49
60
|
if (nameServices.includes(serviceType)) {
|
package/dist/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAAC,GAAQ,EAAE,SAA4B,EAAE,WAAqC,EAAE,IAAY,EAAE,OAAgB,EAC1I,eAAwC;IAExC,6EAA6E;IAC7E,MAAM,sBAAsB,GAAG,CAAE,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAAC,GAAQ,EAAE,SAA4B,EAAE,WAAqC,EAAE,IAAY,EAAE,OAAgB,EAC1I,eAAwC;IAExC,yFAAyF;IACzF,MAAM,8BAA8B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E,IAAI,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,SAA4B,EAAE,WAAqC,EAAE,QAA0C,EAAE,OAAgB;IAE5J,yCAAyC;IACzC,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAE7G,kEAAkE;IAClE,IAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;QAExB,IAAG,OAAO,EAAE,CAAC;YAEX,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,2BAA2B;IAC3B,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-plugin-utils",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"displayName": "Homebridge Plugin Utilities",
|
|
5
5
|
"description": "Opinionated utilities to provide common capabilities and create rich configuration webUI experiences for Homebridge plugins.",
|
|
6
6
|
"author": {
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"@stylistic/eslint-plugin": "2.3.0",
|
|
43
43
|
"@types/node": "20.14.11",
|
|
44
44
|
"eslint": "8.57.0",
|
|
45
|
+
"homebridge": "^1.8.4",
|
|
45
46
|
"shx": "^0.3.4",
|
|
46
47
|
"typescript": "5.5.3",
|
|
47
48
|
"typescript-eslint": "^7.16.1"
|
|
48
49
|
},
|
|
49
50
|
"dependencies": {
|
|
50
|
-
"homebridge": "^1.8.4",
|
|
51
51
|
"mqtt": "^5.8.1"
|
|
52
52
|
}
|
|
53
53
|
}
|