@switchbot/homebridge-switchbot 2.4.1-beta.6 → 2.4.1-beta.7

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/src/platform.ts CHANGED
@@ -16,6 +16,7 @@ import { Fan } from './irdevice/fan';
16
16
  import { Light } from './irdevice/light';
17
17
  import { Others } from './irdevice/other';
18
18
  import { Camera } from './irdevice/camera';
19
+ import { BlindTilt } from './device/blindtilt';
19
20
  import { AirPurifier } from './irdevice/airpurifier';
20
21
  import { WaterHeater } from './irdevice/waterheater';
21
22
  import { VacuumCleaner } from './irdevice/vacuumcleaner';
@@ -434,6 +435,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
434
435
  this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
435
436
  this.createCurtain(device);
436
437
  break;
438
+ case 'Blind Tilt':
439
+ this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
440
+ this.createBlindTilt(device);
441
+ break;
437
442
  case 'Plug':
438
443
  case 'Plug Mini (US)':
439
444
  case 'Plug Mini (JP)':
@@ -885,6 +890,73 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
885
890
  }
886
891
  }
887
892
 
893
+ private async createBlindTilt(device: device & devicesConfig) {
894
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
895
+
896
+ // see if an accessory with the same uuid has already been registered and restored from
897
+ // the cached devices we stored in the `configureAccessory` method above
898
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
899
+
900
+ if (existingAccessory) {
901
+ // the accessory already exists
902
+ if (await this.registerDevice(device)) {
903
+ // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
904
+ existingAccessory.context.model = device.deviceType;
905
+ existingAccessory.context.deviceID = device.deviceId;
906
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
907
+ existingAccessory.context.firmwareRevision = device.firmware;
908
+ existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
909
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
910
+ existingAccessory.context.connectionType = await this.connectionType(device);
911
+ this.api.updatePlatformAccessories([existingAccessory]);
912
+ // create the accessory handler for the restored accessory
913
+ // this is imported from `platformAccessory.ts`
914
+ new BlindTilt(this, existingAccessory, device);
915
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
916
+ } else {
917
+ this.unregisterPlatformAccessories(existingAccessory);
918
+ }
919
+ } else if (await this.registerDevice(device)) {
920
+ // the accessory does not yet exist, so we need to create it
921
+ if (!device.external) {
922
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
923
+ }
924
+
925
+ if (device.group && !device.curtain?.disable_group) {
926
+ this.debugLog('Your Curtains are grouped, '
927
+ + `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
928
+ } else {
929
+ if (device.master) {
930
+ this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
931
+ } else {
932
+ this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
933
+ }
934
+ }
935
+
936
+ // create a new accessory
937
+ const accessory = new this.api.platformAccessory(device.deviceName, uuid);
938
+
939
+ // store a copy of the device object in the `accessory.context`
940
+ // the `context` property can be used to store any data about the accessory you may need
941
+ accessory.context.device = device;
942
+ accessory.context.model = device.deviceType;
943
+ accessory.context.deviceID = device.deviceId;
944
+ accessory.context.firmwareRevision = device.firmware;
945
+ accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
946
+ accessory.context.connectionType = await this.connectionType(device);
947
+ // create the accessory handler for the newly create accessory
948
+ // this is imported from `platformAccessory.ts`
949
+ new BlindTilt(this, accessory, device);
950
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
951
+
952
+ // publish device externally or link the accessory to your platform
953
+ this.externalOrPlatform(device, accessory);
954
+ this.accessories.push(accessory);
955
+ } else {
956
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
957
+ }
958
+ }
959
+
888
960
  private async createCurtain(device: device & devicesConfig) {
889
961
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
890
962
 
@@ -1787,36 +1859,42 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1787
1859
  }
1788
1860
 
1789
1861
  async registerCurtains(device: device & devicesConfig) {
1790
- this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: ` +
1791
- `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
1862
+ if (device.deviceType === 'Curtain') {
1863
+ this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: `
1864
+ + `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
1865
+ } else {
1866
+ this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds}, master: `
1867
+ + `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
1868
+ }
1792
1869
 
1793
1870
  let registerCurtain: boolean;
1794
1871
  if (device.master && device.group) {
1795
- // OpenAPI: Master Curtains in Group
1872
+ // OpenAPI: Master Curtains/Blind Tilt in Group
1796
1873
  registerCurtain = true;
1797
- this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] device.master: ${device.master}, device.group: ${device.group}`
1874
+ this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, device.group: ${device.group}`
1798
1875
  + ` connectionType; ${device.connectionType}`);
1799
1876
  this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1800
1877
  } else if (!device.master && device.curtain?.disable_group) { //!device.group && device.connectionType === 'BLE'
1801
- // OpenAPI: Non-Master Curtain that has Disable Grouping Checked
1878
+ // OpenAPI: Non-Master Curtains/Blind Tilts that has Disable Grouping Checked
1802
1879
  registerCurtain = true;
1803
- this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] device.master: ${device.master}, disable_group: `
1880
+ this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: `
1804
1881
  + `${device.curtain?.disable_group}, connectionType; ${device.connectionType}`);
1805
1882
  this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1806
1883
  } else if (device.master && !device.group) {
1807
- // OpenAPI: Master Curtains not in Group
1884
+ // OpenAPI: Master Curtains/Blind Tilts not in Group
1808
1885
  registerCurtain = true;
1809
- this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] device.master: ${device.master}, device.group: ${device.group}`
1886
+ this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, device.group: ${device.group}`
1810
1887
  + ` connectionType; ${device.connectionType}`);
1811
1888
  this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1812
1889
  } else if (device.connectionType === 'BLE') {
1813
- // BLE: Curtains
1890
+ // BLE: Curtains/Blind Tilt
1814
1891
  registerCurtain = true;
1815
- this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] connectionType: ${device.connectionType}, group: ${device.group}`);
1892
+ this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, `
1893
+ + ` group: ${device.group}`);
1816
1894
  this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
1817
1895
  } else {
1818
1896
  registerCurtain = false;
1819
- this.debugErrorLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group},`
1897
+ this.debugErrorLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.curtain?.disable_group},`
1820
1898
  + ` device.master: ${device.master}, device.group: ${device.group}`);
1821
1899
  this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}, device.connectionType: ${device.connectionType}`);
1822
1900
  }
