homebridge 2.0.0-alpha.8 → 2.0.0-alpha.80
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/README.md +1 -1
- package/bin/homebridge.js +22 -0
- package/dist/api.d.ts +250 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +92 -0
- package/dist/api.js.map +1 -1
- package/dist/bridgeService.d.ts +11 -3
- package/dist/bridgeService.d.ts.map +1 -1
- package/dist/bridgeService.js +9 -5
- package/dist/bridgeService.js.map +1 -1
- package/dist/childBridgeFork.d.ts +30 -3
- package/dist/childBridgeFork.d.ts.map +1 -1
- package/dist/childBridgeFork.js +295 -5
- package/dist/childBridgeFork.js.map +1 -1
- package/dist/childBridgeService.d.ts +22 -0
- package/dist/childBridgeService.d.ts.map +1 -1
- package/dist/childBridgeService.js +85 -26
- package/dist/childBridgeService.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -1
- package/dist/cli.js.map +1 -1
- package/dist/externalPortService.d.ts +27 -6
- package/dist/externalPortService.d.ts.map +1 -1
- package/dist/externalPortService.js +73 -7
- package/dist/externalPortService.js.map +1 -1
- package/dist/index.d.ts +49 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -1
- package/dist/ipcService.d.ts +20 -0
- package/dist/ipcService.d.ts.map +1 -1
- package/dist/ipcService.js.map +1 -1
- package/dist/logger.d.ts +6 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +8 -0
- package/dist/logger.js.map +1 -1
- package/dist/matter/index.d.ts +123 -0
- package/dist/matter/index.d.ts.map +1 -0
- package/dist/matter/index.js +19 -0
- package/dist/matter/index.js.map +1 -0
- package/dist/matter/matterAccessoryCache.d.ts +79 -0
- package/dist/matter/matterAccessoryCache.d.ts.map +1 -0
- package/dist/matter/matterAccessoryCache.js +175 -0
- package/dist/matter/matterAccessoryCache.js.map +1 -0
- package/dist/matter/matterBehaviors.d.ts +178 -0
- package/dist/matter/matterBehaviors.d.ts.map +1 -0
- package/dist/matter/matterBehaviors.js +655 -0
- package/dist/matter/matterBehaviors.js.map +1 -0
- package/dist/matter/matterConfigValidator.d.ts +81 -0
- package/dist/matter/matterConfigValidator.d.ts.map +1 -0
- package/dist/matter/matterConfigValidator.js +240 -0
- package/dist/matter/matterConfigValidator.js.map +1 -0
- package/dist/matter/matterErrorHandler.d.ts +106 -0
- package/dist/matter/matterErrorHandler.d.ts.map +1 -0
- package/dist/matter/matterErrorHandler.js +495 -0
- package/dist/matter/matterErrorHandler.js.map +1 -0
- package/dist/matter/matterLogFormatter.d.ts +19 -0
- package/dist/matter/matterLogFormatter.d.ts.map +1 -0
- package/dist/matter/matterLogFormatter.js +136 -0
- package/dist/matter/matterLogFormatter.js.map +1 -0
- package/dist/matter/matterNetworkMonitor.d.ts +68 -0
- package/dist/matter/matterNetworkMonitor.d.ts.map +1 -0
- package/dist/matter/matterNetworkMonitor.js +249 -0
- package/dist/matter/matterNetworkMonitor.js.map +1 -0
- package/dist/matter/matterServer.d.ts +649 -0
- package/dist/matter/matterServer.d.ts.map +1 -0
- package/dist/matter/matterServer.js +1548 -0
- package/dist/matter/matterServer.js.map +1 -0
- package/dist/matter/matterServerHelpers.d.ts +81 -0
- package/dist/matter/matterServerHelpers.d.ts.map +1 -0
- package/dist/matter/matterServerHelpers.js +305 -0
- package/dist/matter/matterServerHelpers.js.map +1 -0
- package/dist/matter/matterSharedTypes.d.ts +170 -0
- package/dist/matter/matterSharedTypes.d.ts.map +1 -0
- package/dist/matter/matterSharedTypes.js +52 -0
- package/dist/matter/matterSharedTypes.js.map +1 -0
- package/dist/matter/matterStorage.d.ts +128 -0
- package/dist/matter/matterStorage.d.ts.map +1 -0
- package/dist/matter/matterStorage.js +415 -0
- package/dist/matter/matterStorage.js.map +1 -0
- package/dist/matter/matterTypes.d.ts +658 -0
- package/dist/matter/matterTypes.d.ts.map +1 -0
- package/dist/matter/matterTypes.js +174 -0
- package/dist/matter/matterTypes.js.map +1 -0
- package/dist/platformAccessory.d.ts +1 -0
- package/dist/platformAccessory.d.ts.map +1 -1
- package/dist/platformAccessory.js +8 -1
- package/dist/platformAccessory.js.map +1 -1
- package/dist/plugin.d.ts +0 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +5 -8
- package/dist/plugin.js.map +1 -1
- package/dist/pluginManager.d.ts.map +1 -1
- package/dist/pluginManager.js +22 -21
- package/dist/pluginManager.js.map +1 -1
- package/dist/server.d.ts +23 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +391 -10
- package/dist/server.js.map +1 -1
- package/dist/storageService.js +8 -8
- package/dist/storageService.js.map +1 -1
- package/dist/user.d.ts +1 -0
- package/dist/user.d.ts.map +1 -1
- package/dist/user.js +10 -7
- package/dist/user.js.map +1 -1
- package/dist/util/mac.d.ts.map +1 -1
- package/dist/util/mac.js +2 -2
- package/dist/util/mac.js.map +1 -1
- package/dist/version.js +2 -2
- package/dist/version.js.map +1 -1
- package/package.json +21 -20
- package/bin/homebridge +0 -19
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matter Accessory Cache
|
|
3
|
+
*
|
|
4
|
+
* Handles persistence of Matter accessories across Homebridge restarts.
|
|
5
|
+
* Similar to HAP's cached accessories, but designed for Matter's simpler API.
|
|
6
|
+
*/
|
|
7
|
+
import { dirname, join } from 'node:path';
|
|
8
|
+
import fs from 'fs-extra';
|
|
9
|
+
import { Logger } from '../logger.js';
|
|
10
|
+
const log = Logger.withPrefix('Matter/Accessories');
|
|
11
|
+
/**
|
|
12
|
+
* Matter Accessory Cache Manager
|
|
13
|
+
*/
|
|
14
|
+
export class MatterAccessoryCache {
|
|
15
|
+
cacheFilePath;
|
|
16
|
+
cachedAccessories = new Map();
|
|
17
|
+
cacheLoaded = false;
|
|
18
|
+
saveQueue = Promise.resolve();
|
|
19
|
+
directoryEnsured = false;
|
|
20
|
+
constructor(storagePath, bridgeId) {
|
|
21
|
+
this.cacheFilePath = join(storagePath, bridgeId, 'accessories.json');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Load cached accessories from disk
|
|
25
|
+
* Returns a map of cached accessories keyed by UUID
|
|
26
|
+
*/
|
|
27
|
+
async load() {
|
|
28
|
+
if (this.cacheLoaded) {
|
|
29
|
+
return this.cachedAccessories;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
// Check if cache file exists
|
|
33
|
+
if (!await fs.pathExists(this.cacheFilePath)) {
|
|
34
|
+
log.info('No cached Matter accessories found (first run)');
|
|
35
|
+
this.cacheLoaded = true;
|
|
36
|
+
return this.cachedAccessories;
|
|
37
|
+
}
|
|
38
|
+
// Read and parse cache file
|
|
39
|
+
const cacheData = await fs.readJson(this.cacheFilePath);
|
|
40
|
+
if (!Array.isArray(cacheData)) {
|
|
41
|
+
throw new TypeError('Cache file does not contain an array');
|
|
42
|
+
}
|
|
43
|
+
// Load accessories into map (only those with valid UUIDs)
|
|
44
|
+
for (const serialized of cacheData) {
|
|
45
|
+
if (serialized.uuid) {
|
|
46
|
+
this.cachedAccessories.set(serialized.uuid, serialized);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
log.info(`Loaded ${this.cachedAccessories.size} cached Matter accessories`);
|
|
50
|
+
// Directory must exist if we successfully loaded the cache file
|
|
51
|
+
this.directoryEnsured = true;
|
|
52
|
+
this.cacheLoaded = true;
|
|
53
|
+
return this.cachedAccessories;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
// If JSON parsing failed (corrupted file), delete it and start fresh
|
|
57
|
+
log.error(`Failed to load Matter accessory cache from ${this.cacheFilePath}: ${error.message}`);
|
|
58
|
+
log.warn('Deleting corrupted cache file and starting fresh');
|
|
59
|
+
try {
|
|
60
|
+
await fs.remove(this.cacheFilePath);
|
|
61
|
+
}
|
|
62
|
+
catch (removeError) {
|
|
63
|
+
// non-fatal: couldn't delete corrupted file
|
|
64
|
+
log.debug('Could not delete corrupted cache file:', removeError);
|
|
65
|
+
}
|
|
66
|
+
this.cacheLoaded = true;
|
|
67
|
+
return this.cachedAccessories;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Save accessories to cache (serialized to prevent concurrent write conflicts)
|
|
72
|
+
* Uses a queue pattern to ensure saves are truly serialized even when called concurrently
|
|
73
|
+
*/
|
|
74
|
+
async save(accessories) {
|
|
75
|
+
// Chain this save to the end of the queue
|
|
76
|
+
// This ensures all saves run sequentially without race conditions
|
|
77
|
+
this.saveQueue = this.saveQueue.then(() => this.performSave(accessories));
|
|
78
|
+
// Wait for this save to complete
|
|
79
|
+
await this.saveQueue;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Internal save implementation
|
|
83
|
+
* Performs atomic write to prevent cache corruption on system crashes
|
|
84
|
+
*/
|
|
85
|
+
async performSave(accessories) {
|
|
86
|
+
const tempFilePath = `${this.cacheFilePath}.tmp`;
|
|
87
|
+
try {
|
|
88
|
+
// Serialize accessories (strip out functions and non-serializable objects)
|
|
89
|
+
const serialized = Array.from(accessories.values())
|
|
90
|
+
.map(accessory => this.serializeAccessory(accessory));
|
|
91
|
+
// Ensure directory exists (only check once, not on every save)
|
|
92
|
+
if (!this.directoryEnsured) {
|
|
93
|
+
const directory = dirname(this.cacheFilePath);
|
|
94
|
+
await fs.ensureDir(directory);
|
|
95
|
+
// Verify directory was created successfully
|
|
96
|
+
const dirExists = await fs.pathExists(directory);
|
|
97
|
+
if (!dirExists) {
|
|
98
|
+
throw new Error(`Failed to create cache directory: ${directory}`);
|
|
99
|
+
}
|
|
100
|
+
this.directoryEnsured = true;
|
|
101
|
+
log.debug(`Cache directory ensured: ${directory}`);
|
|
102
|
+
}
|
|
103
|
+
// Write to temporary file first (atomic write pattern to prevent corruption)
|
|
104
|
+
await fs.writeJson(tempFilePath, serialized, { spaces: 2 });
|
|
105
|
+
// Atomically move temp file to final location
|
|
106
|
+
// Use move instead of rename for better cross-device compatibility
|
|
107
|
+
await fs.move(tempFilePath, this.cacheFilePath, { overwrite: true });
|
|
108
|
+
log.debug(`Saved ${serialized.length} Matter accessor${serialized.length === 1 ? 'y' : 'ies'} to cache`);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
log.error(`Failed to save Matter accessory cache: ${error.message}`);
|
|
112
|
+
// Clean up temp file if it exists
|
|
113
|
+
try {
|
|
114
|
+
if (await fs.pathExists(tempFilePath)) {
|
|
115
|
+
await fs.remove(tempFilePath);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (cleanupError) {
|
|
119
|
+
// non-fatal: couldn't clean up temp file
|
|
120
|
+
log.debug('Could not clean up temporary cache file:', cleanupError);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get cached accessory by UUID
|
|
126
|
+
*/
|
|
127
|
+
getCached(uuid) {
|
|
128
|
+
return this.cachedAccessories.get(uuid);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Check if an accessory is cached
|
|
132
|
+
*/
|
|
133
|
+
hasCached(uuid) {
|
|
134
|
+
return this.cachedAccessories.has(uuid);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Remove an accessory from cache
|
|
138
|
+
*/
|
|
139
|
+
removeCached(uuid) {
|
|
140
|
+
this.cachedAccessories.delete(uuid);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get all cached accessories
|
|
144
|
+
*/
|
|
145
|
+
getAllCached() {
|
|
146
|
+
return new Map(this.cachedAccessories);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Serialize a Matter accessory for storage
|
|
150
|
+
*/
|
|
151
|
+
serializeAccessory(accessory) {
|
|
152
|
+
// Extract device type information
|
|
153
|
+
const deviceType = accessory.deviceType;
|
|
154
|
+
const deviceTypeInfo = {
|
|
155
|
+
name: deviceType?.name,
|
|
156
|
+
code: deviceType?.code,
|
|
157
|
+
};
|
|
158
|
+
return {
|
|
159
|
+
plugin: accessory._associatedPlugin || '',
|
|
160
|
+
platform: accessory._associatedPlatform || '',
|
|
161
|
+
uuid: accessory.uuid,
|
|
162
|
+
displayName: accessory.displayName,
|
|
163
|
+
deviceType: deviceTypeInfo,
|
|
164
|
+
serialNumber: accessory.serialNumber,
|
|
165
|
+
manufacturer: accessory.manufacturer,
|
|
166
|
+
model: accessory.model,
|
|
167
|
+
firmwareRevision: accessory.firmwareRevision,
|
|
168
|
+
hardwareRevision: accessory.hardwareRevision,
|
|
169
|
+
softwareVersion: accessory.softwareVersion,
|
|
170
|
+
context: accessory.context,
|
|
171
|
+
clusters: structuredClone(accessory.clusters),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=matterAccessoryCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matterAccessoryCache.js","sourceRoot":"","sources":["../../src/matter/matterAccessoryCache.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEzC,OAAO,EAAE,MAAM,UAAU,CAAA;AAEzB,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAA;AA4BnD;;GAEG;AACH,MAAM,OAAO,oBAAoB;IACd,aAAa,CAAQ;IAC9B,iBAAiB,GAA2C,IAAI,GAAG,EAAE,CAAA;IACrE,WAAW,GAAG,KAAK,CAAA;IACnB,SAAS,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAA;IAC5C,gBAAgB,GAAG,KAAK,CAAA;IAEhC,YAAY,WAAmB,EAAE,QAAgB;QAC/C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,kBAAkB,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+
* These custom behaviors extend the base Matter.js behaviors and override
|
|
5
|
+
* command methods to allow plugins to inject custom handlers.
|
|
6
|
+
*
|
|
7
|
+
* Note: Only clusters with user-triggered commands need custom behaviors.
|
|
8
|
+
* Read-only clusters (like sensors) don't need custom behaviors since
|
|
9
|
+
* they only report state, they don't receive commands.
|
|
10
|
+
*/
|
|
11
|
+
import type { MaybePromise } from '@matter/main';
|
|
12
|
+
import type { ColorControl, Identify, LevelControl, ServiceArea, Thermostat, WindowCovering } from '@matter/main/clusters';
|
|
13
|
+
import type { MatterAccessoryMap, MatterCommandHandler } from './matterTypes.js';
|
|
14
|
+
import { ColorControlServer, DoorLockServer, FanControlServer, IdentifyServer, LevelControlServer, OnOffServer, RvcCleanModeServer, RvcOperationalStateServer, RvcRunModeServer, ServiceAreaServer, ThermostatServer, WindowCoveringBaseServer } from '@matter/main/behaviors';
|
|
15
|
+
import { RvcOperationalState } from '@matter/main/clusters';
|
|
16
|
+
/**
|
|
17
|
+
* Result type for Matter commands
|
|
18
|
+
* MaybePromise allows both sync and async returns, matching Matter.js base classes
|
|
19
|
+
*/
|
|
20
|
+
type MatterCommandResult = MaybePromise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Set the accessories map reference for cache syncing
|
|
23
|
+
*/
|
|
24
|
+
export declare function setAccessoriesMap(map: MatterAccessoryMap): void;
|
|
25
|
+
/**
|
|
26
|
+
* Register a handler for a specific endpoint/cluster/command
|
|
27
|
+
*
|
|
28
|
+
* @param endpointId - Unique endpoint identifier (typically the accessory UUID)
|
|
29
|
+
* @param clusterName - Name of the Matter cluster (e.g., 'onOff', 'levelControl')
|
|
30
|
+
* @param commandName - Name of the command method (e.g., 'on', 'off', 'moveToLevel')
|
|
31
|
+
* @param handler - Callback function to execute when the command is received
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* registerHandler('my-light-uuid', 'onOff', 'on', async () => {
|
|
36
|
+
* console.log('Light turned on!')
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function registerHandler(endpointId: string, clusterName: string, commandName: string, handler: MatterCommandHandler): void;
|
|
41
|
+
/**
|
|
42
|
+
* Custom OnOff Server that calls plugin handlers
|
|
43
|
+
*/
|
|
44
|
+
export declare class HomebridgeOnOffServer extends OnOffServer {
|
|
45
|
+
on(): MatterCommandResult;
|
|
46
|
+
off(): MatterCommandResult;
|
|
47
|
+
toggle(): MatterCommandResult;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Custom LevelControl Server that calls plugin handlers
|
|
51
|
+
*/
|
|
52
|
+
export declare class HomebridgeLevelControlServer extends LevelControlServer {
|
|
53
|
+
moveToLevel(request: LevelControl.MoveToLevelRequest): MatterCommandResult;
|
|
54
|
+
moveToLevelWithOnOff(request: LevelControl.MoveToLevelRequest): MaybePromise;
|
|
55
|
+
move(request: LevelControl.MoveRequest): MaybePromise;
|
|
56
|
+
step(request: LevelControl.StepRequest): MaybePromise;
|
|
57
|
+
stop(request: LevelControl.StopRequest): MaybePromise;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Custom WindowCovering Server that calls plugin handlers
|
|
61
|
+
*/
|
|
62
|
+
export declare class HomebridgeWindowCoveringServer extends WindowCoveringBaseServer {
|
|
63
|
+
upOrOpen(): MaybePromise;
|
|
64
|
+
downOrClose(): MaybePromise;
|
|
65
|
+
stopMotion(): MaybePromise;
|
|
66
|
+
goToLiftPercentage(request: WindowCovering.GoToLiftPercentageRequest): MaybePromise;
|
|
67
|
+
goToTiltPercentage(request: WindowCovering.GoToTiltPercentageRequest): MaybePromise;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Custom FanControl Server that calls plugin handlers
|
|
71
|
+
*/
|
|
72
|
+
export declare class HomebridgeFanControlServer extends FanControlServer {
|
|
73
|
+
#private;
|
|
74
|
+
initialize(): void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Custom DoorLock Server that calls plugin handlers
|
|
78
|
+
*/
|
|
79
|
+
export declare class HomebridgeDoorLockServer extends DoorLockServer {
|
|
80
|
+
lockDoor(): MaybePromise;
|
|
81
|
+
unlockDoor(): MaybePromise;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Custom Thermostat Server that calls plugin handlers
|
|
85
|
+
*/
|
|
86
|
+
export declare class HomebridgeThermostatServer extends ThermostatServer {
|
|
87
|
+
#private;
|
|
88
|
+
initialize(): void;
|
|
89
|
+
setpointRaiseLower(request: Thermostat.SetpointRaiseLowerRequest): MaybePromise;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Custom Identify Server that calls plugin handlers
|
|
93
|
+
*/
|
|
94
|
+
export declare class HomebridgeIdentifyServer extends IdentifyServer {
|
|
95
|
+
identify(request: Identify.IdentifyRequest): MaybePromise;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Custom ColorControl Server that calls plugin handlers
|
|
99
|
+
*
|
|
100
|
+
* ColorControl handles color changes for lights (hue, saturation, XY color, color temperature).
|
|
101
|
+
* Plugin developers can override these *Logic methods to handle color changes in their hardware.
|
|
102
|
+
*
|
|
103
|
+
* Features (Xy, ColorTemperature, HueSaturation) are added by the device type, not this behavior.
|
|
104
|
+
* This ensures each device only gets the features it needs.
|
|
105
|
+
*/
|
|
106
|
+
export declare class HomebridgeColorControlServer extends ColorControlServer {
|
|
107
|
+
/**
|
|
108
|
+
* Called when color temperature is changed
|
|
109
|
+
* @param colorTemperatureMireds - Target color temperature in mireds (micro reciprocal degrees)
|
|
110
|
+
* @param transitionTime - Transition time in seconds (0 = as fast as possible)
|
|
111
|
+
*/
|
|
112
|
+
moveToColorTemperatureLogic(colorTemperatureMireds: number, transitionTime: number): MaybePromise;
|
|
113
|
+
/**
|
|
114
|
+
* Called when hue and saturation are changed together
|
|
115
|
+
* @param hue - Target hue value (0-254 for normal hue, 0-65535 for enhanced hue)
|
|
116
|
+
* @param saturation - Target saturation value (0-254)
|
|
117
|
+
* @param transitionTime - Transition time in seconds (0 = as fast as possible)
|
|
118
|
+
*/
|
|
119
|
+
moveToHueAndSaturationLogic(hue: number, saturation: number, transitionTime: number): MaybePromise;
|
|
120
|
+
/**
|
|
121
|
+
* Called when XY color coordinates are changed
|
|
122
|
+
* @param targetX - Target X value (0-65535 representing 0.0-1.0 in CIE color space)
|
|
123
|
+
* @param targetY - Target Y value (0-65535 representing 0.0-1.0 in CIE color space)
|
|
124
|
+
* @param transitionTime - Transition time in seconds (0 = as fast as possible)
|
|
125
|
+
*/
|
|
126
|
+
moveToColorLogic(targetX: number, targetY: number, transitionTime: number): MaybePromise;
|
|
127
|
+
/**
|
|
128
|
+
* Called when hue is changed individually
|
|
129
|
+
* @param targetHue - Target hue value
|
|
130
|
+
* @param direction - Direction to move (shortest, longest, up, down)
|
|
131
|
+
* @param transitionTime - Transition time in seconds
|
|
132
|
+
* @param isEnhancedHue - Whether this is enhanced hue (16-bit) or normal hue (8-bit)
|
|
133
|
+
*/
|
|
134
|
+
moveToHueLogic(targetHue: number, direction: ColorControl.Direction, transitionTime: number, isEnhancedHue?: boolean): MaybePromise;
|
|
135
|
+
/**
|
|
136
|
+
* Called when saturation is changed individually
|
|
137
|
+
* @param targetSaturation - Target saturation value (0-254)
|
|
138
|
+
* @param transitionTime - Transition time in seconds
|
|
139
|
+
*/
|
|
140
|
+
moveToSaturationLogic(targetSaturation: number, transitionTime: number): MaybePromise;
|
|
141
|
+
/**
|
|
142
|
+
* Called when all color movement should be stopped
|
|
143
|
+
*/
|
|
144
|
+
stopAllColorMovement(): MaybePromise;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Custom RvcOperationalState Server that calls plugin handlers
|
|
148
|
+
* Handles robotic vacuum cleaner operational state commands
|
|
149
|
+
*/
|
|
150
|
+
export declare class HomebridgeRvcOperationalStateServer extends RvcOperationalStateServer {
|
|
151
|
+
pause(): MaybePromise<RvcOperationalState.OperationalCommandResponse>;
|
|
152
|
+
resume(): MaybePromise<RvcOperationalState.OperationalCommandResponse>;
|
|
153
|
+
goHome(): MaybePromise<RvcOperationalState.OperationalCommandResponse>;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Custom RvcRunMode Server that calls plugin handlers
|
|
157
|
+
* Handles robotic vacuum cleaner run mode changes
|
|
158
|
+
*/
|
|
159
|
+
export declare class HomebridgeRvcRunModeServer extends RvcRunModeServer {
|
|
160
|
+
changeToMode(request: any): any;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Custom RvcCleanMode Server that calls plugin handlers
|
|
164
|
+
* Handles robotic vacuum cleaner cleaning mode changes
|
|
165
|
+
*/
|
|
166
|
+
export declare class HomebridgeRvcCleanModeServer extends RvcCleanModeServer {
|
|
167
|
+
changeToMode(request: any): any;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Custom ServiceArea Server that calls plugin handlers
|
|
171
|
+
* Handles service area selection for robotic vacuum cleaners
|
|
172
|
+
*/
|
|
173
|
+
export declare class HomebridgeServiceAreaServer extends ServiceAreaServer {
|
|
174
|
+
selectAreas(request: ServiceArea.SelectAreasRequest): MaybePromise<ServiceArea.SelectAreasResponse>;
|
|
175
|
+
skipArea(request: ServiceArea.SkipAreaRequest): MaybePromise<ServiceArea.SkipAreaResponse>;
|
|
176
|
+
}
|
|
177
|
+
export {};
|
|
178
|
+
//# sourceMappingURL=matterBehaviors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matterBehaviors.d.ts","sourceRoot":"","sources":["../../src/matter/matterBehaviors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,UAAU,EACV,cAAc,EACf,MAAM,uBAAuB,CAAA;AAE9B,OAAO,KAAK,EA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