homebridge-bedjet 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,44 @@
1
+ import { OperatingMode } from './constants';
2
+
3
+ export interface BedJetState {
4
+ currentTemperature: number; // Celsius
5
+ targetTemperature: number; // Celsius
6
+ operatingMode: OperatingMode;
7
+ fanSpeed: number; // percent 5–100
8
+ minimumTemperature: number; // Celsius
9
+ maximumTemperature: number; // Celsius
10
+ ambientTemperature: number; // Celsius
11
+ hoursRemaining: number;
12
+ minutesRemaining: number;
13
+ secondsRemaining: number;
14
+ turboTimeSeconds: number;
15
+ isConnected: boolean;
16
+ // from direct status read — undefined until first read
17
+ isDualZone?: boolean;
18
+ ledEnabled?: boolean;
19
+ beepsMuted?: boolean;
20
+ connTestPassed?: boolean;
21
+ unitsSetup?: boolean;
22
+ notificationCode?: number;
23
+ }
24
+
25
+ export interface BedJetConfig {
26
+ name: string;
27
+ address: string; // BLE MAC e.g. "AA:BB:CC:DD:EE:FF"
28
+ scanTimeout?: number; // seconds (default 30)
29
+ }
30
+
31
+ export const DEFAULT_STATE: BedJetState = {
32
+ currentTemperature: 20,
33
+ targetTemperature: 28,
34
+ operatingMode: OperatingMode.STANDBY,
35
+ fanSpeed: 50,
36
+ minimumTemperature: 19,
37
+ maximumTemperature: 43,
38
+ ambientTemperature: 20,
39
+ hoursRemaining: 0,
40
+ minutesRemaining: 0,
41
+ secondsRemaining: 0,
42
+ turboTimeSeconds: 0,
43
+ isConnected: false,
44
+ };
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { API } from 'homebridge';
2
+ import { BedJetPlatform, PLATFORM_NAME, PLUGIN_NAME } from './platform';
3
+
4
+ export = (api: API) => {
5
+ api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, BedJetPlatform);
6
+ };
@@ -0,0 +1,71 @@
1
+ import type { API, DynamicPlatformPlugin, Logging, PlatformAccessory, PlatformConfig } from 'homebridge';
2
+ import { BedJetAccessory } from './accessory';
3
+ import type { BedJetConfig } from './bedjet/types';
4
+
5
+ export const PLATFORM_NAME = 'BedJetPlatform';
6
+ export const PLUGIN_NAME = 'homebridge-bedjet';
7
+
8
+ export class BedJetPlatform implements DynamicPlatformPlugin {
9
+ private readonly accessories: Map<string, PlatformAccessory> = new Map();
10
+ private readonly discoveredUUIDs: string[] = [];
11
+
12
+ constructor(
13
+ public readonly log: Logging,
14
+ public readonly config: PlatformConfig,
15
+ public readonly api: API,
16
+ ) {
17
+ this.log.debug('BedJetPlatform initializing');
18
+
19
+ this.api.on('didFinishLaunching', () => {
20
+ this.log.debug('didFinishLaunching');
21
+ this.discoverDevices();
22
+ });
23
+ }
24
+
25
+ configureAccessory(accessory: PlatformAccessory): void {
26
+ this.log.info('Loading accessory from cache:', accessory.displayName);
27
+ this.accessories.set(accessory.UUID, accessory);
28
+ }
29
+
30
+ private discoverDevices(): void {
31
+ const devices: BedJetConfig[] = this.config['devices'] ?? [];
32
+
33
+ if (devices.length === 0) {
34
+ this.log.warn('No BedJet devices configured. Add at least one device in the plugin settings.');
35
+ return;
36
+ }
37
+
38
+ for (const device of devices) {
39
+ if (!device.address) {
40
+ this.log.warn(`Skipping device "${device.name}" — no address configured`);
41
+ continue;
42
+ }
43
+
44
+ const uuid = this.api.hap.uuid.generate(device.address.toLowerCase());
45
+ this.discoveredUUIDs.push(uuid);
46
+
47
+ const existing = this.accessories.get(uuid);
48
+
49
+ if (existing) {
50
+ this.log.info('Restoring existing accessory from cache:', existing.displayName);
51
+ existing.context.device = device;
52
+ this.api.updatePlatformAccessories([existing]);
53
+ new BedJetAccessory(this, existing, device);
54
+ } else {
55
+ this.log.info('Adding new accessory:', device.name);
56
+ const accessory = new this.api.platformAccessory(device.name, uuid);
57
+ accessory.context.device = device;
58
+ new BedJetAccessory(this, accessory, device);
59
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
60
+ }
61
+ }
62
+
63
+ // Remove accessories that are no longer in the config
64
+ for (const [uuid, accessory] of this.accessories) {
65
+ if (!this.discoveredUUIDs.includes(uuid)) {
66
+ this.log.info('Removing stale accessory from cache:', accessory.displayName);
67
+ this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
68
+ }
69
+ }
70
+ }
71
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": ["ES2020"],
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "declaration": true,
13
+ "sourceMap": true
14
+ },
15
+ "include": ["src/**/*"],
16
+ "exclude": ["node_modules", "dist"]
17
+ }