fix: Ensure no camera outlives a failed initialization (#2657)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user