UNPKG

matterbridge-hass

Version:
24 lines (23 loc) 914 B
import fs from 'node:fs'; import path from 'node:path'; export async function savePayload(platform) { const ha = platform.ha; const filename = path.join(platform.matterbridge.matterbridgePluginDirectory, 'matterbridge-hass', 'homeassistant.json'); const payload = { devices: Array.from(ha.hassDevices.values()), entities: Array.from(ha.hassEntities.values()), areas: Array.from(ha.hassAreas.values()), labels: Array.from(ha.hassLabels.values()), states: Array.from(ha.hassStates.values()), config: ha.hassConfig, services: ha.hassServices, }; try { await fs.promises.writeFile(filename, JSON.stringify(payload, null, 2)); platform.log.debug(`Payload successfully written to ${filename}`); return; } catch (error) { platform.log.error(`Error writing payload to file ${filename}: ${error}`); } }