@switchbot/homebridge-switchbot 4.1.8-beta.7 → 4.3.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.
Files changed (82) hide show
  1. package/.github/workflows/build.yml +1 -1
  2. package/CHANGELOG.md +18 -0
  3. package/config.schema.json +980 -106
  4. package/dist/device/blindtilt.js +1 -1
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.js +1 -1
  7. package/dist/device/bot.js.map +1 -1
  8. package/dist/device/ceilinglight.js +1 -1
  9. package/dist/device/ceilinglight.js.map +1 -1
  10. package/dist/device/colorbulb.js +1 -1
  11. package/dist/device/colorbulb.js.map +1 -1
  12. package/dist/device/contact.js +1 -1
  13. package/dist/device/contact.js.map +1 -1
  14. package/dist/device/curtain.js +1 -1
  15. package/dist/device/curtain.js.map +1 -1
  16. package/dist/device/device.d.ts.map +1 -1
  17. package/dist/device/device.js +19 -1
  18. package/dist/device/device.js.map +1 -1
  19. package/dist/device/fan.js +1 -1
  20. package/dist/device/fan.js.map +1 -1
  21. package/dist/device/hub.js +1 -1
  22. package/dist/device/hub.js.map +1 -1
  23. package/dist/device/humidifier.js +1 -1
  24. package/dist/device/humidifier.js.map +1 -1
  25. package/dist/device/iosensor.js +1 -1
  26. package/dist/device/iosensor.js.map +1 -1
  27. package/dist/device/lightstrip.js +1 -1
  28. package/dist/device/lightstrip.js.map +1 -1
  29. package/dist/device/lock.js +1 -1
  30. package/dist/device/lock.js.map +1 -1
  31. package/dist/device/meter.js +1 -1
  32. package/dist/device/meter.js.map +1 -1
  33. package/dist/device/meterplus.js +1 -1
  34. package/dist/device/meterplus.js.map +1 -1
  35. package/dist/device/meterpro.js +2 -2
  36. package/dist/device/meterpro.js.map +1 -1
  37. package/dist/device/motion.js +1 -1
  38. package/dist/device/motion.js.map +1 -1
  39. package/dist/device/plug.js +1 -1
  40. package/dist/device/plug.js.map +1 -1
  41. package/dist/device/relayswitch.d.ts +96 -0
  42. package/dist/device/relayswitch.d.ts.map +1 -0
  43. package/dist/device/relayswitch.js +650 -0
  44. package/dist/device/relayswitch.js.map +1 -0
  45. package/dist/device/robotvacuumcleaner.js +1 -1
  46. package/dist/device/robotvacuumcleaner.js.map +1 -1
  47. package/dist/device/waterdetector.js +1 -1
  48. package/dist/device/waterdetector.js.map +1 -1
  49. package/dist/platform.d.ts +1 -0
  50. package/dist/platform.d.ts.map +1 -1
  51. package/dist/platform.js +64 -0
  52. package/dist/platform.js.map +1 -1
  53. package/dist/settings.d.ts +12 -1
  54. package/dist/settings.d.ts.map +1 -1
  55. package/dist/settings.js +2 -0
  56. package/dist/settings.js.map +1 -1
  57. package/docs/functions/default.html +1 -1
  58. package/package.json +12 -12
  59. package/src/device/blindtilt.ts +2 -2
  60. package/src/device/bot.ts +1 -1
  61. package/src/device/ceilinglight.ts +1 -1
  62. package/src/device/colorbulb.ts +1 -1
  63. package/src/device/contact.ts +1 -1
  64. package/src/device/curtain.ts +2 -2
  65. package/src/device/device.ts +20 -1
  66. package/src/device/fan.ts +1 -1
  67. package/src/device/hub.ts +1 -1
  68. package/src/device/humidifier.ts +1 -1
  69. package/src/device/iosensor.ts +1 -1
  70. package/src/device/lightstrip.ts +1 -1
  71. package/src/device/lock.ts +1 -1
  72. package/src/device/meter.ts +1 -1
  73. package/src/device/meterplus.ts +1 -1
  74. package/src/device/meterpro.ts +2 -2
  75. package/src/device/motion.ts +1 -1
  76. package/src/device/plug.ts +1 -1
  77. package/src/device/relayswitch.ts +733 -0
  78. package/src/device/robotvacuumcleaner.ts +1 -1
  79. package/src/device/waterdetector.ts +1 -1
  80. package/src/platform.ts +68 -3
  81. package/src/settings.ts +14 -1
  82. package/.github/npm-version-script.cjs +0 -81
