@camstack/addon-provider-homeassistant 1.2.172 → 1.2.601

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/dist/addon.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_dist = require("./dist-Ba9raKow.js");
2
+ const require_dist = require("./dist-BXMUyWXo.js");
3
3
  let node_crypto = require("node:crypto");
4
4
  let node_zlib = require("node:zlib");
5
5
  //#region src/ha-admin-link.ts
@@ -1592,6 +1592,7 @@ var COLD_START$15 = {
1592
1592
  * - `target_temp_high` / `target_temp_low` → `targetHigh` / `targetLow`
1593
1593
  * - `target_humidity` → `targetHumidity`
1594
1594
  * - `current_temperature` / `current_humidity` → read-only
1595
+ * - `min_temp` / `max_temp` / `target_temp_step` → setpoint bounds
1595
1596
  *
1596
1597
  * Mutations route to:
1597
1598
  * - `climate.set_hvac_mode({ hvac_mode })`
@@ -1691,6 +1692,9 @@ function climateSliceFromState(state) {
1691
1692
  currentTemp: readNumberAttr$5(attrs, "current_temperature"),
1692
1693
  currentHumidity: readNumberAttr$5(attrs, "current_humidity"),
1693
1694
  ...readSwing(attrs),
1695
+ minTemp: readNumberAttr$5(attrs, "min_temp"),
1696
+ maxTemp: readNumberAttr$5(attrs, "max_temp"),
1697
+ tempStep: readNumberAttr$5(attrs, "target_temp_step"),
1694
1698
  lastFetchedAt
1695
1699
  };
1696
1700
  }
@@ -5805,7 +5809,7 @@ function mapHaEntityToCamStack(input) {
5805
5809
  switch (domain) {
5806
5810
  case "switch": return {
5807
5811
  deviceType: require_dist.DeviceType.Switch,
5808
- role: null,
5812
+ role: deviceClass === "outlet" ? require_dist.DeviceRole.Outlet : null,
5809
5813
  capabilities: ["switch"]
5810
5814
  };
5811
5815
  case "input_boolean": return {
@@ -6779,6 +6783,54 @@ function createHaIconRouteProvider() {
6779
6783
  }]);
6780
6784
  }
6781
6785
  //#endregion
6786
+ //#region src/broker-record-kinds.ts
6787
+ /**
6788
+ * Broker entry kind (B2): credentials live in records; integrations keep brokerId.
6789
+ */
6790
+ var HA_BROKERS_KIND = "brokers";
6791
+ var HA_BROKERS_OWNER = "provider-homeassistant";
6792
+ var HaBrokerBodySchema = require_dist.entryBody({
6793
+ auth: HaBrokerEntrySchema.shape.auth,
6794
+ integrationId: require_dist.string().optional()
6795
+ });
6796
+ var haBrokersEntryKind = require_dist.defineEntryKind(HA_BROKERS_KIND, {
6797
+ title: "Home Assistant brokers",
6798
+ schema: HaBrokerBodySchema,
6799
+ writeTrigger: "an operator adds, edits or removes a Home Assistant broker connection",
6800
+ adoptsFrom: require_dist.settingsBrokersAdoptsFrom(HA_BROKERS_OWNER)
6801
+ });
6802
+ //#endregion
6803
+ //#region src/record-kinds.ts
6804
+ /**
6805
+ * Body of one stored HA notification target. The record id IS the target id
6806
+ * and is not repeated in the body.
6807
+ * No `.meta({ secret: true })` fields: HA notify targets carry no standalone
6808
+ * credential — delivery reuses the broker WebSocket connection (the token
6809
+ * lives in the broker config, not in the target).
6810
+ */
6811
+ var HaTargetBodySchema = require_dist.TargetSchema.omit({ id: true });
6812
+ var haRecordKinds = require_dist.defineRecordKinds({
6813
+ /**
6814
+ * One row per configured Home Assistant push target. Operator-managed via the
6815
+ * notification-output cap CRUD; no TTL.
6816
+ * The legacy collection name is `provider-homeassistant:ha-notification-targets`.
6817
+ */
6818
+ "ha-notification-targets": {
6819
+ schema: HaTargetBodySchema,
6820
+ class: "config",
6821
+ writeTrigger: "an operator creates, updates, enables/disables or deletes a HA notification target",
6822
+ device: "none",
6823
+ at: "none",
6824
+ retention: { none: "a row is removed only on an explicit operator delete; bounded by the number of HA notify targets the operator configures" },
6825
+ adoptsFrom: "provider-homeassistant:ha-notification-targets",
6826
+ entry: { title: "Home Assistant notification targets" }
6827
+ } });
6828
+ /** All record kinds this addon declares (targets + B2 broker entries). */
6829
+ var haAllRecordKinds = {
6830
+ ...haRecordKinds,
6831
+ [haBrokersEntryKind.name]: haBrokersEntryKind
6832
+ };
6833
+ //#endregion
6782
6834
  //#region src/ha-notification-output.ts
