Add support for pushing things to OpenHAB
This commit is contained in:
@@ -21,10 +21,6 @@ export const importThings = async (config: Config, options: ImportOptions) => {
|
|||||||
return new constructor(source, cfg).loadThings();
|
return new constructor(source, cfg).loadThings();
|
||||||
}))).flat();
|
}))).flat();
|
||||||
|
|
||||||
if (options.force) {
|
|
||||||
await openhab.deleteThings(...things.map(t => t.UID));
|
|
||||||
}
|
|
||||||
|
|
||||||
const existingThings = await openhab.getThings();
|
const existingThings = await openhab.getThings();
|
||||||
const existingThingsUIDs = existingThings.map(t => t.UID);
|
const existingThingsUIDs = existingThings.map(t => t.UID);
|
||||||
|
|
||||||
@@ -36,6 +32,11 @@ export const importThings = async (config: Config, options: ImportOptions) => {
|
|||||||
.filter(t => !existingThingsUIDs.includes(t.UID))
|
.filter(t => !existingThingsUIDs.includes(t.UID))
|
||||||
.filter(filter);
|
.filter(filter);
|
||||||
|
|
||||||
|
if (options.force) {
|
||||||
|
await openhab.deleteThings(...thingsToImport.map(t => t.UID));
|
||||||
|
}
|
||||||
|
|
||||||
|
await openhab.createThings(...thingsToImport);
|
||||||
|
|
||||||
return thingsToImport;
|
return thingsToImport;
|
||||||
}
|
}
|
||||||
@@ -28,8 +28,8 @@ export class OpenHAB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createThings(...things: Thing[]): Promise<Thing[]> {
|
async createThings(...things: Thing[]): Promise<Thing[]> {
|
||||||
const response = await this.#api.post<Thing[]>('/things');
|
const responses = await Promise.all(things.map(thing => this.#api.post<Thing>('/things', thing)));
|
||||||
return response.data;
|
return responses.map(r => r.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user