@@ -1837,9 +1915,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1837
1915
  device.connectionType = await this.connectionType(device);
1838
1916
  let registerDevice: boolean;
1839
1917
  if (!device.hide_device && device.connectionType === 'BLE/OpenAPI') {
1840
- if (device.deviceType === 'Curtain') {
1918
+ if (device.deviceType === 'Curtain' || device.deviceType === 'Blind Tilt') {
1841
1919
  registerDevice = await this.registerCurtains(device);
1842
- this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1920
+ this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
1843
1921
  } else {
1844
1922
  registerDevice = true;
1845
1923
  this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
@@ -1847,27 +1925,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1847
1925
  this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1848
1926
  } else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName
1849
1927
  && device.connectionType === 'BLE') {
1850
- if (device.deviceType === 'Curtain') {
1928
+ if (device.deviceType === 'Curtain' || device.deviceType === 'Blind Tilt') {
1851
1929
  registerDevice = await this.registerCurtains(device);
1852
- this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1930
+ this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
1853
1931
  } else {
1854
1932
  registerDevice = true;
1855
1933
  this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1856
1934
  }
1857
1935
  this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1858
1936
  } else if (!device.hide_device && device.connectionType === 'OpenAPI') {
1859
- if (device.deviceType === 'Curtain') {
1937
+ if (device.deviceType === 'Curtain' || device.deviceType === 'Blind Tilt') {
1860
1938
  registerDevice = await this.registerCurtains(device);
1861
- this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1939
+ this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
1862
1940
  } else {
1863
1941
  registerDevice = true;
1864
1942
  this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
1865
1943
  }
1866
1944
  this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
1867
1945
  } else if (!device.hide_device && device.connectionType === 'Disabled') {
1868
- if (device.deviceType === 'Curtain') {
1946
+ if (device.deviceType === 'Curtain' || device.deviceType === 'Blind Tilt') {
1869
1947
  registerDevice = await this.registerCurtains(device);
1870
- this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
1948
+ this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
1871
1949
  } else {
1872
1950
  registerDevice = true;
1873
1951
  this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
package/src/settings.ts CHANGED
@@ -196,6 +196,8 @@ export type device = {
196
196
  hubDeviceId: string;
197
197
  //only available for Curtain devices. a list of Curtain device IDs such that the Curtain devices are being paired or grouped.
198
198
  curtainDevicesIds?: Array<string>;
199
+ //only available for Blind Titl devices. a list of Blind Tilt device IDs such that the Blind Tilt devices are being paired or grouped.
200
+ blindTiltDevicesIds?: Array<string>;
199
201
  //only available for Curtain/Lock devices. determines if the open position and the close position of a device have been properly calibrated or not
200
202
  calibrate?: boolean;
201
203
  //only available for Curtain devices. determines if a Curtain is paired with or grouped with another Curtain or not.
@@ -204,6 +206,12 @@ export type device = {
204
206
  master?: boolean;
205
207
  //only available for Curtain devices. the opening direction of a Curtain.
206
208
  openDirection?: string;
209
+ //the opening direction of a Blind Tilt device
210
+ direction?: string;
211
+ //the current position, 0-100
212
+ slidePosition?: string;
213
+ //the version of the device
214
+ version?: number;
207
215
  //BLE Mac Address
208
216
  bleMac?: string;
209
217
  };