@@ -294,7 +294,7 @@ export class RobotVacuumCleaner extends deviceBase {
294
294
 
295
295
  async registerPlatformBLE(): Promise<void> {
296
296
  this.debugLog('registerPlatformBLE')
297
- if (this.config.options?.BLE) {
297
+ if (this.config.options?.BLE && !this.device.disablePlatformBLE) {
298
298
  this.debugLog('is listening to Platform BLE.')
299
299
  try {
300
300
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
@@ -288,7 +288,7 @@ export class WaterDetector extends deviceBase {
288
288
 
289
289
  async registerPlatformBLE(): Promise<void> {
290
290
  this.debugLog('registerPlatformBLE')
291
- if (this.config.options?.BLE) {
291
+ if (this.config.options?.BLE && !this.device.disablePlatformBLE) {
292
292
  this.debugLog('is listening to Platform BLE.')
293
293
  try {
294
294
  const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
package/src/platform.ts CHANGED
@@ -11,13 +11,12 @@ import type { MqttClient } from 'mqtt'
11
11
  * import type { blindTilt, curtain, curtain3, device, irdevice } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
12
12
  * import { LogLevel, SwitchBotBLE, SwitchBotModel, SwitchBotOpenAPI } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
13
13
  */
14
- import type { blindTilt, bodyChange, curtain, curtain3, device, deviceStatus, deviceStatusRequest, irdevice } from 'node-switchbot'
14
+ import type { blindTilt, bodyChange, curtain, curtain3, device, deviceStatusRequest, irdevice } from 'node-switchbot'
15
15
 
16
16
  import type { blindTiltConfig, curtainConfig, devicesConfig, irDevicesConfig, options, SwitchBotPlatformConfig } from './settings.js'
17
17
 
18
18
  import { readFileSync } from 'node:fs'
19
- import { hostname } from 'node:os'
20
- import process, { argv } from 'node:process'
19
+ import { argv } from 'node:process'
21
20
 
22
21
  import asyncmqtt from 'async-mqtt'
23
22
  import fakegato from 'fakegato-history'
@@ -42,6 +41,7 @@ import { MeterPlus } from './device/meterplus.js'
42
41
  import { MeterPro } from './device/meterpro.js'
43
42
  import { Motion } from './device/motion.js'
44
43
  import { Plug } from './device/plug.js'
44
+ import { RelaySwitch } from './device/relayswitch.js'
45
45
  import { RobotVacuumCleaner } from './device/robotvacuumcleaner.js'
46
46
  import { WaterDetector } from './device/waterdetector.js'
47
47
  import { AirConditioner } from './irdevice/airconditioner.js'
@@ -586,6 +586,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
586
586
  'Humidifier2': this.createHumidifier.bind(this),
587
587
  'Hub 2': this.createHub2.bind(this),
588
588
  'Bot': this.createBot.bind(this),
589
+ 'Relay Switch 1': this.createRelaySwitch.bind(this),
590
+ 'Relay Switch 1PM': this.createRelaySwitch.bind(this),
589
591
  'Meter': this.createMeter.bind(this),
590
592
  'MeterPlus': this.createMeterPlus.bind(this),
591
593
  'Meter Plus (JP)': this.createMeterPlus.bind(this),
@@ -796,6 +798,69 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
796
798
  }
797
799
  }
798
800
 
801
+ private async createRelaySwitch(device: device & devicesConfig) {
802
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
803
+
804
+ // see if an accessory with the same uuid has already been registered and restored from
805
+ // the cached devices we stored in the `configureAccessory` method above
806
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
807
+
808
+ if (existingAccessory) {
809
+ // the accessory already exists
810
+ if (await this.registerDevice(device)) {
811
+ // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
812
+ existingAccessory.context.device = device
813
+ existingAccessory.context.deviceId = device.deviceId
814
+ existingAccessory.context.deviceType = device.deviceType
815
+ existingAccessory.context.model = device.deviceType === 'Relay Switch 1' ? SwitchBotModel.RelaySwitch1 : SwitchBotModel.RelaySwitch1PM
816
+ existingAccessory.displayName = device.configDeviceName
817
+ ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
818
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
819
+ existingAccessory.context.connectionType = await this.connectionType(device)
820
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
821
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
822
+ this.api.updatePlatformAccessories([existingAccessory])
823
+ // create the accessory handler for the restored accessory
824
+ // this is imported from `platformAccessory.ts`
825
+ new RelaySwitch(this, existingAccessory, device)
826
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
827
+ } else {
828
+ this.unregisterPlatformAccessories(existingAccessory)
829
+ }
830
+ } else if (await this.registerDevice(device)) {
831
+ // create a new accessory
832
+ const accessory = new this.api.platformAccessory(device.configDeviceName
833
+ ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
834
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
835
+
836
+ // store a copy of the device object in the `accessory.context`
837
+ // the `context` property can be used to store any data about the accessory you may need
838
+ accessory.context.device = device
839
+ accessory.context.deviceId = device.deviceId
840
+ accessory.context.deviceType = device.deviceType
841
+ accessory.context.model = device.deviceType === 'Relay Switch 1' ? SwitchBotModel.RelaySwitch1 : SwitchBotModel.RelaySwitch1PM
842
+ accessory.displayName = device.configDeviceName
843
+ ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
844
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
845
+ accessory.context.connectionType = await this.connectionType(device)
846
+ accessory.context.connectionType = await this.connectionType(device)
847
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
848
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
849
+ this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
850
+ // accessory.context.version = findaccessories.accessoryAttribute.softwareRevision;
851
+ // create the accessory handler for the newly create accessory
852
+ // this is imported from `platformAccessory.ts`
853
+ new RelaySwitch(this, accessory, device)
854
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
855
+
856
+ // publish device externally or link the accessory to your platform
857
+ this.externalOrPlatform(device, accessory)
858
+ this.accessories.push(accessory)
859
+ } else {
860
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
861
+ }
862
+ }
863
+
799
864
  private async createMeter(device: device & devicesConfig) {
800
865
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
801
866
 
package/src/settings.ts CHANGED
@@ -53,7 +53,7 @@ export interface options {
53
53
  logging?: string
54
54
  };
55
55
 
56
- export type devicesConfig = botConfig | meterConfig | meterProConfig | indoorOutdoorSensorConfig | humidifierConfig | curtainConfig | blindTiltConfig | contactConfig | motionConfig | waterDetectorConfig | plugConfig | colorBulbConfig | stripLightConfig | ceilingLightConfig | lockConfig | hubConfig
56
+ export type devicesConfig = botConfig | relaySwitch1Config | relaySwitch1PMConfig | meterConfig | meterProConfig | indoorOutdoorSensorConfig | humidifierConfig | curtainConfig | blindTiltConfig | contactConfig | motionConfig | waterDetectorConfig | plugConfig | colorBulbConfig | stripLightConfig | ceilingLightConfig | lockConfig | hubConfig
57
57
 
58
58
  export interface BaseDeviceConfig extends device {
59
59
  bleMac?: string
@@ -79,6 +79,7 @@ export interface BaseDeviceConfig extends device {
79
79
  maxRetries?: number
80
80
  delayBetweenRetries?: number
81
81
  disableCaching?: boolean
82
+ disablePlatformBLE?: boolean
82
83
  mqttURL?: string
83
84
  mqttOptions?: IClientOptions
84
85
  mqttPubOptions?: IClientOptions
@@ -96,6 +97,18 @@ export interface botConfig extends BaseDeviceConfig {
96
97
  multiPress?: boolean
97
98
  };
98
99
 
100
+ export interface relaySwitch1Config extends BaseDeviceConfig {
101
+ configDeviceType: 'Relay Switch 1'
102
+ type: string
103
+ allowPush?: boolean
104
+ };
105
+
106
+ export interface relaySwitch1PMConfig extends BaseDeviceConfig {
107
+ configDeviceType: 'Relay Switch 1PM'
108
+ type: string
109
+ allowPush?: boolean
110
+ };
111
+
99
112
  export interface meterConfig extends BaseDeviceConfig {
100
113
  configDeviceType: 'Meter' | 'MeterPlus'
101
114
  hide_temperature?: boolean
@@ -1,81 +0,0 @@
1
- #!/bin/env node
2
-
3
- /**
4
- * This scripts queries the npm registry to pull out the latest version for a given tag.
5
- */
6
-
7
- const fs = require("fs");
8
- const semver = require("semver");
9
- const child_process = require("child_process");
10
- const assert = require("assert");
11
-
12
- const BRANCH_VERSION_PATTERN = /^([A-Za-z]*)-(\d+.\d+.\d+)$/
13
-
14
- // Load the contents of the package.json file
15
- const packageJSON = JSON.parse(fs.readFileSync("package.json", "utf8"));
16
-
17
- let refArgument = process.argv[2];
18
- let tagArgument = process.argv[3] || "latest";
19
-
20
- if (refArgument == null) {
21
- console.error("ref argument is missing");
22
- console.error("Usage: npm-version-script.cjs <ref> [tag]");
23
- process.exit(1);
24
- }
25
-
26
- /**
27
- * Queries the NPM registry for the latest version for the provided tag.
28
- * @param tag The tag to query for.
29
- * @returns {string} Returns the version.
30
- */
31
- function getTagVersionFromNpm(tag) {
32
- try {
33
- return child_process.execSync(`npm info ${packageJSON.name} version --tag="${tag}"`).toString("utf8").trim();
34
- } catch (e) {
35
- throw e;
36
- }
37
- }
38
-
39
- function desiredTargetVersion(ref) {
40
- // ref is a GitHub action ref string
41
- if (ref.startsWith("refs/pull/")) {
42
- throw Error("The version script was executed inside a PR!");
43
- }
44
-
45
- assert(ref.startsWith("refs/heads/"))
46
- let branchName = ref.slice("refs/heads/".length);
47
-
48
- let results = branchName.match(BRANCH_VERSION_PATTERN);
49
- if (results != null) {
50
- if (results[1] !== tagArgument) {
51
- console.warn(`The base branch name (${results[1]}) differs from the tag name ${tagArgument}`);
52
- }
53
-
54
- return results[2];
55
- }
56
-
57
- // legacy mode were we use the `betaVersion` property in the package.json
58
- if (branchName === "beta" && packageJSON.betaVersion) {
59
- return packageJSON.betaVersion
60
- }
61
-
62
- throw new Error("Malformed branch name for ref: " + ref + ". Can't derive the base version. Use a branch name like: beta-x.x.x!");
63
- }
64
-
65
- // derive the base version from the branch ref
66
- const baseVersion = desiredTargetVersion(refArgument);
67
-
68
- // query the npm registry for the latest version of the provided tag name
69
- const latestReleasedVersion = getTagVersionFromNpm(tagArgument); // e.g. 0.7.0-beta.12
70
- const latestReleaseBase = semver.inc(latestReleasedVersion, "patch"); // will produce 0.7.0 (removing the preid, needed for the equality check below)
71
-
72
- let publishTag;
73
- if (semver.eq(baseVersion, latestReleaseBase)) { // check if we are releasing another version for the latest beta
74
- publishTag = latestReleasedVersion; // set the current latest beta to be incremented
75
- } else {
76
- publishTag = baseVersion; // start of with a new beta version
77
- }
78
-
79
- // save the package.json
80
- packageJSON.version = publishTag;
81
- fs.writeFileSync("package.json", JSON.stringify(packageJSON, null, 2));