Skip to content

Commit

Permalink
Fix ./persist folder not created.
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5e committed Nov 12, 2022
1 parent 757bc8f commit 1d9bc8d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/platform.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service, Characteristic } from 'homebridge';
import { Validator } from 'jsonschema';
import path from 'path';
import fs from 'fs/promises';
import fs from 'fs';

import TuyaDevice, { TuyaDeviceStatus } from './device/TuyaDevice';
import TuyaDeviceManager from './device/TuyaDeviceManager';
Expand Down Expand Up @@ -106,7 +106,10 @@ export class TuyaPlatform implements DynamicPlatformPlugin {
this.log.info(`Got ${devices.length} device(s).`);
const file = path.join(this.api.user.persistPath(), `TuyaDeviceList.${this.deviceManager!.api.tokenInfo.uid}.json`);
this.log.info('Device list saved at %s', file);
await fs.writeFile(file, JSON.stringify(devices, null, 2));
if (!fs.existsSync(this.api.user.persistPath())) {
await fs.promises.mkdir(this.api.user.persistPath());
}
await fs.promises.writeFile(file, JSON.stringify(devices, null, 2));

// add accessories
for (const device of devices) {
Expand Down

0 comments on commit 1d9bc8d

Please sign in to comment.