homebridge-bedjet 0.2.9 → 0.3.0
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/accessory.js +17 -2
- package/package.json +1 -1
- package/src/accessory.ts +18 -2
package/dist/accessory.js
CHANGED
|
@@ -10,6 +10,20 @@ const DEFAULT_MODE_MAP = {
|
|
|
10
10
|
cool: constants_1.OperatingMode.COOL,
|
|
11
11
|
dry: constants_1.OperatingMode.DRY,
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* HomeKit only allows alphanumeric, space, and apostrophe characters in names,
|
|
15
|
+
* starting and ending with alphanumeric. Underscores and other punctuation
|
|
16
|
+
* cause HAP warnings and may prevent the accessory from pairing.
|
|
17
|
+
*/
|
|
18
|
+
function sanitizeName(name) {
|
|
19
|
+
return name
|
|
20
|
+
.replace(/_/g, ' ') // underscores → spaces
|
|
21
|
+
.replace(/[^a-zA-Z0-9 ']/g, ' ') // anything else invalid → space
|
|
22
|
+
.replace(/\s+/g, ' ') // collapse multiple spaces
|
|
23
|
+
.trim()
|
|
24
|
+
.replace(/^[^a-zA-Z0-9]+/, '') // must start with alphanumeric
|
|
25
|
+
.replace(/[^a-zA-Z0-9]+$/, '') || 'BedJet'; // must end with alphanumeric
|
|
26
|
+
}
|
|
13
27
|
// OperatingMode → CurrentHeatingCoolingState value
|
|
14
28
|
const CURRENT_STATE_MAP = {
|
|
15
29
|
[constants_1.OperatingMode.STANDBY]: 0, // OFF
|
|
@@ -52,6 +66,7 @@ class BedJetAccessory {
|
|
|
52
66
|
this.pendingMode = null;
|
|
53
67
|
this.pendingModeTimer = null;
|
|
54
68
|
const { Service, Characteristic } = platform.api.hap;
|
|
69
|
+
const safeName = sanitizeName(config.name);
|
|
55
70
|
// AccessoryInformation
|
|
56
71
|
const infoService = this.accessory.getService(Service.AccessoryInformation)
|
|
57
72
|
?? this.accessory.addService(Service.AccessoryInformation);
|
|
@@ -61,7 +76,7 @@ class BedJetAccessory {
|
|
|
61
76
|
.setCharacteristic(Characteristic.SerialNumber, config.address);
|
|
62
77
|
// Thermostat service
|
|
63
78
|
this.thermostatService = this.accessory.getService(Service.Thermostat)
|
|
64
|
-
?? this.accessory.addService(Service.Thermostat,
|
|
79
|
+
?? this.accessory.addService(Service.Thermostat, safeName, 'thermostat');
|
|
65
80
|
this.thermostatService.getCharacteristic(Characteristic.TemperatureDisplayUnits)
|
|
66
81
|
.onGet(() => Characteristic.TemperatureDisplayUnits.CELSIUS);
|
|
67
82
|
this.thermostatService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
@@ -100,7 +115,7 @@ class BedJetAccessory {
|
|
|
100
115
|
});
|
|
101
116
|
// FanV2 service
|
|
102
117
|
this.fanService = this.accessory.getService(Service.Fanv2)
|
|
103
|
-
?? this.accessory.addService(Service.Fanv2, `${
|
|
118
|
+
?? this.accessory.addService(Service.Fanv2, `${safeName} Fan`, 'fan');
|
|
104
119
|
this.fanService.getCharacteristic(Characteristic.Active)
|
|
105
120
|
.onGet(() => this.bedjet.state.operatingMode !== constants_1.OperatingMode.STANDBY
|
|
106
121
|
? Characteristic.Active.ACTIVE
|
package/package.json
CHANGED
package/src/accessory.ts
CHANGED
|
@@ -12,6 +12,21 @@ const DEFAULT_MODE_MAP: Record<DefaultMode, OperatingMode> = {
|
|
|
12
12
|
dry: OperatingMode.DRY,
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* HomeKit only allows alphanumeric, space, and apostrophe characters in names,
|
|
17
|
+
* starting and ending with alphanumeric. Underscores and other punctuation
|
|
18
|
+
* cause HAP warnings and may prevent the accessory from pairing.
|
|
19
|
+
*/
|
|
20
|
+
function sanitizeName(name: string): string {
|
|
21
|
+
return name
|
|
22
|
+
.replace(/_/g, ' ') // underscores → spaces
|
|
23
|
+
.replace(/[^a-zA-Z0-9 ']/g, ' ') // anything else invalid → space
|
|
24
|
+
.replace(/\s+/g, ' ') // collapse multiple spaces
|
|
25
|
+
.trim()
|
|
26
|
+
.replace(/^[^a-zA-Z0-9]+/, '') // must start with alphanumeric
|
|
27
|
+
.replace(/[^a-zA-Z0-9]+$/, '') || 'BedJet'; // must end with alphanumeric
|
|
28
|
+
}
|
|
29
|
+
|
|
15
30
|
// OperatingMode → CurrentHeatingCoolingState value
|
|
16
31
|
const CURRENT_STATE_MAP: Record<OperatingMode, number> = {
|
|
17
32
|
[OperatingMode.STANDBY]: 0, // OFF
|
|
@@ -69,6 +84,7 @@ export class BedJetAccessory {
|
|
|
69
84
|
private readonly config: BedJetConfig,
|
|
70
85
|
) {
|
|
71
86
|
const { Service, Characteristic } = platform.api.hap;
|
|
87
|
+
const safeName = sanitizeName(config.name);
|
|
72
88
|
|
|
73
89
|
// AccessoryInformation
|
|
74
90
|
const infoService = this.accessory.getService(Service.AccessoryInformation)
|
|
@@ -80,7 +96,7 @@ export class BedJetAccessory {
|
|
|
80
96
|
|
|
81
97
|
// Thermostat service
|
|
82
98
|
this.thermostatService = this.accessory.getService(Service.Thermostat)
|
|
83
|
-
?? this.accessory.addService(Service.Thermostat,
|
|
99
|
+
?? this.accessory.addService(Service.Thermostat, safeName, 'thermostat');
|
|
84
100
|
|
|
85
101
|
this.thermostatService.getCharacteristic(Characteristic.TemperatureDisplayUnits)
|
|
86
102
|
.onGet(() => Characteristic.TemperatureDisplayUnits.CELSIUS);
|
|
@@ -127,7 +143,7 @@ export class BedJetAccessory {
|
|
|
127
143
|
|
|
128
144
|
// FanV2 service
|
|
129
145
|
this.fanService = this.accessory.getService(Service.Fanv2)
|
|
130
|
-
?? this.accessory.addService(Service.Fanv2, `${
|
|
146
|
+
?? this.accessory.addService(Service.Fanv2, `${safeName} Fan`, 'fan');
|
|
131
147
|
|
|
132
148
|
this.fanService.getCharacteristic(Characteristic.Active)
|
|
133
149
|
.onGet(() =>
|