From 02da09b54c79c346732831d20e9d765db5e17e54 Mon Sep 17 00:00:00 2001 From: Adam Wychowaniec Date: Mon, 25 Dec 2023 09:44:52 +0100 Subject: [PATCH] Update `vastra-radiator-valve` to `1.2.1` --- .npmignore | 3 +++ .vscode/settings.json | 6 +++--- package.json | 4 ++-- src/platform.ts | 26 +++++++++----------------- yarn.lock | 8 ++++---- 5 files changed, 21 insertions(+), 26 deletions(-) diff --git a/.npmignore b/.npmignore index 4b55a2a..856fe2b 100644 --- a/.npmignore +++ b/.npmignore @@ -132,3 +132,6 @@ web_modules/ .yarn/unplugged .yarn/build-state.yml .pnp.* + +dist/fake-bluetooth.* +src/snapshot.bin \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 31b20d1..3ccc820 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,8 @@ { "files.eol": "\n", "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" }, - "editor.rulers": [ 140 ], + "editor.rulers": [140], "eslint.enable": true -} \ No newline at end of file +} diff --git a/package.json b/package.json index cda47fc..9d4edcf 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "Vastra Radiator Valve", "name": "homebridge-vastra-radiator-valve", - "version": "1.0.2", + "version": "1.2.0", "description": "Homebridge integration for Vastra's radiator valves", "license": "MIT", "author": { @@ -30,7 +30,7 @@ "homebridge-plugin" ], "dependencies": { - "vastra-radiator-valve": "^1.1.1" + "vastra-radiator-valve": "^1.2.1" }, "devDependencies": { "@types/node": "^18.16.20", diff --git a/src/platform.ts b/src/platform.ts index fd517ea..ccc368b 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -10,8 +10,7 @@ import { } from "homebridge"; import { NobleBluetoothCentral, - RadiatorValves, - Logger as VastraLogger, + RadiatorValveScanner, } from "vastra-radiator-valve"; import { VastraRadiatorValvePlatformAccessory } from "./radiatorValveAccessory"; import { PLATFORM_NAME, PLUGIN_NAME } from "./settings"; @@ -23,7 +22,7 @@ export class VastraRadiatorValveHomebridgePlugin public readonly Characteristic: typeof Characteristic = this.api.hap.Characteristic; - private radiatorValves?: RadiatorValves; + private scanner?: RadiatorValveScanner; public readonly accessories: VastraRadiatorValvePlatformAccessory[] = []; @@ -37,7 +36,7 @@ export class VastraRadiatorValveHomebridgePlugin }); this.api.on("shutdown", () => { - this.radiatorValves?.dispose(); + this.scanner?.disconnectAll(); }); } @@ -49,21 +48,12 @@ export class VastraRadiatorValveHomebridgePlugin } startDiscovering() { - this.radiatorValves = new RadiatorValves(new NobleBluetoothCentral(), { - logger: new VastraLogger(false), + this.scanner = new RadiatorValveScanner(new NobleBluetoothCentral(), { + verbose: false, raspberryFix: true, }); - this.radiatorValves.startScanning(async (valve) => { - try { - await valve.connect(); - } catch (error) { - this.log.error( - `Failed to open connection to ${valve.peripheral.address}.`, - error - ); - return; - } + this.scanner.on("connected", async (valve) => { const uuid = this.api.hap.uuid.generate(valve.peripheral.address); const existingAccessory = this.accessories.find( (accessory) => accessory.accessory.UUID === uuid @@ -78,7 +68,7 @@ export class VastraRadiatorValveHomebridgePlugin uuid, Categories.THERMOSTAT ); - accessory.context.serialNumber = valve.getSerialNumber(); + accessory.context.serialNumber = await valve.getSerialNumber(); accessory.context.address = valve.peripheral.address; this.accessories.push( @@ -90,5 +80,7 @@ export class VastraRadiatorValveHomebridgePlugin ]); } }); + + this.scanner.start(); } } diff --git a/yarn.lock b/yarn.lock index 495c780..eb7d414 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2043,10 +2043,10 @@ v8-compile-cache-lib@^3.0.1: resolved "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz" integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg== -vastra-radiator-valve@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/vastra-radiator-valve/-/vastra-radiator-valve-1.1.1.tgz#7ed5414a526dbf2925c9550b5fe90b12742afbeb" - integrity sha512-e/uP7jZuaB+GU2495cSZ8HiGEabsBz0Mh/5fVI1WW5PXhoDd8mGHpuZrnhAsJAZEL4jK1LqZHSDVJ7BULGcMcA== +vastra-radiator-valve@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/vastra-radiator-valve/-/vastra-radiator-valve-1.2.1.tgz#6169f82289b596c6e365a6472a76981deb78811b" + integrity sha512-LTNcXAb4t3A8FXyXBdElMuL60dzs2JuOATfJeWETREVS3pJ7wj4rtCaJNvBpzBSpZSekLb7zzRB6pGTuDvZbHA== dependencies: "@abandonware/noble" "^1.9.2-23"