matterbridge 3.2.6 → 3.2.7-dev-20250908-3bb699e
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/CHANGELOG.md +20 -0
- package/dist/cli.js +2 -91
- package/dist/cliEmitter.js +0 -30
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +3 -24
- package/dist/deviceManager.js +1 -94
- package/dist/devices/airConditioner.js +0 -57
- package/dist/devices/batteryStorage.js +1 -48
- package/dist/devices/cooktop.js +0 -55
- package/dist/devices/dishwasher.js +0 -57
- package/dist/devices/evse.js +10 -74
- package/dist/devices/export.js +0 -5
- package/dist/devices/extractorHood.js +0 -42
- package/dist/devices/heatPump.js +2 -50
- package/dist/devices/laundryDryer.js +3 -62
- package/dist/devices/laundryWasher.js +4 -70
- package/dist/devices/microwaveOven.js +5 -88
- package/dist/devices/oven.js +0 -85
- package/dist/devices/refrigerator.js +0 -102
- package/dist/devices/roboticVacuumCleaner.js +9 -100
- package/dist/devices/solarPower.js +0 -38
- package/dist/devices/speaker.js +0 -80
- package/dist/devices/temperatureControl.js +3 -25
- package/dist/devices/waterHeater.js +2 -82
- package/dist/dgram/coap.js +13 -126
- package/dist/dgram/dgram.js +2 -114
- package/dist/dgram/mb_coap.js +3 -41
- package/dist/dgram/mb_mdns.js +15 -80
- package/dist/dgram/mdns.js +137 -299
- package/dist/dgram/multicast.js +1 -62
- package/dist/dgram/unicast.js +0 -54
- package/dist/frontend.js +24 -450
- package/dist/globalMatterbridge.js +0 -47
- package/dist/helpers.js +0 -53
- package/dist/index.js +1 -30
- package/dist/jest-utils/jestHelpers.js +2 -124
- package/dist/logger/export.js +0 -1
- package/dist/matter/behaviors.js +0 -2
- package/dist/matter/clusters.js +0 -2
- package/dist/matter/devices.js +0 -2
- package/dist/matter/endpoints.js +0 -2
- package/dist/matter/export.js +0 -3
- package/dist/matter/types.js +0 -3
- package/dist/matterbridge.js +49 -780
- package/dist/matterbridgeAccessoryPlatform.js +0 -36
- package/dist/matterbridgeBehaviors.js +5 -65
- package/dist/matterbridgeDeviceTypes.js +17 -630
- package/dist/matterbridgeDynamicPlatform.js +0 -36
- package/dist/matterbridgeEndpoint.js +54 -1301
- package/dist/matterbridgeEndpointHelpers.js +12 -345
- package/dist/matterbridgePlatform.js +1 -305
- package/dist/matterbridgeTypes.js +0 -25
- package/dist/pluginManager.js +5 -251
- package/dist/shelly.js +7 -168
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -69
- package/dist/utils/colorUtils.js +2 -97
- package/dist/utils/commandLine.js +0 -54
- package/dist/utils/copyDirectory.js +1 -38
- package/dist/utils/createDirectory.js +0 -33
- package/dist/utils/createZip.js +2 -47
- package/dist/utils/deepCopy.js +0 -39
- package/dist/utils/deepEqual.js +1 -72
- package/dist/utils/error.js +0 -41
- package/dist/utils/export.js +0 -1
- package/dist/utils/hex.js +0 -124
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/network.js +6 -92
- package/dist/utils/spawn.js +0 -40
- package/dist/utils/wait.js +8 -60
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -2
- package/dist/cli.d.ts +0 -26
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cliEmitter.d.ts +0 -34
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.js.map +0 -1
- package/dist/clusters/export.d.ts +0 -2
- package/dist/clusters/export.d.ts.map +0 -1
- package/dist/clusters/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -28
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -112
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/devices/airConditioner.d.ts +0 -98
- package/dist/devices/airConditioner.d.ts.map +0 -1
- package/dist/devices/airConditioner.js.map +0 -1
- package/dist/devices/batteryStorage.d.ts +0 -48
- package/dist/devices/batteryStorage.d.ts.map +0 -1
- package/dist/devices/batteryStorage.js.map +0 -1
- package/dist/devices/cooktop.d.ts +0 -60
- package/dist/devices/cooktop.d.ts.map +0 -1
- package/dist/devices/cooktop.js.map +0 -1
- package/dist/devices/dishwasher.d.ts +0 -71
- package/dist/devices/dishwasher.d.ts.map +0 -1
- package/dist/devices/dishwasher.js.map +0 -1
- package/dist/devices/evse.d.ts +0 -75
- package/dist/devices/evse.d.ts.map +0 -1
- package/dist/devices/evse.js.map +0 -1
- package/dist/devices/export.d.ts +0 -17
- package/dist/devices/export.d.ts.map +0 -1
- package/dist/devices/export.js.map +0 -1
- package/dist/devices/extractorHood.d.ts +0 -46
- package/dist/devices/extractorHood.d.ts.map +0 -1
- package/dist/devices/extractorHood.js.map +0 -1
- package/dist/devices/heatPump.d.ts +0 -47
- package/dist/devices/heatPump.d.ts.map +0 -1
- package/dist/devices/heatPump.js.map +0 -1
- package/dist/devices/laundryDryer.d.ts +0 -67
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -81
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.js.map +0 -1
- package/dist/devices/microwaveOven.d.ts +0 -168
- package/dist/devices/microwaveOven.d.ts.map +0 -1
- package/dist/devices/microwaveOven.js.map +0 -1
- package/dist/devices/oven.d.ts +0 -105
- package/dist/devices/oven.d.ts.map +0 -1
- package/dist/devices/oven.js.map +0 -1
- package/dist/devices/refrigerator.d.ts +0 -118
- package/dist/devices/refrigerator.d.ts.map +0 -1
- package/dist/devices/refrigerator.js.map +0 -1
- package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
- package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/devices/roboticVacuumCleaner.js.map +0 -1
- package/dist/devices/solarPower.d.ts +0 -40
- package/dist/devices/solarPower.d.ts.map +0 -1
- package/dist/devices/solarPower.js.map +0 -1
- package/dist/devices/speaker.d.ts +0 -83
- package/dist/devices/speaker.d.ts.map +0 -1
- package/dist/devices/speaker.js.map +0 -1
- package/dist/devices/temperatureControl.d.ts +0 -166
- package/dist/devices/temperatureControl.d.ts.map +0 -1
- package/dist/devices/temperatureControl.js.map +0 -1
- package/dist/devices/waterHeater.d.ts +0 -111
- package/dist/devices/waterHeater.d.ts.map +0 -1
- package/dist/devices/waterHeater.js.map +0 -1
- package/dist/dgram/coap.d.ts +0 -205
- package/dist/dgram/coap.d.ts.map +0 -1
- package/dist/dgram/coap.js.map +0 -1
- package/dist/dgram/dgram.d.ts +0 -141
- package/dist/dgram/dgram.d.ts.map +0 -1
- package/dist/dgram/dgram.js.map +0 -1
- package/dist/dgram/mb_coap.d.ts +0 -24
- package/dist/dgram/mb_coap.d.ts.map +0 -1
- package/dist/dgram/mb_coap.js.map +0 -1
- package/dist/dgram/mb_mdns.d.ts +0 -24
- package/dist/dgram/mb_mdns.d.ts.map +0 -1
- package/dist/dgram/mb_mdns.js.map +0 -1
- package/dist/dgram/mdns.d.ts +0 -290
- package/dist/dgram/mdns.d.ts.map +0 -1
- package/dist/dgram/mdns.js.map +0 -1
- package/dist/dgram/multicast.d.ts +0 -67
- package/dist/dgram/multicast.d.ts.map +0 -1
- package/dist/dgram/multicast.js.map +0 -1
- package/dist/dgram/unicast.d.ts +0 -56
- package/dist/dgram/unicast.d.ts.map +0 -1
- package/dist/dgram/unicast.js.map +0 -1
- package/dist/frontend.d.ts +0 -313
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/globalMatterbridge.d.ts +0 -59
- package/dist/globalMatterbridge.d.ts.map +0 -1
- package/dist/globalMatterbridge.js.map +0 -1
- package/dist/helpers.d.ts +0 -48
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js.map +0 -1
- package/dist/index.d.ts +0 -33
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/jest-utils/jestHelpers.d.ts +0 -103
- package/dist/jest-utils/jestHelpers.d.ts.map +0 -1
- package/dist/jest-utils/jestHelpers.js.map +0 -1
- package/dist/logger/export.d.ts +0 -2
- package/dist/logger/export.d.ts.map +0 -1
- package/dist/logger/export.js.map +0 -1
- package/dist/matter/behaviors.d.ts +0 -2
- package/dist/matter/behaviors.d.ts.map +0 -1
- package/dist/matter/behaviors.js.map +0 -1
- package/dist/matter/clusters.d.ts +0 -2
- package/dist/matter/clusters.d.ts.map +0 -1
- package/dist/matter/clusters.js.map +0 -1
- package/dist/matter/devices.d.ts +0 -2
- package/dist/matter/devices.d.ts.map +0 -1
- package/dist/matter/devices.js.map +0 -1
- package/dist/matter/endpoints.d.ts +0 -2
- package/dist/matter/endpoints.d.ts.map +0 -1
- package/dist/matter/endpoints.js.map +0 -1
- package/dist/matter/export.d.ts +0 -5
- package/dist/matter/export.d.ts.map +0 -1
- package/dist/matter/export.js.map +0 -1
- package/dist/matter/types.d.ts +0 -3
- package/dist/matter/types.d.ts.map +0 -1
- package/dist/matter/types.js.map +0 -1
- package/dist/matterbridge.d.ts +0 -457
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1351
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -761
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1438
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -407
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -379
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -198
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -270
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -174
- package/dist/shelly.d.ts.map +0 -1
- package/dist/shelly.js.map +0 -1
- package/dist/storage/export.d.ts +0 -2
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/update.d.ts +0 -75
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -99
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/commandLine.d.ts +0 -59
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -33
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createDirectory.d.ts +0 -34
- package/dist/utils/createDirectory.d.ts.map +0 -1
- package/dist/utils/createDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -39
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -32
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -54
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/error.d.ts +0 -44
- package/dist/utils/error.d.ts.map +0 -1
- package/dist/utils/error.js.map +0 -1
- package/dist/utils/export.d.ts +0 -13
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/hex.d.ts +0 -89
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -103
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/network.d.ts +0 -84
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/spawn.d.ts +0 -33
- package/dist/utils/spawn.d.ts.map +0 -1
- package/dist/utils/spawn.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -54
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
package/dist/shelly.js
CHANGED
|
@@ -1,54 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the shelly api functions.
|
|
3
|
-
*
|
|
4
|
-
* @file shelly.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @created 2025-02-19
|
|
7
|
-
* @version 1.1.0
|
|
8
|
-
* @license Apache-2.0
|
|
9
|
-
*
|
|
10
|
-
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
11
|
-
*
|
|
12
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License.
|
|
14
|
-
* You may obtain a copy of the License at
|
|
15
|
-
*
|
|
16
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
-
* See the License for the specific language governing permissions and
|
|
22
|
-
* limitations under the License.
|
|
23
|
-
*/
|
|
24
1
|
import { debugStringify } from 'node-ansi-logger';
|
|
25
2
|
import { WS_ID_SHELLY_MAIN_UPDATE, WS_ID_SHELLY_SYS_UPDATE } from './frontend.js';
|
|
26
3
|
let verifyIntervalSecs = 15;
|
|
27
4
|
let verifyTimeoutSecs = 600;
|
|
28
|
-
/**
|
|
29
|
-
* Sets the interval for verification in seconds.
|
|
30
|
-
*
|
|
31
|
-
* @param {number} seconds - The interval in seconds.
|
|
32
|
-
* @returns {void}
|
|
33
|
-
*/
|
|
34
5
|
export function setVerifyIntervalSecs(seconds) {
|
|
35
6
|
verifyIntervalSecs = seconds;
|
|
36
7
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Sets the timeout for verification in seconds.
|
|
39
|
-
*
|
|
40
|
-
* @param {number} seconds - The timeout in seconds.
|
|
41
|
-
* @returns {void}
|
|
42
|
-
*/
|
|
43
8
|
export function setVerifyTimeoutSecs(seconds) {
|
|
44
9
|
verifyTimeoutSecs = seconds;
|
|
45
10
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Fetches Shelly system updates. If available: logs the result, sends a snackbar message, and broadcasts the message.
|
|
48
|
-
*
|
|
49
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
50
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
51
|
-
*/
|
|
52
11
|
export async function getShellySysUpdate(matterbridge) {
|
|
53
12
|
try {
|
|
54
13
|
const updates = (await getShelly('/api/updates/sys/check'));
|
|
@@ -67,33 +26,19 @@ export async function getShellySysUpdate(matterbridge) {
|
|
|
67
26
|
matterbridge.log.error(`Error getting Shelly system updates: ${err instanceof Error ? err.message : String(err)}`);
|
|
68
27
|
}
|
|
69
28
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Triggers Shelly system updates.
|
|
72
|
-
*
|
|
73
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
74
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
75
|
-
*/
|
|
76
29
|
export async function triggerShellySysUpdate(matterbridge) {
|
|
77
30
|
try {
|
|
78
|
-
// Trigger the update request
|
|
79
31
|
await getShelly('/api/updates/sys/perform');
|
|
80
32
|
matterbridge.log.notice('Installing Shelly system update...');
|
|
81
33
|
matterbridge.matterbridgeInformation.shellySysUpdate = false;
|
|
82
34
|
matterbridge.frontend.wssSendSnackbarMessage('Installing Shelly system update...', 15);
|
|
83
35
|
matterbridge.frontend.wssBroadcastMessage(WS_ID_SHELLY_SYS_UPDATE, 'shelly-sys-update', { available: false });
|
|
84
|
-
// Begin polling update status
|
|
85
36
|
await verifyShellyUpdate(matterbridge, '/api/updates/sys/status', 'Shelly system update');
|
|
86
37
|
}
|
|
87
38
|
catch (err) {
|
|
88
39
|
matterbridge.log.error(`Error triggering Shelly system update: ${err instanceof Error ? err.message : String(err)}`);
|
|
89
40
|
}
|
|
90
41
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Fetches Shelly main updates. If available: logs the result, sends a snackbar message, and broadcasts the message.
|
|
93
|
-
*
|
|
94
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
95
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
96
|
-
*/
|
|
97
42
|
export async function getShellyMainUpdate(matterbridge) {
|
|
98
43
|
try {
|
|
99
44
|
const updates = (await getShelly('/api/updates/main/check'));
|
|
@@ -112,35 +57,19 @@ export async function getShellyMainUpdate(matterbridge) {
|
|
|
112
57
|
matterbridge.log.error(`Error getting Shelly main updates: ${err instanceof Error ? err.message : String(err)}`);
|
|
113
58
|
}
|
|
114
59
|
}
|
|
115
|
-
/**
|
|
116
|
-
* Triggers Shelly main updates.
|
|
117
|
-
*
|
|
118
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
119
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
120
|
-
*/
|
|
121
60
|
export async function triggerShellyMainUpdate(matterbridge) {
|
|
122
61
|
try {
|
|
123
|
-
// Trigger the perform-update request
|
|
124
62
|
await getShelly('/api/updates/main/perform');
|
|
125
63
|
matterbridge.log.notice('Installing Shelly software update...');
|
|
126
64
|
matterbridge.matterbridgeInformation.shellyMainUpdate = false;
|
|
127
65
|
matterbridge.frontend.wssSendSnackbarMessage('Installing Shelly software update...', 15);
|
|
128
66
|
matterbridge.frontend.wssBroadcastMessage(WS_ID_SHELLY_MAIN_UPDATE, 'shelly-main-update', { available: false });
|
|
129
|
-
// Begin polling the update status
|
|
130
67
|
await verifyShellyUpdate(matterbridge, '/api/updates/main/status', 'Shelly software update');
|
|
131
68
|
}
|
|
132
69
|
catch (err) {
|
|
133
70
|
matterbridge.log.error(`Error triggering Shelly main update: ${err instanceof Error ? err.message : String(err)}`);
|
|
134
71
|
}
|
|
135
72
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Verifies Shelly update.
|
|
138
|
-
*
|
|
139
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
140
|
-
* @param {string} api - The api to call: /api/updates/sys/status or /api/updates/main/status
|
|
141
|
-
* @param {string} name - The name of the update.
|
|
142
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
143
|
-
*/
|
|
144
73
|
export async function verifyShellyUpdate(matterbridge, api, name) {
|
|
145
74
|
return new Promise((resolve) => {
|
|
146
75
|
const timeout = setTimeout(() => {
|
|
@@ -148,9 +77,9 @@ export async function verifyShellyUpdate(matterbridge, api, name) {
|
|
|
148
77
|
matterbridge.frontend.wssSendCloseSnackbarMessage(`${name} in progress...`);
|
|
149
78
|
clearInterval(interval);
|
|
150
79
|
resolve();
|
|
151
|
-
}, verifyTimeoutSecs * 1000);
|
|
80
|
+
}, verifyTimeoutSecs * 1000);
|
|
152
81
|
const interval = setInterval(() => {
|
|
153
|
-
getShelly(api, 10 * 1000)
|
|
82
|
+
getShelly(api, 10 * 1000)
|
|
154
83
|
.then(async (data) => {
|
|
155
84
|
if (data.updatingInProgress) {
|
|
156
85
|
matterbridge.log.debug(`${name} in progress...`);
|
|
@@ -173,21 +102,9 @@ export async function verifyShellyUpdate(matterbridge, api, name) {
|
|
|
173
102
|
clearTimeout(timeout);
|
|
174
103
|
resolve();
|
|
175
104
|
});
|
|
176
|
-
}, verifyIntervalSecs * 1000);
|
|
105
|
+
}, verifyIntervalSecs * 1000);
|
|
177
106
|
});
|
|
178
107
|
}
|
|
179
|
-
/**
|
|
180
|
-
* Triggers Shelly change network configuration.
|
|
181
|
-
*
|
|
182
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
183
|
-
* @param {object} config - The network configuration.
|
|
184
|
-
* @param {string} config.type - The type of network configuration, either 'static' or 'dhcp'.
|
|
185
|
-
* @param {string} config.ip - The IP address to set (required for static configuration).
|
|
186
|
-
* @param {string} config.subnet - The subnet mask to set (required for static configuration).
|
|
187
|
-
* @param {string} config.gateway - The gateway to set (required for static configuration).
|
|
188
|
-
* @param {string} config.dns - The DNS server to set (required for static configuration).
|
|
189
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
190
|
-
*/
|
|
191
108
|
export async function triggerShellyChangeIp(matterbridge, config) {
|
|
192
109
|
const api = config.type === 'static' ? '/api/network/connection/static' : '/api/network/connection/dynamic';
|
|
193
110
|
const data = { interface: 'end0' };
|
|
@@ -210,12 +127,6 @@ export async function triggerShellyChangeIp(matterbridge, config) {
|
|
|
210
127
|
matterbridge.frontend.wssSendSnackbarMessage('Error changing Shelly network configuration', 10, 'error');
|
|
211
128
|
}
|
|
212
129
|
}
|
|
213
|
-
/**
|
|
214
|
-
* Triggers Shelly system reboot.
|
|
215
|
-
*
|
|
216
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
217
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
218
|
-
*/
|
|
219
130
|
export async function triggerShellyReboot(matterbridge) {
|
|
220
131
|
matterbridge.log.debug(`Triggering Shelly system reboot`);
|
|
221
132
|
try {
|
|
@@ -233,13 +144,6 @@ export async function triggerShellyReboot(matterbridge) {
|
|
|
233
144
|
matterbridge.frontend.wssSendSnackbarMessage('Error rebooting Shelly board', 10, 'error');
|
|
234
145
|
}
|
|
235
146
|
}
|
|
236
|
-
/**
|
|
237
|
-
* Triggers Shelly soft reset.
|
|
238
|
-
* It will replaces network config with the default one (edn0 on dhcp).
|
|
239
|
-
*
|
|
240
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
241
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
242
|
-
*/
|
|
243
147
|
export async function triggerShellySoftReset(matterbridge) {
|
|
244
148
|
matterbridge.log.debug(`Triggering Shelly soft reset`);
|
|
245
149
|
try {
|
|
@@ -257,13 +161,6 @@ export async function triggerShellySoftReset(matterbridge) {
|
|
|
257
161
|
matterbridge.frontend.wssSendSnackbarMessage('Error resetting the network parameters on Shelly board', 10, 'error');
|
|
258
162
|
}
|
|
259
163
|
}
|
|
260
|
-
/**
|
|
261
|
-
* Triggers Shelly hard reset.
|
|
262
|
-
* It will do a hard reset and will remove both directories .matterbridge Matterbridge.
|
|
263
|
-
*
|
|
264
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
265
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
266
|
-
*/
|
|
267
164
|
export async function triggerShellyHardReset(matterbridge) {
|
|
268
165
|
matterbridge.log.debug(`Triggering Shelly hard reset`);
|
|
269
166
|
try {
|
|
@@ -281,12 +178,6 @@ export async function triggerShellyHardReset(matterbridge) {
|
|
|
281
178
|
matterbridge.frontend.wssSendSnackbarMessage('Error while factory resetting the Shelly board', 10, 'error');
|
|
282
179
|
}
|
|
283
180
|
}
|
|
284
|
-
/**
|
|
285
|
-
* Fetches Shelly system log and write it to shelly.log.
|
|
286
|
-
*
|
|
287
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
288
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the log was successfully downloaded, false otherwise.
|
|
289
|
-
*/
|
|
290
181
|
export async function createShellySystemLog(matterbridge) {
|
|
291
182
|
const { promises: fs } = await import('node:fs');
|
|
292
183
|
const path = await import('node:path');
|
|
@@ -303,28 +194,6 @@ export async function createShellySystemLog(matterbridge) {
|
|
|
303
194
|
return false;
|
|
304
195
|
}
|
|
305
196
|
}
|
|
306
|
-
/**
|
|
307
|
-
* Perform a GET to Shelly board apis.
|
|
308
|
-
*
|
|
309
|
-
* @param {string} api - The api to call:
|
|
310
|
-
*
|
|
311
|
-
* /api/updates/sys/check => [{name:string; ...}]
|
|
312
|
-
* /api/updates/sys/perform => {"updatingInProgress":true} or {"updatingInProgress":false}
|
|
313
|
-
* /api/updates/sys/status => {"updatingInProgress":true} or {"updatingInProgress":false}
|
|
314
|
-
* /api/updates/main/check => [{name:string; ...}]
|
|
315
|
-
* /api/updates/main/perform => {"updatingInProgress":true} or {"updatingInProgress":false}
|
|
316
|
-
* /api/updates/main/status => {"updatingInProgress":true} or {"updatingInProgress":false}
|
|
317
|
-
*
|
|
318
|
-
* /api/logs/system => text
|
|
319
|
-
*
|
|
320
|
-
* /api/reset/soft => "ok" Replaces network config with default one (edn0 on dhcp)
|
|
321
|
-
* /api/reset/hard => reboot on success Hard reset makes soft reset + removing both directories .matterbridge Matterbridge + reboot
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
* @param {number} [timeout] - The timeout duration in milliseconds (default is 60000ms).
|
|
325
|
-
* @returns {Promise<any>} A promise that resolves to the response.
|
|
326
|
-
* @throws {Error} If the request fails.
|
|
327
|
-
*/
|
|
328
197
|
export async function getShelly(api, timeout = 60000) {
|
|
329
198
|
const http = await import('node:http');
|
|
330
199
|
return new Promise((resolve, reject) => {
|
|
@@ -338,13 +207,12 @@ export async function getShelly(api, timeout = 60000) {
|
|
|
338
207
|
let data = '';
|
|
339
208
|
if (res.statusCode !== 200) {
|
|
340
209
|
clearTimeout(timeoutId);
|
|
341
|
-
res.resume();
|
|
342
|
-
req.destroy();
|
|
210
|
+
res.resume();
|
|
211
|
+
req.destroy();
|
|
343
212
|
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
344
213
|
return;
|
|
345
214
|
}
|
|
346
215
|
res.on('data', (chunk) => {
|
|
347
|
-
// console.log(chunk);
|
|
348
216
|
data += chunk;
|
|
349
217
|
});
|
|
350
218
|
res.on('end', () => {
|
|
@@ -359,7 +227,6 @@ export async function getShelly(api, timeout = 60000) {
|
|
|
359
227
|
}
|
|
360
228
|
}
|
|
361
229
|
else {
|
|
362
|
-
// console.log(data);
|
|
363
230
|
resolve(data);
|
|
364
231
|
}
|
|
365
232
|
});
|
|
@@ -370,31 +237,6 @@ export async function getShelly(api, timeout = 60000) {
|
|
|
370
237
|
});
|
|
371
238
|
});
|
|
372
239
|
}
|
|
373
|
-
/**
|
|
374
|
-
* Perform a POST request to Shelly board apis.
|
|
375
|
-
*
|
|
376
|
-
* @param {string} api - The api to call:
|
|
377
|
-
*
|
|
378
|
-
* Set static ip
|
|
379
|
-
* /api/network/connection/static -d '{"interface": "end0", "addr": "10.11.12.101", "mask": "255.255.255.0", "gw": "10.11.12.1", "dns": "1.1.1.1"}' => {}
|
|
380
|
-
*
|
|
381
|
-
* Set dhcp
|
|
382
|
-
* /api/network/connection/dynamic -d '{"interface": "end0"}' => {}
|
|
383
|
-
*
|
|
384
|
-
* Reboot
|
|
385
|
-
* /api/system/reboot => {"success":true}
|
|
386
|
-
*
|
|
387
|
-
* curl -H "Content-Type: application/json" -X POST http://127.0.0.1:8101/api/network/connection/dynamic
|
|
388
|
-
* -d '{"interface": "end0"}'
|
|
389
|
-
*
|
|
390
|
-
* curl -H "Content-Type: application/json" -X POST http://127.0.0.1:8101/api/network/connection/static
|
|
391
|
-
* -d '{"interface": "end0", "addr": "192.168.1.64", "mask": "255.255.255.0", "gw": "192.168.1.1", "dns": "192.168.1.1"}'
|
|
392
|
-
*
|
|
393
|
-
* @param {any} data - The data to send in the POST request, typically a JSON object.
|
|
394
|
-
* @param {number} [timeout] - The timeout duration in milliseconds (default is 60000ms).
|
|
395
|
-
* @returns {Promise<any>} A promise that resolves to the response.
|
|
396
|
-
* @throws {Error} If the request fails.
|
|
397
|
-
*/
|
|
398
240
|
export async function postShelly(api, data, timeout = 60000) {
|
|
399
241
|
const http = await import('node:http');
|
|
400
242
|
return new Promise((resolve, reject) => {
|
|
@@ -415,11 +257,10 @@ export async function postShelly(api, data, timeout = 60000) {
|
|
|
415
257
|
};
|
|
416
258
|
const req = http.request(url, options, (res) => {
|
|
417
259
|
let responseData = '';
|
|
418
|
-
// Check for non-success status codes (e.g., 300+)
|
|
419
260
|
if (res.statusCode && res.statusCode >= 300) {
|
|
420
261
|
clearTimeout(timeoutId);
|
|
421
|
-
res.resume();
|
|
422
|
-
req.destroy();
|
|
262
|
+
res.resume();
|
|
263
|
+
req.destroy();
|
|
423
264
|
return reject(new Error(`Failed to post data. Status code: ${res.statusCode}`));
|
|
424
265
|
}
|
|
425
266
|
res.on('data', (chunk) => {
|
|
@@ -440,9 +281,7 @@ export async function postShelly(api, data, timeout = 60000) {
|
|
|
440
281
|
clearTimeout(timeoutId);
|
|
441
282
|
reject(new Error(`Request failed: ${error instanceof Error ? error.message : error}`));
|
|
442
283
|
});
|
|
443
|
-
// Send the JSON data
|
|
444
284
|
req.write(jsonData);
|
|
445
285
|
req.end();
|
|
446
286
|
});
|
|
447
287
|
}
|
|
448
|
-
//# sourceMappingURL=shelly.js.map
|
package/dist/storage/export.js
CHANGED
package/dist/update.js
CHANGED
|
@@ -1,37 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the check updates functions.
|
|
3
|
-
*
|
|
4
|
-
* @file update.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @created 2025-02-24
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
* @license Apache-2.0
|
|
9
|
-
*
|
|
10
|
-
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
11
|
-
*
|
|
12
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License.
|
|
14
|
-
* You may obtain a copy of the License at
|
|
15
|
-
*
|
|
16
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
-
* See the License for the specific language governing permissions and
|
|
22
|
-
* limitations under the License.
|
|
23
|
-
*/
|
|
24
|
-
// AnsiLogger module
|
|
25
1
|
import { db, debugStringify, nt, wr } from 'node-ansi-logger';
|
|
26
2
|
import { plg } from './matterbridgeTypes.js';
|
|
27
3
|
import { isValidString } from './utils/isvalid.js';
|
|
28
|
-
/**
|
|
29
|
-
* Checks for updates for Matterbridge and its plugins.
|
|
30
|
-
* If the 'shelly' parameter is present, also checks for Shelly updates.
|
|
31
|
-
*
|
|
32
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
33
|
-
* @returns {Promise<void>} A promise that resolves when the update checks are complete.
|
|
34
|
-
*/
|
|
35
4
|
export async function checkUpdates(matterbridge) {
|
|
36
5
|
const { hasParameter } = await import('./utils/commandLine.js');
|
|
37
6
|
const update = checkUpdatesAndLog(matterbridge);
|
|
@@ -55,12 +24,6 @@ export async function checkUpdates(matterbridge) {
|
|
|
55
24
|
}
|
|
56
25
|
await Promise.all([update, latestVersion, devVersion, ...pluginsVersions, ...pluginsDevVersions, ...shellyUpdates]);
|
|
57
26
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Checks for updates and logs from GitHub.
|
|
60
|
-
* If the update check fails, logs a warning message.
|
|
61
|
-
*
|
|
62
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
63
|
-
*/
|
|
64
27
|
export async function checkUpdatesAndLog(matterbridge) {
|
|
65
28
|
const { getGitHubUpdate } = await import('./utils/network.js');
|
|
66
29
|
const branch = matterbridge.matterbridgeVersion.includes('-dev-') ? 'dev' : 'main';
|
|
@@ -78,13 +41,6 @@ export async function checkUpdatesAndLog(matterbridge) {
|
|
|
78
41
|
matterbridge.log.debug(`Error checking GitHub ${branch} updates: ${error instanceof Error ? error.message : error}`);
|
|
79
42
|
}
|
|
80
43
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Retrieves the latest version of Matterbridge and updates the matterbridgeLatestVersion property.
|
|
83
|
-
* If there is an error retrieving the latest version, logs an error message.
|
|
84
|
-
*
|
|
85
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
86
|
-
* @returns {Promise<string | undefined>} A promise that resolves when the latest version is retrieved.
|
|
87
|
-
*/
|
|
88
44
|
export async function getMatterbridgeLatestVersion(matterbridge) {
|
|
89
45
|
const { getNpmPackageVersion } = await import('./utils/network.js');
|
|
90
46
|
try {
|
|
@@ -104,17 +60,9 @@ export async function getMatterbridgeLatestVersion(matterbridge) {
|
|
|
104
60
|
return version;
|
|
105
61
|
}
|
|
106
62
|
catch (error) {
|
|
107
|
-
// logError(matterbridge.log, `Error getting Matterbridge latest version`, error);
|
|
108
63
|
matterbridge.log.warn(`Error getting Matterbridge latest version: ${error instanceof Error ? error.message : error}`);
|
|
109
64
|
}
|
|
110
65
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Retrieves the latest dev version of Matterbridge and updates the matterbridgeDevVersion property.
|
|
113
|
-
* If there is an error retrieving the latest version, logs an error message.
|
|
114
|
-
*
|
|
115
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
116
|
-
* @returns {Promise<string | undefined>} A promise that resolves when the latest dev version is retrieved.
|
|
117
|
-
*/
|
|
118
66
|
export async function getMatterbridgeDevVersion(matterbridge) {
|
|
119
67
|
const { getNpmPackageVersion } = await import('./utils/network.js');
|
|
120
68
|
try {
|
|
@@ -137,14 +85,6 @@ export async function getMatterbridgeDevVersion(matterbridge) {
|
|
|
137
85
|
matterbridge.log.warn(`Error getting Matterbridge latest dev version: ${error instanceof Error ? error.message : error}`);
|
|
138
86
|
}
|
|
139
87
|
}
|
|
140
|
-
/**
|
|
141
|
-
* Retrieves the latest version of a plugin and updates the plugin's latestVersion property.
|
|
142
|
-
* If there is an error retrieving the latest version, logs an error message.
|
|
143
|
-
*
|
|
144
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
145
|
-
* @param {RegisteredPlugin} plugin - The plugin for which to retrieve the latest version.
|
|
146
|
-
* @returns {Promise<string | undefined>} A promise that resolves when the latest version is retrieved.
|
|
147
|
-
*/
|
|
148
88
|
export async function getPluginLatestVersion(matterbridge, plugin) {
|
|
149
89
|
const { getNpmPackageVersion } = await import('./utils/network.js');
|
|
150
90
|
try {
|
|
@@ -163,14 +103,6 @@ export async function getPluginLatestVersion(matterbridge, plugin) {
|
|
|
163
103
|
matterbridge.log.warn(`Error getting plugin ${plg}${plugin.name}${wr} latest version: ${error instanceof Error ? error.message : error}`);
|
|
164
104
|
}
|
|
165
105
|
}
|
|
166
|
-
/**
|
|
167
|
-
* Retrieves the latest dev version of a plugin and updates the plugin's devVersion property.
|
|
168
|
-
* If there is an error retrieving the latest version, logs an error message.
|
|
169
|
-
*
|
|
170
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
171
|
-
* @param {RegisteredPlugin} plugin - The plugin for which to retrieve the latest version.
|
|
172
|
-
* @returns {Promise<string | undefined>} A promise that resolves when the latest dev version is retrieved.
|
|
173
|
-
*/
|
|
174
106
|
export async function getPluginDevVersion(matterbridge, plugin) {
|
|
175
107
|
const { getNpmPackageVersion } = await import('./utils/network.js');
|
|
176
108
|
try {
|
|
@@ -189,4 +121,3 @@ export async function getPluginDevVersion(matterbridge, plugin) {
|
|
|
189
121
|
matterbridge.log.debug(`Error getting plugin ${plg}${plugin.name}${db} latest dev version: ${error instanceof Error ? error.message : error}`);
|
|
190
122
|
}
|
|
191
123
|
}
|
|
192
|
-
//# sourceMappingURL=update.js.map
|
package/dist/utils/colorUtils.js
CHANGED
|
@@ -1,35 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the color utilities.
|
|
3
|
-
*
|
|
4
|
-
* @file colorUtils.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @created 2023-10-05
|
|
7
|
-
* @version 1.3.0
|
|
8
|
-
* @license Apache-2.0
|
|
9
|
-
*
|
|
10
|
-
* Copyright 2023, 2024, 2025 Luca Liguori.
|
|
11
|
-
*
|
|
12
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License.
|
|
14
|
-
* You may obtain a copy of the License at
|
|
15
|
-
*
|
|
16
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
-
* See the License for the specific language governing permissions and
|
|
22
|
-
* limitations under the License.
|
|
23
|
-
*/
|
|
24
1
|
import { assert } from 'node:console';
|
|
25
|
-
/**
|
|
26
|
-
* Converts from HSL to RGB color space
|
|
27
|
-
*
|
|
28
|
-
* @param {number} hue - The hue value (0-360).
|
|
29
|
-
* @param {number} saturation - The saturation value (0-100).
|
|
30
|
-
* @param {number} luminance - The luminance value (0-100).
|
|
31
|
-
* @returns {RGB} An object containing the RGB values.
|
|
32
|
-
*/
|
|
33
2
|
export function hslColorToRgbColor(hue, saturation, luminance) {
|
|
34
3
|
if (hue === 360) {
|
|
35
4
|
hue = 0;
|
|
@@ -41,7 +10,7 @@ export function hslColorToRgbColor(hue, saturation, luminance) {
|
|
|
41
10
|
luminance /= 100;
|
|
42
11
|
let r, g, b;
|
|
43
12
|
if (saturation === 0) {
|
|
44
|
-
r = g = b = luminance;
|
|
13
|
+
r = g = b = luminance;
|
|
45
14
|
}
|
|
46
15
|
else {
|
|
47
16
|
const hue2rgb = (p, q, t) => {
|
|
@@ -74,54 +43,33 @@ export function hslColorToRgbColor(hue, saturation, luminance) {
|
|
|
74
43
|
b: Math.ceil(b * 255),
|
|
75
44
|
};
|
|
76
45
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Converts RGB color space to CIE 1931 XY color space
|
|
79
|
-
*
|
|
80
|
-
* @param {RGB} rgb - The RGB color object.
|
|
81
|
-
* @returns {XY} An object containing the x and y values in CIE 1931 XY color space.
|
|
82
|
-
*/
|
|
83
46
|
export function rgbColorToXYColor(rgb) {
|
|
84
47
|
let r = rgb.r / 255;
|
|
85
48
|
let g = rgb.g / 255;
|
|
86
49
|
let b = rgb.b / 255;
|
|
87
|
-
// Apply gamma correction
|
|
88
50
|
r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
|
|
89
51
|
g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
|
|
90
52
|
b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
|
|
91
|
-
// Scale the values to the D65 illuminant
|
|
92
53
|
r = r * 100;
|
|
93
54
|
g = g * 100;
|
|
94
55
|
b = b * 100;
|
|
95
|
-
// Convert RGB to XYZ
|
|
96
56
|
const X = r * 0.664511 + g * 0.154324 + b * 0.162028;
|
|
97
57
|
const Y = r * 0.283881 + g * 0.668433 + b * 0.047685;
|
|
98
58
|
const Z = r * 0.000088 + g * 0.07231 + b * 0.986039;
|
|
99
|
-
// Normalization
|
|
100
59
|
let x = X / (X + Y + Z);
|
|
101
60
|
let y = Y / (X + Y + Z);
|
|
102
|
-
// Round to 4 digits
|
|
103
61
|
x = Math.round(x * 10000) / 10000;
|
|
104
62
|
y = Math.round(y * 10000) / 10000;
|
|
105
63
|
return { x, y };
|
|
106
64
|
}
|
|
107
|
-
/**
|
|
108
|
-
* Converts CIE 1931 XY color space to RGB color space
|
|
109
|
-
*
|
|
110
|
-
* @param {number} x - The x value in CIE 1931 XY color space.
|
|
111
|
-
* @param {number} y - The y value in CIE 1931 XY color space.
|
|
112
|
-
* @param {number} [brightness] - The brightness value (1-254). Defaults to 254.
|
|
113
|
-
* @returns {RGB} An object containing the RGB values.
|
|
114
|
-
*/
|
|
115
65
|
export function xyColorToRgbColor(x, y, brightness = 254) {
|
|
116
66
|
const z = 1.0 - x - y;
|
|
117
67
|
const Y = (brightness / 254).toFixed(2);
|
|
118
68
|
const X = (Number(Y) / y) * x;
|
|
119
69
|
const Z = (Number(Y) / y) * z;
|
|
120
|
-
// Convert to RGB using Wide RGB D65 conversion
|
|
121
70
|
let red = X * 1.656492 - Number(Y) * 0.354851 - Z * 0.255038;
|
|
122
71
|
let green = -X * 0.707196 + Number(Y) * 1.655397 + Z * 0.036152;
|
|
123
72
|
let blue = X * 0.051713 - Number(Y) * 0.121364 + Z * 1.01153;
|
|
124
|
-
// If red, green or blue is larger than 1.0 set it back to the maximum of 1.0
|
|
125
73
|
if (red > blue && red > green && red > 1.0) {
|
|
126
74
|
green = green / red;
|
|
127
75
|
blue = blue / red;
|
|
@@ -137,40 +85,27 @@ export function xyColorToRgbColor(x, y, brightness = 254) {
|
|
|
137
85
|
green = green / blue;
|
|
138
86
|
blue = 1.0;
|
|
139
87
|
}
|
|
140
|
-
// Reverse gamma correction
|
|
141
88
|
red = red <= 0.0031308 ? 12.92 * red : (1.0 + 0.055) * Math.pow(red, 1.0 / 2.4) - 0.055;
|
|
142
89
|
green = green <= 0.0031308 ? 12.92 * green : (1.0 + 0.055) * Math.pow(green, 1.0 / 2.4) - 0.055;
|
|
143
90
|
blue = blue <= 0.0031308 ? 12.92 * blue : (1.0 + 0.055) * Math.pow(blue, 1.0 / 2.4) - 0.055;
|
|
144
|
-
// Convert normalized decimal to decimal
|
|
145
91
|
red = Math.round(red * 255);
|
|
146
92
|
green = Math.round(green * 255);
|
|
147
93
|
blue = Math.round(blue * 255);
|
|
148
|
-
// Normalize even if this code should never be reached...
|
|
149
94
|
if (isNaN(red) || red < 0) {
|
|
150
|
-
/* istanbul ignore next */
|
|
151
95
|
red = 0;
|
|
152
96
|
}
|
|
153
97
|
if (isNaN(green) || green < 0) {
|
|
154
|
-
/* istanbul ignore next */
|
|
155
98
|
green = 0;
|
|
156
99
|
}
|
|
157
100
|
if (isNaN(blue) || blue < 0) {
|
|
158
|
-
/* istanbul ignore next */
|
|
159
101
|
blue = 0;
|
|
160
102
|
}
|
|
161
|
-
// Fix negative zero issue by ensuring we return positive zero
|
|
162
103
|
return {
|
|
163
104
|
r: red === 0 ? 0 : red,
|
|
164
105
|
g: green === 0 ? 0 : green,
|
|
165
106
|
b: blue === 0 ? 0 : blue,
|
|
166
107
|
};
|
|
167
108
|
}
|
|
168
|
-
/**
|
|
169
|
-
* Converts RGB color space to HSL color space
|
|
170
|
-
*
|
|
171
|
-
* @param {RGB} rgb - The RGB color object.
|
|
172
|
-
* @returns {HSL} An object containing the HSL values.
|
|
173
|
-
*/
|
|
174
109
|
export function rgbColorToHslColor(rgb) {
|
|
175
110
|
const r = rgb.r / 255;
|
|
176
111
|
const g = rgb.g / 255;
|
|
@@ -180,7 +115,7 @@ export function rgbColorToHslColor(rgb) {
|
|
|
180
115
|
let h = 0, s = 0;
|
|
181
116
|
const l = (max + min) / 2;
|
|
182
117
|
if (max === min) {
|
|
183
|
-
h = s = 0;
|
|
118
|
+
h = s = 0;
|
|
184
119
|
}
|
|
185
120
|
else {
|
|
186
121
|
const d = max - min;
|
|
@@ -204,46 +139,19 @@ export function rgbColorToHslColor(rgb) {
|
|
|
204
139
|
l: Math.round(l * 100),
|
|
205
140
|
};
|
|
206
141
|
}
|
|
207
|
-
/**
|
|
208
|
-
* Converts CIE 1931 XY color space to HSL color space
|
|
209
|
-
*
|
|
210
|
-
* @param {number} x - The x value in CIE 1931 XY color space.
|
|
211
|
-
* @param {number} y - The y value in CIE 1931 XY color space.
|
|
212
|
-
* @returns {HSL} An object containing the HSL values.
|
|
213
|
-
*/
|
|
214
142
|
export function xyToHsl(x, y) {
|
|
215
143
|
const rgb = xyColorToRgbColor(x, y);
|
|
216
144
|
return rgbColorToHslColor(rgb);
|
|
217
145
|
}
|
|
218
|
-
/**
|
|
219
|
-
* Converts mireds to kelvin.
|
|
220
|
-
*
|
|
221
|
-
* @param {number} mired - The mired value to convert.
|
|
222
|
-
* @returns {number} The converted kelvin value.
|
|
223
|
-
*/
|
|
224
146
|
export function miredToKelvin(mired) {
|
|
225
147
|
return Math.round(1000000 / mired);
|
|
226
148
|
}
|
|
227
|
-
/**
|
|
228
|
-
* Converts kelvin to mireds.
|
|
229
|
-
*
|
|
230
|
-
* @param {number} kelvin - The kelvin value to convert.
|
|
231
|
-
* @returns {number} The converted mired value.
|
|
232
|
-
*/
|
|
233
149
|
export function kelvinToMired(kelvin) {
|
|
234
150
|
return Math.round(1000000 / kelvin);
|
|
235
151
|
}
|
|
236
|
-
/**
|
|
237
|
-
* Converts kelvin to RGB color space.
|
|
238
|
-
*
|
|
239
|
-
* @param {number} kelvin - The kelvin value to convert (1000K to 40000K).
|
|
240
|
-
* @returns {RGB} An object containing the RGB values.
|
|
241
|
-
*/
|
|
242
152
|
export function kelvinToRGB(kelvin) {
|
|
243
|
-
// Clamp the temperature to the range 1000K to 40000K
|
|
244
153
|
kelvin = Math.max(1000, Math.min(40000, kelvin)) / 100;
|
|
245
154
|
let r, g, b;
|
|
246
|
-
// Calculate red
|
|
247
155
|
if (kelvin <= 66) {
|
|
248
156
|
r = 255;
|
|
249
157
|
}
|
|
@@ -252,7 +160,6 @@ export function kelvinToRGB(kelvin) {
|
|
|
252
160
|
r = 329.698727446 * Math.pow(r, -0.1332047592);
|
|
253
161
|
r = Math.max(0, Math.min(255, r));
|
|
254
162
|
}
|
|
255
|
-
// Calculate green
|
|
256
163
|
if (kelvin <= 66) {
|
|
257
164
|
g = kelvin;
|
|
258
165
|
g = 99.4708025861 * Math.log(g) - 161.1195681661;
|
|
@@ -263,7 +170,6 @@ export function kelvinToRGB(kelvin) {
|
|
|
263
170
|
g = 288.1221695283 * Math.pow(g, -0.0755148492);
|
|
264
171
|
g = Math.max(0, Math.min(255, g));
|
|
265
172
|
}
|
|
266
|
-
// Calculate blue
|
|
267
173
|
if (kelvin >= 66) {
|
|
268
174
|
b = 255;
|
|
269
175
|
}
|
|
@@ -277,4 +183,3 @@ export function kelvinToRGB(kelvin) {
|
|
|
277
183
|
}
|
|
278
184
|
return { r: Math.round(r), g: Math.round(g), b: Math.round(b) };
|
|
279
185
|
}
|
|
280
|
-
//# sourceMappingURL=colorUtils.js.map
|