6783
6835
  /**
6784
6836
  * `homeassistant` notification-output kind — hosted BY the HA provider addon.
@@ -6812,8 +6864,6 @@ function createHaIconRouteProvider() {
6812
6864
  */
6813
6865
  /** The single kind this provider contributes to the shared catalog. */
6814
6866
  var HA_NOTIFICATION_KIND = "homeassistant";
6815
- /** addonId-namespaced settings-store collection holding HA notify targets. */
6816
- var HA_TARGETS_COLLECTION = "provider-homeassistant:ha-notification-targets";
6817
6867
  function haConfigSchema() {
6818
6868
  return { sections: [{
6819
6869
  id: "connection",
@@ -6993,71 +7043,59 @@ function parseNotifyServices(result, brokerId) {
6993
7043
  }
6994
7044
  }));
6995
7045
  }
6996
- /** KV JSON-blob shape — a single `data` column routes the row through the
6997
- * settings backend's canonical key/value path (id TEXT PK, data TEXT). */
6998
- var KV_BLOB_COLUMNS = [{
6999
- name: "data",
7000
- type: "TEXT",
7001
- notNull: true
7002
- }];
7003
- function rowToTarget(row) {
7004
- const parsed = require_dist.TargetSchema.safeParse({
7005
- id: row.id,
7006
- ...row.data
7007
- });
7008
- return parsed.success ? parsed.data : null;
7009
- }
7010
- function targetToData(target) {
7011
- return {
7012
- name: target.name,
7013
- kind: target.kind,
7014
- addonId: target.addonId,
7015
- enabled: target.enabled,
7016
- config: target.config
7017
- };
7018
- }
7019
- /** CRUD over one settings-store collection of `homeassistant` notify targets. */
7020
- var HaTargetStore = class {
7021
- store;
7022
- collection;
7023
- constructor(store, collection = HA_TARGETS_COLLECTION) {
7024
- this.store = store;
7025
- this.collection = collection;
7046
+ /**
7047
+ * CRUD over the `ha-notification-targets` record kind.
7048
+ *
7049
+ * `HaTargetStore.of(records)` is the production factory; the test helper
7050
+ * (`makeFakeHaRecords`) supplies a fake transport so nothing hits SQLite.
7051
+ * No `init()` method: kinds are declared at addon boot via
7052
+ * `ctx.records.declare(haRecordKinds)`.
7053
+ */
7054
+ var HaTargetStore = class HaTargetStore {
7055
+ kind;
7056
+ constructor(kind) {
7057
+ this.kind = kind;
7026
7058
  }
7027
- /** Declare the backing collection before any read/write. The SQLite settings
7028
- * backend rejects undeclared collections (fail-fast), so this MUST run before
7029
- * `list`/`getById`/`upsert`/`delete` — mirrors addon-ai's ProfileStore.init. */
7030
- async init() {
7031
- await this.store.declareCollection(this.collection, KV_BLOB_COLUMNS);
7059
+ /** Factory: build from a declared `RecordsAccess` (after `ctx.records.declare`). */
7060
+ static of(records) {
7061
+ return new HaTargetStore(records.kind(haRecordKinds["ha-notification-targets"]));
7032
7062
  }
7033
7063
  async list() {
7034
- const rows = await this.store.query(this.collection);
7064
+ const page = await this.kind.query({ limit: 1e3 });
7035
7065
  const out = [];
7036
- for (const row of rows) {
7037
- const target = rowToTarget(row);
7038
- if (target) out.push(target);
7066
+ for (const record of page.records) {
7067
+ const parsed = require_dist.TargetSchema.safeParse({
7068
+ id: record.id,
7069
+ ...record.data
7070
+ });
7071
+ if (parsed.success) out.push(parsed.data);
7039
7072
  }
7040
7073
  return out;
7041
7074
  }
7042
7075
  async getById(id) {
7043
- const row = (await this.store.query(this.collection)).find((r) => r.id === id);
7044
- return row ? rowToTarget(row) : null;
7076
+ const row = await this.kind.get(id);
7077
+ if (row === null) return null;
7078
+ const parsed = require_dist.TargetSchema.safeParse({
7079
+ id: row.id,
7080
+ ...row.data
7081
+ });
7082
+ return parsed.success ? parsed.data : null;
7045
7083
  }
7046
7084
  async upsert(target) {
7047
- const exists = (await this.store.query(this.collection)).some((r) => r.id === target.id);
7048
- const data = targetToData(target);
7049
- if (exists) await this.store.update(this.collection, target.id, data);
7050
- else await this.store.insert(this.collection, {
7051
- id: target.id,
7052
- data
7085
+ const { id, ...rest } = target;
7086
+ const parsed = haRecordKinds["ha-notification-targets"].schema.safeParse(rest);
7087
+ if (!parsed.success) throw new Error(`invalid HA target '${id}': ${parsed.error.message}`);
7088
+ await this.kind.put({
7089
+ id,
7090
+ data: parsed.data
7053
7091
  });
7054
7092
  }
7055
7093
  async delete(id) {
7056
- await this.store.remove(this.collection, id);
7094
+ await this.kind.delete(id);
7057
7095
  }
7058
7096
  async setEnabled(id, enabled) {
7059
7097
  const target = await this.getById(id);
7060
- if (!target) return null;
7098
+ if (target === null) return null;
7061
7099
  const next = {
7062
7100
  ...target,
7063
7101
  enabled
@@ -7066,78 +7104,6 @@ var HaTargetStore = class {
7066
7104
  return next;
7067
7105
  }
7068
7106
  };
7069
- /** Adapt the tRPC-shaped `settings-store` cap client to the narrow port. */
7070
- function createApiHaSettingsStorePort(api) {
7071
- return {
7072
- query: async (collection) => {
7073
- return (await api.settingsStore.query.query({ collection })).map((r) => ({
7074
- id: r.id,
7075
- data: r.data
7076
- }));
7077
- },
7078
- insert: async (collection, record) => {
7079
- await api.settingsStore.insert.mutate({
7080
- collection,
7081
- record: {
7082
- id: record.id,
7083
- data: { ...record.data }
7084
- }
7085
- });
7086
- },
7087
- update: async (collection, id, data) => {
7088
- await api.settingsStore.update.mutate({
7089
- collection,
7090
- id,
7091
- data
7092
- });
7093
- },
7094
- remove: async (collection, id) => {
7095
- await api.settingsStore.delete.mutate({
7096
- collection,
7097
- key: id
7098
- });
7099
- },
7100
- declareCollection: async (collection, columns) => {
7101
- await api.settingsStore.declareCollection.mutate({
7102
- collection,
7103
- columns: columns.map((c) => ({ ...c }))
7104
- });
7105
- }
7106
- };
7107
- }
7108
- /** In-memory port — a resilient fallback when no `api` is wired. */
7109
- function createMemoryHaSettingsStorePort() {
7110
- const collections = /* @__PURE__ */ new Map();
7111
- const bucket = (collection) => {
7112
- let map = collections.get(collection);
7113
- if (!map) {
7114
- map = /* @__PURE__ */ new Map();
7115
- collections.set(collection, map);
7116
- }
7117
- return map;
7118
- };
7119
- return {
7120
- query: async (collection) => [...bucket(collection).values()],
7121
- insert: async (collection, record) => {
7122
- bucket(collection).set(record.id, {
7123
- id: record.id,
7124
- data: { ...record.data }
7125
- });
7126
- },
7127
- update: async (collection, id, data) => {
7128
- bucket(collection).set(id, {
7129
- id,
7130
- data: { ...data }
7131
- });
7132
- },
7133
- remove: async (collection, id) => {
7134
- bucket(collection).delete(id);
7135
- },
7136
- declareCollection: async (collection) => {
7137
- bucket(collection);
7138
- }
7139
- };
7140
- }
7141
7107
  /** The canned notification `testTarget` sends when the caller omits a sample. */
7142
7108
  function cannedNotification() {
7143
7109
  return {
@@ -7287,6 +7253,78 @@ function createHaNotificationOutputProvider(deps) {
7287
7253
  };
7288
7254
  }
7289
7255
  //#endregion
7256
+ //#region src/ha-broker-store.ts
7257
+ /**
7258
+ * CRUD for HA brokers over the `brokers` entry record kind (B2).
7259
+ */
7260
+ function rowToEntry(id, data) {
7261
+ const parsed = HaBrokerEntrySchema.safeParse({
7262
+ id,
7263
+ name: data.name,
7264
+ auth: data.auth,
7265
+ integrationId: data.integrationId
7266
+ });
7267
+ return parsed.success ? parsed.data : null;
7268
+ }
7269
+ var HaBrokerStore = class HaBrokerStore {
7270
+ kind;
7271
+ constructor(kind) {
7272
+ this.kind = kind;
7273
+ }
7274
+ static of(records) {
7275
+ return new HaBrokerStore(records.kind(haBrokersEntryKind));
7276
+ }
7277
+ async listResolved() {
7278
+ const page = await this.kind.query({ limit: 1e3 });
7279
+ const out = [];
7280
+ for (const record of page.records) {
7281
+ let data = record.data;
7282
+ try {
7283
+ const resolved = await this.kind.getResolved(record.id);
7284
+ if (resolved !== null) data = resolved.data;
7285
+ } catch (err) {
7286
+ if (!(err instanceof require_dist.RecordSecretUnavailableError)) throw err;
7287
+ }
7288
+ const entry = rowToEntry(record.id, data);
7289
+ if (entry !== null) out.push(entry);
7290
+ }
7291
+ return out;
7292
+ }
7293
+ async getById(id) {
7294
+ try {
7295
+ const row = await this.kind.getResolved(id);
7296
+ if (row === null) return null;
7297
+ return rowToEntry(row.id, row.data);
7298
+ } catch (err) {
7299
+ if (err instanceof require_dist.RecordSecretUnavailableError) return null;
7300
+ throw err;
7301
+ }
7302
+ }
7303
+ async upsert(entry) {
7304
+ const { id, name, auth, integrationId } = entry;
7305
+ const body = {
7306
+ name,
7307
+ auth,
7308
+ ...integrationId === void 0 ? {} : { integrationId }
7309
+ };
7310
+ const parsed = haBrokersEntryKind.schema.safeParse(body);
7311
+ if (!parsed.success) throw new Error(`invalid HA broker '${id}': ${parsed.error.message}`);
7312
+ await this.kind.put({
7313
+ id,
7314
+ data: parsed.data
7315
+ });
7316
+ }
7317
+ async delete(id) {
7318
+ await this.kind.delete(id);
7319
+ }
7320
+ async replaceAll(entries) {
7321
+ const page = await this.kind.query({ limit: 1e3 });
7322
+ const nextIds = new Set(entries.map((e) => e.id));
7323
+ for (const row of page.records) if (!nextIds.has(row.id)) await this.kind.delete(row.id);
7324
+ for (const entry of entries) await this.upsert(entry);
7325
+ }
7326
+ };
7327
+ //#endregion
7290
7328
  //#region src/ha-calendar-source.ts
7291
7329
  function isCalendarEntity(entityId) {
7292
7330
  return entityId.startsWith("calendar.");
@@ -7947,6 +7985,9 @@ var HaProviderAddon = class HaProviderAddon extends require_dist.BaseDeviceProvi
7947
7985
  return `ha:${String(config?.["brokerId"] ?? "unknown")}:dev:${String(config?.["haDeviceId"] ?? Date.now())}`;
7948
7986
  }
7949
7987
  registry = null;
7988
+ brokerStore = null;
7989
+ /** Runtime broker rows (records when B2 is live, else settings). */
7990
+ activeBrokers = [];
7950
7991
  /** Periodic re-sync sweep handle (cleared on shutdown). */
7951
7992
  resyncTimer = null;
7952
7993
  /** `brokerId → aggregator deviceId` cache for the per-broker generic
@@ -7960,6 +8001,11 @@ var HaProviderAddon = class HaProviderAddon extends require_dist.BaseDeviceProvi
7960
8001
  super({ ...DEFAULT_CONFIG });
7961
8002
  }
7962
8003
  async onInitialize() {
8004
+ const records = this.ctx.records;
8005
+ if (records === void 0) throw new Error("provider-homeassistant: ctx.records is required (hub-only addon)");
8006
+ await records.declare(haAllRecordKinds);
8007
+ this.brokerStore = HaBrokerStore.of(records);
8008
+ this.activeBrokers = await this.loadPersistedBrokers();
7963
8009
  this.registry = new HaBrokerRegistry(this.ctx.logger, this.ctx.eventBus);
7964
8010
  this.registry.setOnBrokerConnected((brokerId) => {
7965
8011
  this.reconcileBroker(brokerId);
@@ -7970,11 +8016,11 @@ var HaProviderAddon = class HaProviderAddon extends require_dist.BaseDeviceProvi
7970
8016
  this.registry.setOnBusEvent((brokerId, ev) => {
7971
8017
  this.routeBusEvent(brokerId, ev);
7972
8018
  });
7973
- await this.registry.restore(this.config.brokers);
8019
+ await this.registry.restore(this.activeBrokers);
7974
8020
  this.resyncTimer = setInterval(() => {
7975
8021
  this.reconcileAllConnectedBrokers();
7976
8022
  }, HaProviderAddon.RESYNC_INTERVAL_MS);
7977
- this.ctx.logger.info("ha provider initialised", { meta: { brokerCount: this.config.brokers.length } });
8023
+ this.ctx.logger.info("ha provider initialised", { meta: { brokerCount: this.activeBrokers.length } });
7978
8024
  await this.reconcileIntegrationsToBrokers();
7979
8025
  this.subscribeIntegrationLifecycle();
7980
8026
  return [
@@ -8005,11 +8051,9 @@ var HaProviderAddon = class HaProviderAddon extends require_dist.BaseDeviceProvi
8005
8051
  ];
8006
8052
  }
8007
8053
  async buildNotificationOutputProvider() {
8008
- const api = this.ctx.api;
8009
- const port = api ? createApiHaSettingsStorePort(api) : createMemoryHaSettingsStorePort();
8010
- if (!api) this.ctx.logger.warn("ha notification-output: no ctx.api — targets persist in-memory only");
8011
- const store = new HaTargetStore(port);
8012
- await store.init();
8054
+ const records = this.ctx.records;
8055
+ if (records === void 0) throw new Error("ha notification-output: ctx.records is required (hub-only addon)");
8056
+ const store = HaTargetStore.of(records);
8013
8057
  return createHaNotificationOutputProvider({
8014
8058
  addonId: this.ctx.id,
8015
8059
  iconUrl: HA_NOTIFICATION_ICON_URL,
@@ -8026,7 +8070,7 @@ var HaProviderAddon = class HaProviderAddon extends require_dist.BaseDeviceProvi
8026
8070
  if (!manager) throw new Error(`ha-broker '${brokerId}' not found`);
8027
8071
  return manager.sendMessage({ type: "get_services" });
8028
8072
  },
8029
- listBrokerIds: () => this.config.brokers.map((b) => b.id),
8073
+ listBrokerIds: () => this.activeBrokers.map((b) => b.id),
8030
8074
  logger: this.ctx.logger.child("notification-output")
8031
8075
  });
8032
8076
  }
@@ -8087,7 +8131,7 @@ var HaProviderAddon = class HaProviderAddon extends require_dist.BaseDeviceProvi
8087
8131
  const settings = await api.integrations.getSettings.query({ id: integration.id });
8088
8132
  const brokerId = typeof settings["brokerId"] === "string" ? settings["brokerId"] : null;
8089
8133
  if (!brokerId) continue;
8090
- if (!this.config.brokers.find((b) => b.id === brokerId)) {
8134
+ if (!this.activeBrokers.find((b) => b.id === brokerId)) {
8091
8135
  this.ctx.logger.warn("integration→broker: linked broker not found", { meta: {
8092
8136
  integrationId: integration.id,
8093
8137
  brokerId
@@ -8100,11 +8144,11 @@ var HaProviderAddon = class HaProviderAddon extends require_dist.BaseDeviceProvi
8100
8144
  brokerId
8101
8145
  });
8102
8146
  }
8103
- const linkedBrokers = linkBrokersToIntegrations(this.config.brokers, integrationsWithBrokerId);
8104
- if (linkedBrokers.some((b, i) => b !== this.config.brokers[i])) await this.updateGlobalSettings({ brokers: linkedBrokers });
8105
- const orphans = computeBrokerCleanup(this.config.brokers, survivingIntegrationIds);
8147
+ const linkedBrokers = linkBrokersToIntegrations(this.activeBrokers, integrationsWithBrokerId);
8148
+ if (linkedBrokers.some((b, i) => b !== this.activeBrokers[i])) await this.persistBrokerEntries(linkedBrokers);
8149
+ const orphans = computeBrokerCleanup(this.activeBrokers, survivingIntegrationIds);
8106
8150
  this.ctx.logger.info("integration→broker reconcile", { meta: {
8107
- brokerCount: this.config.brokers.length,
8151
+ brokerCount: this.activeBrokers.length,
8108
8152
  integrationCount: haIntegrations.length,
8109
8153
  orphans: orphans.length
8110
8154
  } });
@@ -8201,7 +8245,8 @@ var HaProviderAddon = class HaProviderAddon extends require_dist.BaseDeviceProvi
8201
8245
  async onConfigChanged() {
8202
8246
  const reg = this.registry;
8203
8247
  if (!reg) return;
8204
- const persisted = this.config.brokers;
8248
+ this.activeBrokers = await this.loadPersistedBrokers();
8249
+ const persisted = this.activeBrokers;
8205
8250
  const liveIds = new Set(reg.list().map((b) => b.id));
8206
8251
  const persistedIds = new Set(persisted.map((e) => e.id));
8207
8252
  for (const liveId of liveIds) if (!persistedIds.has(liveId)) try {
@@ -8239,7 +8284,7 @@ var HaProviderAddon = class HaProviderAddon extends require_dist.BaseDeviceProvi
8239
8284
  ...b,
8240
8285
  id: created.id
8241
8286
  } : b);
8242
- await this.updateGlobalSettings({ brokers: next });
8287
+ await this.persistBrokerEntries(next);
8243
8288
  }
8244
8289
  } catch (err) {
8245
8290
  this.ctx.logger.warn("ha onConfigChanged: failed to start new broker", { meta: {
@@ -8249,9 +8294,26 @@ var HaProviderAddon = class HaProviderAddon extends require_dist.BaseDeviceProvi
8249
8294
  }
8250
8295
  }
8251
8296
  }
8297
+ async loadPersistedBrokers() {
8298
+ const store = this.brokerStore;
8299
+ if (store !== null) {
8300
+ const fromRecords = await store.listResolved();
8301
+ if (fromRecords.length > 0) return fromRecords;
8302
+ }
8303
+ return this.config.brokers;
8304
+ }
8305
+ async persistBrokerEntries(entries) {
8306
+ this.activeBrokers = [...entries];
8307
+ const store = this.brokerStore;
8308
+ if (store !== null) {
8309
+ await store.replaceAll(entries);
8310
+ return;
8311
+ }
8312
+ await this.updateGlobalSettings({ brokers: entries });
8313
+ }
8252
8314
  buildBrokerProvider() {
8253
8315
  const ownerAddonId = this.ctx.id;
8254
- const owns = (id) => this.config.brokers.some((b) => b.id === id);
8316
+ const owns = (id) => this.activeBrokers.some((b) => b.id === id);
8255
8317
  return {
8256
8318
  list: async ({ kind }) => {
8257
8319
  if (kind && kind !== HA_KIND) return [];
@@ -8281,7 +8343,7 @@ var HaProviderAddon = class HaProviderAddon extends require_dist.BaseDeviceProvi
8281
8343
  brokerId: entry.id,
8282
8344
  name
8283
8345
  } });
8284
- await this.updateGlobalSettings({ brokers: [...this.config.brokers, entry] });
8346
+ await this.persistBrokerEntries([...this.activeBrokers, entry]);
8285
8347
  return { id: entry.id };
8286
8348
  },
8287
8349
  remove: async ({ id }) => {
@@ -8296,8 +8358,8 @@ var HaProviderAddon = class HaProviderAddon extends require_dist.BaseDeviceProvi
8296
8358
  brokerId: id,
8297
8359
  logger: this.ctx.logger
8298
8360
  });
8299
- const nextBrokers = this.config.brokers.filter((b) => b.id !== id);
8300
- await this.updateGlobalSettings({ brokers: nextBrokers });
8361
+ const nextBrokers = this.activeBrokers.filter((b) => b.id !== id);
8362
+ await this.persistBrokerEntries(nextBrokers);
8301
8363
  },
8302
8364
  testConnection: async ({ id }) => {
8303
8365
  if (!owns(id)) return {
@@ -8319,18 +8381,18 @@ var HaProviderAddon = class HaProviderAddon extends require_dist.BaseDeviceProvi
8319
8381
  };
8320
8382
  },
8321
8383
  getSettings: async ({ id }) => {
8322
- const entry = this.config.brokers.find((b) => b.id === id);
8384
+ const entry = this.activeBrokers.find((b) => b.id === id);
8323
8385
  if (!entry) return null;
8324
8386
  return authToSettings(entry.auth);
8325
8387
  },
8326
8388
  setSettings: async ({ id, settings }) => {
8327
8389
  if (!owns(id)) return;
8328
8390
  const entry = await this.requireRegistry().updateEntry(id, settings);
8329
- const next = this.config.brokers.map((b) => b.id === id ? entry : b);
8330
- await this.updateGlobalSettings({ brokers: next });
8391
+ const next = this.activeBrokers.map((b) => b.id === id ? entry : b);
8392
+ await this.persistBrokerEntries(next);
8331
8393
  },
8332
8394
  getBrokerConfig: async ({ id }) => {
8333
- const entry = this.config.brokers.find((b) => b.id === id);
8395
+ const entry = this.activeBrokers.find((b) => b.id === id);
8334
8396
  if (!entry) return null;
8335
8397
  return authToSettings(entry.auth);
8336
8398
  },