Skip to content

Commit

Permalink
fix: card broken with HA 2023.04bXX
Browse files Browse the repository at this point in the history
  • Loading branch information
RomRider committed Apr 2, 2023
1 parent b05c6b4 commit 9b4f1e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
stateIcon,
HomeAssistant,
handleClick,
getLovelace,
timerTimeRemaining,
secondsToDuration,
durationToSeconds,
Expand Down Expand Up @@ -51,6 +50,7 @@ import {
getLightColorBasedOnTemperature,
mergeDeep,
mergeStatesById,
getLovelace,
getLovelaceCast,
} from './helpers';
import { styles } from './styles';
Expand Down
21 changes: 20 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PropertyValues } from 'lit-element';
import tinycolor, { TinyColor } from '@ctrl/tinycolor';
import { HomeAssistant } from 'custom-card-helpers';
import { HomeAssistant, LovelaceConfig } from 'custom-card-helpers';
import { StateConfig } from './types';

export function computeDomain(entityId: string): string {
Expand Down Expand Up @@ -153,3 +153,22 @@ export function getLovelaceCast(): any {
}
return null;
}

export function getLovelace(): LovelaceConfig | null {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let root: any = document.querySelector('home-assistant');
root = root && root.shadowRoot;
root = root && root.querySelector('home-assistant-main');
root = root && root.shadowRoot;
root = root && root.querySelector('app-drawer-layout partial-panel-resolver, ha-drawer partial-panel-resolver');
root = (root && root.shadowRoot) || root;
root = root && root.querySelector('ha-panel-lovelace');
root = root && root.shadowRoot;
root = root && root.querySelector('hui-root');
if (root) {
const ll = root.lovelace;
ll.current_view = root.___curView;
return ll;
}
return null;
}

0 comments on commit 9b4f1e2

Please sign in to comment.