matterbridge 3.3.7 → 3.3.8-dev-20251114-9b65e59
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 +37 -0
- package/README-SERVICE-OPT.md +4 -4
- package/README.md +4 -0
- package/dist/broadcastServer.js +1 -93
- package/dist/broadcastServerTypes.js +0 -24
- package/dist/cli.js +1 -97
- package/dist/cliEmitter.js +0 -37
- package/dist/cliHistory.js +0 -38
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -24
- package/dist/deviceManager.js +1 -105
- package/dist/devices/airConditioner.js +1 -58
- package/dist/devices/batteryStorage.js +2 -49
- package/dist/devices/cooktop.js +1 -56
- package/dist/devices/dishwasher.js +1 -58
- package/dist/devices/evse.js +11 -75
- package/dist/devices/export.js +0 -5
- package/dist/devices/extractorHood.js +1 -43
- package/dist/devices/heatPump.js +3 -51
- package/dist/devices/laundryDryer.js +4 -63
- package/dist/devices/laundryWasher.js +5 -71
- package/dist/devices/microwaveOven.js +6 -89
- package/dist/devices/oven.js +1 -86
- package/dist/devices/refrigerator.js +2 -104
- package/dist/devices/roboticVacuumCleaner.js +10 -101
- package/dist/devices/solarPower.js +1 -39
- package/dist/devices/speaker.js +1 -85
- package/dist/devices/temperatureControl.js +3 -24
- package/dist/devices/waterHeater.js +3 -83
- 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 +40 -452
- package/dist/frontendTypes.js +0 -45
- package/dist/helpers.js +0 -53
- package/dist/index.js +1 -25
- package/dist/jestutils/export.js +1 -0
- package/dist/{utils → jestutils}/jestHelpers.js +167 -175
- 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 +50 -838
- package/dist/matterbridgeAccessoryPlatform.js +0 -37
- package/dist/matterbridgeBehaviors.js +5 -68
- package/dist/matterbridgeDeviceTypes.js +27 -653
- package/dist/matterbridgeDynamicPlatform.js +0 -37
- package/dist/matterbridgeEndpoint.js +73 -1429
- package/dist/matterbridgeEndpointHelpers.js +42 -475
- package/dist/matterbridgeEndpointTypes.js +3 -0
- package/dist/matterbridgePlatform.js +18 -341
- package/dist/matterbridgeTypes.js +0 -26
- package/dist/pluginManager.js +5 -340
- 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 -60
- 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 +2 -43
- package/dist/utils/export.js +0 -1
- package/dist/utils/format.js +0 -49
- package/dist/utils/hex.js +0 -124
- package/dist/utils/inspector.js +1 -69
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/network.js +5 -96
- package/dist/utils/spawn.js +0 -71
- package/dist/utils/tracker.js +1 -64
- package/dist/utils/wait.js +8 -60
- package/npm-shrinkwrap.json +8 -8
- package/package.json +5 -2
- package/scripts/fetch-chip.mjs +100 -0
- package/dist/broadcastServer.d.ts +0 -115
- package/dist/broadcastServer.d.ts.map +0 -1
- package/dist/broadcastServer.js.map +0 -1
- package/dist/broadcastServerTypes.d.ts +0 -806
- package/dist/broadcastServerTypes.d.ts.map +0 -1
- package/dist/broadcastServerTypes.js.map +0 -1
- package/dist/cli.d.ts +0 -30
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cliEmitter.d.ts +0 -50
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.js.map +0 -1
- package/dist/cliHistory.d.ts +0 -48
- package/dist/cliHistory.d.ts.map +0 -1
- package/dist/cliHistory.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 -128
- 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 -76
- 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 -87
- 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 -238
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/frontendTypes.d.ts +0 -529
- package/dist/frontendTypes.d.ts.map +0 -1
- package/dist/frontendTypes.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/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 -478
- 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 -2404
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -770
- 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 -1556
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -758
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -402
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -239
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -371
- 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 -101
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/commandLine.d.ts +0 -66
- 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/format.d.ts +0 -53
- package/dist/utils/format.d.ts.map +0 -1
- package/dist/utils/format.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/inspector.d.ts +0 -87
- package/dist/utils/inspector.d.ts.map +0 -1
- package/dist/utils/inspector.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/jestHelpers.d.ts +0 -139
- package/dist/utils/jestHelpers.d.ts.map +0 -1
- package/dist/utils/jestHelpers.js.map +0 -1
- package/dist/utils/network.d.ts +0 -101
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/spawn.d.ts +0 -35
- package/dist/utils/spawn.d.ts.map +0 -1
- package/dist/utils/spawn.js.map +0 -1
- package/dist/utils/tracker.d.ts +0 -108
- package/dist/utils/tracker.d.ts.map +0 -1
- package/dist/utils/tracker.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,53 +1,12 @@
|
|
|
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
|
let verifyIntervalSecs = 15;
|
|
26
3
|
let verifyTimeoutSecs = 600;
|
|
27
|
-
/**
|
|
28
|
-
* Sets the interval for verification in seconds.
|
|
29
|
-
*
|
|
30
|
-
* @param {number} seconds - The interval in seconds.
|
|
31
|
-
* @returns {void}
|
|
32
|
-
*/
|
|
33
4
|
export function setVerifyIntervalSecs(seconds) {
|
|
34
5
|
verifyIntervalSecs = seconds;
|
|
35
6
|
}
|
|
36
|
-
/**
|
|
37
|
-
* Sets the timeout for verification in seconds.
|
|
38
|
-
*
|
|
39
|
-
* @param {number} seconds - The timeout in seconds.
|
|
40
|
-
* @returns {void}
|
|
41
|
-
*/
|
|
42
7
|
export function setVerifyTimeoutSecs(seconds) {
|
|
43
8
|
verifyTimeoutSecs = seconds;
|
|
44
9
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Fetches Shelly system updates. If available: logs the result, sends a snackbar message, and broadcasts the message.
|
|
47
|
-
*
|
|
48
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
49
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
50
|
-
*/
|
|
51
10
|
export async function getShellySysUpdate(matterbridge) {
|
|
52
11
|
try {
|
|
53
12
|
const updates = (await getShelly('/api/updates/sys/check'));
|
|
@@ -66,33 +25,19 @@ export async function getShellySysUpdate(matterbridge) {
|
|
|
66
25
|
matterbridge.log.error(`Error getting Shelly system updates: ${err instanceof Error ? err.message : String(err)}`);
|
|
67
26
|
}
|
|
68
27
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Triggers Shelly system updates.
|
|
71
|
-
*
|
|
72
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
73
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
74
|
-
*/
|
|
75
28
|
export async function triggerShellySysUpdate(matterbridge) {
|
|
76
29
|
try {
|
|
77
|
-
// Trigger the update request
|
|
78
30
|
await getShelly('/api/updates/sys/perform');
|
|
79
31
|
matterbridge.log.notice('Installing Shelly system update...');
|
|
80
32
|
matterbridge.shellySysUpdate = false;
|
|
81
33
|
matterbridge.frontend.wssSendSnackbarMessage('Installing Shelly system update...', 15);
|
|
82
34
|
matterbridge.frontend.wssBroadcastMessage({ id: 0, src: 'Matterbridge', dst: 'Frontend', method: 'shelly_sys_update', success: true, response: { available: false } });
|
|
83
|
-
// Begin polling update status
|
|
84
35
|
await verifyShellyUpdate(matterbridge, '/api/updates/sys/status', 'Shelly system update');
|
|
85
36
|
}
|
|
86
37
|
catch (err) {
|
|
87
38
|
matterbridge.log.error(`Error triggering Shelly system update: ${err instanceof Error ? err.message : String(err)}`);
|
|
88
39
|
}
|
|
89
40
|
}
|
|
90
|
-
/**
|
|
91
|
-
* Fetches Shelly main updates. If available: logs the result, sends a snackbar message, and broadcasts the message.
|
|
92
|
-
*
|
|
93
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
94
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
95
|
-
*/
|
|
96
41
|
export async function getShellyMainUpdate(matterbridge) {
|
|
97
42
|
try {
|
|
98
43
|
const updates = (await getShelly('/api/updates/main/check'));
|
|
@@ -111,35 +56,19 @@ export async function getShellyMainUpdate(matterbridge) {
|
|
|
111
56
|
matterbridge.log.error(`Error getting Shelly main updates: ${err instanceof Error ? err.message : String(err)}`);
|
|
112
57
|
}
|
|
113
58
|
}
|
|
114
|
-
/**
|
|
115
|
-
* Triggers Shelly main updates.
|
|
116
|
-
*
|
|
117
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
118
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
119
|
-
*/
|
|
120
59
|
export async function triggerShellyMainUpdate(matterbridge) {
|
|
121
60
|
try {
|
|
122
|
-
// Trigger the perform-update request
|
|
123
61
|
await getShelly('/api/updates/main/perform');
|
|
124
62
|
matterbridge.log.notice('Installing Shelly software update...');
|
|
125
63
|
matterbridge.shellyMainUpdate = false;
|
|
126
64
|
matterbridge.frontend.wssSendSnackbarMessage('Installing Shelly software update...', 15);
|
|
127
65
|
matterbridge.frontend.wssBroadcastMessage({ id: 0, src: 'Matterbridge', dst: 'Frontend', method: 'shelly_main_update', success: true, response: { available: false } });
|
|
128
|
-
// Begin polling the update status
|
|
129
66
|
await verifyShellyUpdate(matterbridge, '/api/updates/main/status', 'Shelly software update');
|
|
130
67
|
}
|
|
131
68
|
catch (err) {
|
|
132
69
|
matterbridge.log.error(`Error triggering Shelly main update: ${err instanceof Error ? err.message : String(err)}`);
|
|
133
70
|
}
|
|
134
71
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Verifies Shelly update.
|
|
137
|
-
*
|
|
138
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
139
|
-
* @param {string} api - The api to call: /api/updates/sys/status or /api/updates/main/status
|
|
140
|
-
* @param {string} name - The name of the update.
|
|
141
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
142
|
-
*/
|
|
143
72
|
export async function verifyShellyUpdate(matterbridge, api, name) {
|
|
144
73
|
return new Promise((resolve) => {
|
|
145
74
|
const timeout = setTimeout(() => {
|
|
@@ -147,9 +76,9 @@ export async function verifyShellyUpdate(matterbridge, api, name) {
|
|
|
147
76
|
matterbridge.frontend.wssSendCloseSnackbarMessage(`${name} in progress...`);
|
|
148
77
|
clearInterval(interval);
|
|
149
78
|
resolve();
|
|
150
|
-
}, verifyTimeoutSecs * 1000);
|
|
79
|
+
}, verifyTimeoutSecs * 1000);
|
|
151
80
|
const interval = setInterval(() => {
|
|
152
|
-
getShelly(api, 10 * 1000)
|
|
81
|
+
getShelly(api, 10 * 1000)
|
|
153
82
|
.then(async (data) => {
|
|
154
83
|
if (data.updatingInProgress) {
|
|
155
84
|
matterbridge.log.debug(`${name} in progress...`);
|
|
@@ -172,21 +101,9 @@ export async function verifyShellyUpdate(matterbridge, api, name) {
|
|
|
172
101
|
clearTimeout(timeout);
|
|
173
102
|
resolve();
|
|
174
103
|
});
|
|
175
|
-
}, verifyIntervalSecs * 1000);
|
|
104
|
+
}, verifyIntervalSecs * 1000);
|
|
176
105
|
});
|
|
177
106
|
}
|
|
178
|
-
/**
|
|
179
|
-
* Triggers Shelly change network configuration.
|
|
180
|
-
*
|
|
181
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
182
|
-
* @param {object} config - The network configuration.
|
|
183
|
-
* @param {string} config.type - The type of network configuration, either 'static' or 'dhcp'.
|
|
184
|
-
* @param {string} config.ip - The IP address to set (required for static configuration).
|
|
185
|
-
* @param {string} config.subnet - The subnet mask to set (required for static configuration).
|
|
186
|
-
* @param {string} config.gateway - The gateway to set (required for static configuration).
|
|
187
|
-
* @param {string} config.dns - The DNS server to set (required for static configuration).
|
|
188
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
189
|
-
*/
|
|
190
107
|
export async function triggerShellyChangeIp(matterbridge, config) {
|
|
191
108
|
const api = config.type === 'static' ? '/api/network/connection/static' : '/api/network/connection/dynamic';
|
|
192
109
|
const data = { interface: 'end0' };
|
|
@@ -209,12 +126,6 @@ export async function triggerShellyChangeIp(matterbridge, config) {
|
|
|
209
126
|
matterbridge.frontend.wssSendSnackbarMessage('Error changing Shelly network configuration', 10, 'error');
|
|
210
127
|
}
|
|
211
128
|
}
|
|
212
|
-
/**
|
|
213
|
-
* Triggers Shelly system reboot.
|
|
214
|
-
*
|
|
215
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
216
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
217
|
-
*/
|
|
218
129
|
export async function triggerShellyReboot(matterbridge) {
|
|
219
130
|
matterbridge.log.debug(`Triggering Shelly system reboot`);
|
|
220
131
|
try {
|
|
@@ -232,13 +143,6 @@ export async function triggerShellyReboot(matterbridge) {
|
|
|
232
143
|
matterbridge.frontend.wssSendSnackbarMessage('Error rebooting Shelly board', 10, 'error');
|
|
233
144
|
}
|
|
234
145
|
}
|
|
235
|
-
/**
|
|
236
|
-
* Triggers Shelly soft reset.
|
|
237
|
-
* It will replaces network config with the default one (edn0 on dhcp).
|
|
238
|
-
*
|
|
239
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
240
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
241
|
-
*/
|
|
242
146
|
export async function triggerShellySoftReset(matterbridge) {
|
|
243
147
|
matterbridge.log.debug(`Triggering Shelly soft reset`);
|
|
244
148
|
try {
|
|
@@ -256,13 +160,6 @@ export async function triggerShellySoftReset(matterbridge) {
|
|
|
256
160
|
matterbridge.frontend.wssSendSnackbarMessage('Error resetting the network parameters on Shelly board', 10, 'error');
|
|
257
161
|
}
|
|
258
162
|
}
|
|
259
|
-
/**
|
|
260
|
-
* Triggers Shelly hard reset.
|
|
261
|
-
* It will do a hard reset and will remove both directories .matterbridge Matterbridge.
|
|
262
|
-
*
|
|
263
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
264
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
265
|
-
*/
|
|
266
163
|
export async function triggerShellyHardReset(matterbridge) {
|
|
267
164
|
matterbridge.log.debug(`Triggering Shelly hard reset`);
|
|
268
165
|
try {
|
|
@@ -280,12 +177,6 @@ export async function triggerShellyHardReset(matterbridge) {
|
|
|
280
177
|
matterbridge.frontend.wssSendSnackbarMessage('Error while factory resetting the Shelly board', 10, 'error');
|
|
281
178
|
}
|
|
282
179
|
}
|
|
283
|
-
/**
|
|
284
|
-
* Fetches Shelly system log and write it to shelly.log.
|
|
285
|
-
*
|
|
286
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
287
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the log was successfully downloaded, false otherwise.
|
|
288
|
-
*/
|
|
289
180
|
export async function createShellySystemLog(matterbridge) {
|
|
290
181
|
const { promises: fs } = await import('node:fs');
|
|
291
182
|
const path = await import('node:path');
|
|
@@ -302,28 +193,6 @@ export async function createShellySystemLog(matterbridge) {
|
|
|
302
193
|
return false;
|
|
303
194
|
}
|
|
304
195
|
}
|
|
305
|
-
/**
|
|
306
|
-
* Perform a GET to Shelly board apis.
|
|
307
|
-
*
|
|
308
|
-
* @param {string} api - The api to call:
|
|
309
|
-
*
|
|
310
|
-
* /api/updates/sys/check => [{name:string; ...}]
|
|
311
|
-
* /api/updates/sys/perform => {"updatingInProgress":true} or {"updatingInProgress":false}
|
|
312
|
-
* /api/updates/sys/status => {"updatingInProgress":true} or {"updatingInProgress":false}
|
|
313
|
-
* /api/updates/main/check => [{name:string; ...}]
|
|
314
|
-
* /api/updates/main/perform => {"updatingInProgress":true} or {"updatingInProgress":false}
|
|
315
|
-
* /api/updates/main/status => {"updatingInProgress":true} or {"updatingInProgress":false}
|
|
316
|
-
*
|
|
317
|
-
* /api/logs/system => text
|
|
318
|
-
*
|
|
319
|
-
* /api/reset/soft => "ok" Replaces network config with default one (edn0 on dhcp)
|
|
320
|
-
* /api/reset/hard => reboot on success Hard reset makes soft reset + removing both directories .matterbridge Matterbridge + reboot
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
* @param {number} [timeout] - The timeout duration in milliseconds (default is 60000ms).
|
|
324
|
-
* @returns {Promise<any>} A promise that resolves to the response.
|
|
325
|
-
* @throws {Error} If the request fails.
|
|
326
|
-
*/
|
|
327
196
|
export async function getShelly(api, timeout = 60000) {
|
|
328
197
|
const http = await import('node:http');
|
|
329
198
|
return new Promise((resolve, reject) => {
|
|
@@ -337,13 +206,12 @@ export async function getShelly(api, timeout = 60000) {
|
|
|
337
206
|
let data = '';
|
|
338
207
|
if (res.statusCode !== 200) {
|
|
339
208
|
clearTimeout(timeoutId);
|
|
340
|
-
res.resume();
|
|
341
|
-
req.destroy();
|
|
209
|
+
res.resume();
|
|
210
|
+
req.destroy();
|
|
342
211
|
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
343
212
|
return;
|
|
344
213
|
}
|
|
345
214
|
res.on('data', (chunk) => {
|
|
346
|
-
// console.log(chunk);
|
|
347
215
|
data += chunk;
|
|
348
216
|
});
|
|
349
217
|
res.on('end', () => {
|
|
@@ -358,7 +226,6 @@ export async function getShelly(api, timeout = 60000) {
|
|
|
358
226
|
}
|
|
359
227
|
}
|
|
360
228
|
else {
|
|
361
|
-
// console.log(data);
|
|
362
229
|
resolve(data);
|
|
363
230
|
}
|
|
364
231
|
});
|
|
@@ -369,31 +236,6 @@ export async function getShelly(api, timeout = 60000) {
|
|
|
369
236
|
});
|
|
370
237
|
});
|
|
371
238
|
}
|
|
372
|
-
/**
|
|
373
|
-
* Perform a POST request to Shelly board apis.
|
|
374
|
-
*
|
|
375
|
-
* @param {string} api - The api to call:
|
|
376
|
-
*
|
|
377
|
-
* Set static ip
|
|
378
|
-
* /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"}' => {}
|
|
379
|
-
*
|
|
380
|
-
* Set dhcp
|
|
381
|
-
* /api/network/connection/dynamic -d '{"interface": "end0"}' => {}
|
|
382
|
-
*
|
|
383
|
-
* Reboot
|
|
384
|
-
* /api/system/reboot => {"success":true}
|
|
385
|
-
*
|
|
386
|
-
* curl -H "Content-Type: application/json" -X POST http://127.0.0.1:8101/api/network/connection/dynamic
|
|
387
|
-
* -d '{"interface": "end0"}'
|
|
388
|
-
*
|
|
389
|
-
* curl -H "Content-Type: application/json" -X POST http://127.0.0.1:8101/api/network/connection/static
|
|
390
|
-
* -d '{"interface": "end0", "addr": "192.168.1.64", "mask": "255.255.255.0", "gw": "192.168.1.1", "dns": "192.168.1.1"}'
|
|
391
|
-
*
|
|
392
|
-
* @param {any} data - The data to send in the POST request, typically a JSON object.
|
|
393
|
-
* @param {number} [timeout] - The timeout duration in milliseconds (default is 60000ms).
|
|
394
|
-
* @returns {Promise<any>} A promise that resolves to the response.
|
|
395
|
-
* @throws {Error} If the request fails.
|
|
396
|
-
*/
|
|
397
239
|
export async function postShelly(api, data, timeout = 60000) {
|
|
398
240
|
const http = await import('node:http');
|
|
399
241
|
return new Promise((resolve, reject) => {
|
|
@@ -414,11 +256,10 @@ export async function postShelly(api, data, timeout = 60000) {
|
|
|
414
256
|
};
|
|
415
257
|
const req = http.request(url, options, (res) => {
|
|
416
258
|
let responseData = '';
|
|
417
|
-
// Check for non-success status codes (e.g., 300+)
|
|
418
259
|
if (res.statusCode && res.statusCode >= 300) {
|
|
419
260
|
clearTimeout(timeoutId);
|
|
420
|
-
res.resume();
|
|
421
|
-
req.destroy();
|
|
261
|
+
res.resume();
|
|
262
|
+
req.destroy();
|
|
422
263
|
return reject(new Error(`Failed to post data. Status code: ${res.statusCode}`));
|
|
423
264
|
}
|
|
424
265
|
res.on('data', (chunk) => {
|
|
@@ -439,9 +280,7 @@ export async function postShelly(api, data, timeout = 60000) {
|
|
|
439
280
|
clearTimeout(timeoutId);
|
|
440
281
|
reject(new Error(`Request failed: ${error instanceof Error ? error.message : error}`));
|
|
441
282
|
});
|
|
442
|
-
// Send the JSON data
|
|
443
283
|
req.write(jsonData);
|
|
444
284
|
req.end();
|
|
445
285
|
});
|
|
446
286
|
}
|
|
447
|
-
//# sourceMappingURL=shelly.js.map
|
package/dist/storage/export.js
CHANGED
package/dist/update.js
CHANGED
|
@@ -1,36 +1,5 @@
|
|
|
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
|
-
/**
|
|
28
|
-
* Checks for updates for Matterbridge and its plugins.
|
|
29
|
-
* If the 'shelly' parameter is present, also checks for Shelly updates.
|
|
30
|
-
*
|
|
31
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
32
|
-
* @returns {Promise<void>} A promise that resolves when the update checks are complete.
|
|
33
|
-
*/
|
|
34
3
|
export async function checkUpdates(matterbridge) {
|
|
35
4
|
const { hasParameter } = await import('./utils/commandLine.js');
|
|
36
5
|
const update = checkUpdatesAndLog(matterbridge);
|
|
@@ -54,12 +23,6 @@ export async function checkUpdates(matterbridge) {
|
|
|
54
23
|
}
|
|
55
24
|
await Promise.all([update, latestVersion, devVersion, ...pluginsVersions, ...pluginsDevVersions, ...shellyUpdates]);
|
|
56
25
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Checks for updates and logs from GitHub.
|
|
59
|
-
* If the update check fails, logs a warning message.
|
|
60
|
-
*
|
|
61
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
62
|
-
*/
|
|
63
26
|
export async function checkUpdatesAndLog(matterbridge) {
|
|
64
27
|
const { getGitHubUpdate } = await import('./utils/network.js');
|
|
65
28
|
const { isValidString } = await import('./utils/isvalid.js');
|
|
@@ -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 {
|
|
@@ -103,17 +59,9 @@ export async function getMatterbridgeLatestVersion(matterbridge) {
|
|
|
103
59
|
return version;
|
|
104
60
|
}
|
|
105
61
|
catch (error) {
|
|
106
|
-
// logError(matterbridge.log, `Error getting Matterbridge latest version`, error);
|
|
107
62
|
matterbridge.log.warn(`Error getting Matterbridge latest version: ${error instanceof Error ? error.message : error}`);
|
|
108
63
|
}
|
|
109
64
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Retrieves the latest dev version of Matterbridge and updates the matterbridgeDevVersion property.
|
|
112
|
-
* If there is an error retrieving the latest version, logs an error message.
|
|
113
|
-
*
|
|
114
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
115
|
-
* @returns {Promise<string | undefined>} A promise that resolves when the latest dev version is retrieved.
|
|
116
|
-
*/
|
|
117
65
|
export async function getMatterbridgeDevVersion(matterbridge) {
|
|
118
66
|
const { getNpmPackageVersion } = await import('./utils/network.js');
|
|
119
67
|
try {
|
|
@@ -135,14 +83,6 @@ export async function getMatterbridgeDevVersion(matterbridge) {
|
|
|
135
83
|
matterbridge.log.warn(`Error getting Matterbridge latest dev version: ${error instanceof Error ? error.message : error}`);
|
|
136
84
|
}
|
|
137
85
|
}
|
|
138
|
-
/**
|
|
139
|
-
* Retrieves the latest version of a plugin and updates the plugin's latestVersion property.
|
|
140
|
-
* If there is an error retrieving the latest version, logs an error message.
|
|
141
|
-
*
|
|
142
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
143
|
-
* @param {Plugin} plugin - The plugin for which to retrieve the latest version.
|
|
144
|
-
* @returns {Promise<string | undefined>} A promise that resolves when the latest version is retrieved.
|
|
145
|
-
*/
|
|
146
86
|
export async function getPluginLatestVersion(matterbridge, plugin) {
|
|
147
87
|
const { getNpmPackageVersion } = await import('./utils/network.js');
|
|
148
88
|
try {
|
|
@@ -161,14 +101,6 @@ export async function getPluginLatestVersion(matterbridge, plugin) {
|
|
|
161
101
|
matterbridge.log.warn(`Error getting plugin ${plg}${plugin.name}${wr} latest version: ${error instanceof Error ? error.message : error}`);
|
|
162
102
|
}
|
|
163
103
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Retrieves the latest dev version of a plugin and updates the plugin's devVersion property.
|
|
166
|
-
* If there is an error retrieving the latest version, logs an error message.
|
|
167
|
-
*
|
|
168
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
169
|
-
* @param {Plugin} plugin - The plugin for which to retrieve the latest version.
|
|
170
|
-
* @returns {Promise<string | undefined>} A promise that resolves when the latest dev version is retrieved.
|
|
171
|
-
*/
|
|
172
104
|
export async function getPluginDevVersion(matterbridge, plugin) {
|
|
173
105
|
const { getNpmPackageVersion } = await import('./utils/network.js');
|
|
174
106
|
try {
|
|
@@ -187,4 +119,3 @@ export async function getPluginDevVersion(matterbridge, plugin) {
|
|
|
187
119
|
matterbridge.log.debug(`Error getting plugin ${plg}${plugin.name}${db} latest dev version: ${error instanceof Error ? error.message : error}`);
|
|
188
120
|
}
|
|
189
121
|
}
|
|
190
|
-
//# 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,48 +139,21 @@ 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
149
|
export const miredsToKelvin = miredToKelvin;
|
|
228
|
-
/**
|
|
229
|
-
* Converts kelvin to mireds.
|
|
230
|
-
*
|
|
231
|
-
* @param {number} kelvin - The kelvin value to convert.
|
|
232
|
-
* @returns {number} The converted mired value.
|
|
233
|
-
*/
|
|
234
150
|
export function kelvinToMired(kelvin) {
|
|
235
151
|
return Math.round(1000000 / kelvin);
|
|
236
152
|
}
|
|
237
153
|
export const kelvinToMireds = kelvinToMired;
|
|
238
|
-
/**
|
|
239
|
-
* Converts kelvin to RGB color space.
|
|
240
|
-
*
|
|
241
|
-
* @param {number} kelvin - The kelvin value to convert (1000K to 40000K).
|
|
242
|
-
* @returns {RGB} An object containing the RGB values.
|
|
243
|
-
*/
|
|
244
154
|
export function kelvinToRGB(kelvin) {
|
|
245
|
-
// Clamp the temperature to the range 1000K to 40000K
|
|
246
155
|
kelvin = Math.max(1000, Math.min(40000, kelvin)) / 100;
|
|
247
156
|
let r, g, b;
|
|
248
|
-
// Calculate red
|
|
249
157
|
if (kelvin <= 66) {
|
|
250
158
|
r = 255;
|
|
251
159
|
}
|
|
@@ -254,7 +162,6 @@ export function kelvinToRGB(kelvin) {
|
|
|
254
162
|
r = 329.698727446 * Math.pow(r, -0.1332047592);
|
|
255
163
|
r = Math.max(0, Math.min(255, r));
|
|
256
164
|
}
|
|
257
|
-
// Calculate green
|
|
258
165
|
if (kelvin <= 66) {
|
|
259
166
|
g = kelvin;
|
|
260
167
|
g = 99.4708025861 * Math.log(g) - 161.1195681661;
|
|
@@ -265,7 +172,6 @@ export function kelvinToRGB(kelvin) {
|
|
|
265
172
|
g = 288.1221695283 * Math.pow(g, -0.0755148492);
|
|
266
173
|
g = Math.max(0, Math.min(255, g));
|
|
267
174
|
}
|
|
268
|
-
// Calculate blue
|
|
269
175
|
if (kelvin >= 66) {
|
|
270
176
|
b = 255;
|
|
271
177
|
}
|
|
@@ -279,4 +185,3 @@ export function kelvinToRGB(kelvin) {
|
|
|
279
185
|
}
|
|
280
186
|
return { r: Math.round(r), g: Math.round(g), b: Math.round(b) };
|
|
281
187
|
}
|
|
282
|
-
//# sourceMappingURL=colorUtils.js.map
|