Use an automation to change view to default.
This commit is contained in:
@@ -79,6 +79,10 @@ export class CardElementManager {
|
||||
'mousemove',
|
||||
this._api.getInteractionManager().reportInteraction,
|
||||
);
|
||||
this._element.addEventListener(
|
||||
'wheel',
|
||||
this._api.getInteractionManager().reportInteraction,
|
||||
);
|
||||
this._element.addEventListener(
|
||||
'll-custom',
|
||||
this._api.getActionsManager().handleCustomActionEvent,
|
||||
@@ -129,11 +133,15 @@ export class CardElementManager {
|
||||
// Uninitialize cameras to cause them to reinitialize on
|
||||
// reconnection, to ensure the state subscription/unsubscription works
|
||||
// correctly for triggers.
|
||||
this._api.getInitializationManager().uninitialize(InitializationAspect.CAMERAS),
|
||||
this._element.removeEventListener(
|
||||
'mousemove',
|
||||
this._api.getInteractionManager().reportInteraction,
|
||||
);
|
||||
this._api.getInitializationManager().uninitialize(InitializationAspect.CAMERAS);
|
||||
this._element.removeEventListener(
|
||||
'mousemove',
|
||||
this._api.getInteractionManager().reportInteraction,
|
||||
);
|
||||
this._element.removeEventListener(
|
||||
'wheel',
|
||||
this._api.getInteractionManager().reportInteraction,
|
||||
);
|
||||
this._element.removeEventListener(
|
||||
'll-custom',
|
||||
this._api.getActionsManager().handleCustomActionEvent,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { DestroyCallback, subscribeToTrigger } from '../utils/ha';
|
||||
import { isActionAllowedBasedOnInteractionState } from '../utils/interaction-mode';
|
||||
import { Timer } from '../utils/timer';
|
||||
import { CardDefaultManagerAPI } from './types';
|
||||
import { createGeneralAction } from '../utils/action';
|
||||
|
||||
/**
|
||||
* Manages automated resetting to the default view.
|
||||
@@ -25,6 +26,22 @@ export class DefaultManager {
|
||||
public async initialize(): Promise<boolean> {
|
||||
const result = await this._initializationLimit.add(() => this._reconfigure());
|
||||
this._startTimer();
|
||||
|
||||
if (this._api.getConfigManager().getConfig()?.view.default_reset.after_interaction) {
|
||||
this._api.getAutomationsManager().addAutomations([
|
||||
{
|
||||
actions: [createGeneralAction('default')],
|
||||
conditions: [
|
||||
{
|
||||
condition: 'interaction' as const,
|
||||
interaction: false,
|
||||
},
|
||||
],
|
||||
tag: this,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
return !!result;
|
||||
}
|
||||
|
||||
@@ -32,6 +49,7 @@ export class DefaultManager {
|
||||
this._timer.stop();
|
||||
this._unsubscribeCallback?.();
|
||||
this._unsubscribeCallback = null;
|
||||
this._api.getAutomationsManager().deleteAutomations(this);
|
||||
}
|
||||
|
||||
protected async _reconfigure(): Promise<boolean> {
|
||||
|
||||
@@ -39,16 +39,7 @@ export class InteractionManager {
|
||||
|
||||
this._timer.start(timeoutSeconds, () => {
|
||||
this._api.getConditionsManager().setState({ interaction: false });
|
||||
|
||||
if (!this._api.getTriggersManager().isTriggered()) {
|
||||
if (
|
||||
this._api.getConfigManager().getConfig()?.view.default_reset
|
||||
.after_interaction
|
||||
) {
|
||||
this._api.getViewManager().setViewDefault();
|
||||
}
|
||||
this._api.getStyleManager().setLightOrDarkMode();
|
||||
}
|
||||
this._api.getStyleManager().setLightOrDarkMode();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ export interface CardConfigLoaderAPI {
|
||||
}
|
||||
|
||||
export interface CardDefaultManagerAPI {
|
||||
getAutomationsManager(): AutomationsManager;
|
||||
getConfigManager(): ConfigManager;
|
||||
getHASSManager(): HASSManager;
|
||||
getInteractionManager(): InteractionManager;
|
||||
|
||||
Reference in New Issue
Block a user