fix: Ensure no camera outlives a failed initialization (#2657)

This commit is contained in:
Dermot Duffy
2026-08-04 21:33:46 -07:00
committed by GitHub
parent 80ec92e3b2
commit 9f88aacefe
13 changed files with 646 additions and 123 deletions
+15 -1
View File
@@ -101,6 +101,7 @@ export class FakeHASS {
private _isAdmin: boolean;
private _handlers = new Map<string, WSCommandHandler>();
private _commandLog: MessageBase[] = [];
private _openEventSubscriptions = 0;
constructor(options?: FakeHASSOptions) {
this._language = options?.language ?? 'en';
@@ -129,6 +130,13 @@ export class FakeHASS {
this._handlers.set(type, handler);
}
/**
* Number of event subscriptions not yet released.
*/
public getOpenEventSubscriptionCount(): number {
return this._openEventSubscriptions;
}
/**
* Every WebSocket command the card has issued, in order.
*/
@@ -202,7 +210,13 @@ export class FakeHASS {
private _createConnection(): Connection {
const connection = mock<Connection>();
connection.subscribeMessage.mockResolvedValue(() => Promise.resolve());
connection.subscribeEvents.mockResolvedValue(() => Promise.resolve());
connection.subscribeEvents.mockImplementation(async () => {
this._openEventSubscriptions++;
return () => {
this._openEventSubscriptions--;
return Promise.resolve();
};
});
// `callWS` and `sendMessagePromise` are the same request/response channel,
// so both go through one handler table. Given two tables, a command