forked from pgerke/homebridge-freeathome-local-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreeAtHomeContext.ts
43 lines (40 loc) · 1.13 KB
/
freeAtHomeContext.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import {
Channel,
Device,
isChannel,
isDevice,
Logger,
} from "freeathome-local-api-client";
import {
PlatformAccessory,
UnknownContext,
} from "homebridge/lib/platformAccessory";
/** Describes the context of a free@home accessory. */
export interface FreeAtHomeContext {
channel: Channel;
channelId: string;
deviceSerial: string;
device: Device;
}
/**
* Determines whether the specified accessory is a free@home accessory.
* @param accessory The accessory to be tested
* @param logger {Logger} The logger instance to be used.
* @returns {boolean} A value indicating whether the specified object is a free@home accessory.
*/
export function isFreeAtHomeAccessory(
accessory: PlatformAccessory<UnknownContext>,
logger: Logger
): accessory is PlatformAccessory<FreeAtHomeContext> {
const keys = Object.keys(accessory.context);
const hasKeys =
keys.includes("device") &&
keys.includes("deviceSerial") &&
keys.includes("channel") &&
keys.includes("channelId");
return (
hasKeys &&
isChannel(accessory.context.channel, logger) &&
isDevice(accessory.context.device, logger)
);
}