refactor: Retire the use of unmaintained custom-card-helpers (#1956)

- Closes #1295
This commit is contained in:
Dermot Duffy
2025-03-09 16:02:33 -07:00
committed by GitHub
parent c65ee3f0f2
commit a79ffa6edc
116 changed files with 933 additions and 545 deletions
+1 -1
View File
@@ -1,8 +1,8 @@
import { HomeAssistant } from '@dermotduffy/custom-card-helpers';
import { HassEntity } from 'home-assistant-js-websocket';
import frigateSVG from '../camera-manager/frigate/assets/frigate.svg';
import motioneyeSVG from '../camera-manager/motioneye/assets/motioneye.svg';
import reolinkSVG from '../camera-manager/reolink/assets/reolink.svg';
import { HomeAssistant } from '../ha/types';
import irisSVG from '../images/iris.svg';
import { Icon } from '../types';
@@ -1,5 +1,5 @@
import { dispatchAdvancedCameraCardEvent } from '../../../utils/basic';
import { fireAdvancedCameraCardEvent } from '../../../utils/fire-advanced-camera-card-event';
export function dispatchLiveErrorEvent(element: EventTarget): void {
dispatchAdvancedCameraCardEvent(element, 'live:error');
fireAdvancedCameraCardEvent(element, 'live:error');
}
+4 -7
View File
@@ -3,11 +3,8 @@ import throttle from 'lodash-es/throttle';
import Masonry from 'masonry-layout';
import { ViewDisplayConfig } from '../config/types';
import { MediaLoadedInfo } from '../types';
import {
dispatchAdvancedCameraCardEvent,
getChildrenFromElement,
setOrRemoveAttribute,
} from '../utils/basic';
import { getChildrenFromElement, setOrRemoveAttribute } from '../utils/basic';
import { fireAdvancedCameraCardEvent } from '../utils/fire-advanced-camera-card-event';
import {
AdvancedCameraCardMediaLoadedEventTarget,
dispatchExistingMediaLoadedInfoAsEvent,
@@ -137,7 +134,7 @@ export class MediaGridController {
}
this._selected = id;
dispatchAdvancedCameraCardEvent(this._host, 'media-grid:selected', { selected: id });
fireAdvancedCameraCardEvent(this._host, 'media-grid:selected', { selected: id });
const mediaLoadedInfo = this._mediaLoadedInfoMap.get(id);
if (mediaLoadedInfo) {
@@ -155,7 +152,7 @@ export class MediaGridController {
public unselectAll() {
if (this._selected !== null) {
dispatchMediaUnloadedEvent(this._host);
dispatchAdvancedCameraCardEvent(this._host, 'media-grid:unselected');
fireAdvancedCameraCardEvent(this._host, 'media-grid:unselected');
}
this._selected = null;
this._updateSelectedStylesOnElements();
+1 -1
View File
@@ -1,4 +1,3 @@
import { HomeAssistant } from '@dermotduffy/custom-card-helpers';
import { StyleInfo } from 'lit/directives/style-map';
import { CameraManager } from '../camera-manager/manager';
import { FullscreenManager } from '../card-controller/fullscreen/fullscreen-manager';
@@ -11,6 +10,7 @@ import {
MenuItem,
VIEWS_USER_SPECIFIED,
} from '../config/types';
import { HomeAssistant } from '../ha/types';
import { localize } from '../localize/localize.js';
import { MediaLoadedInfo } from '../types';
import {
+2 -2
View File
@@ -1,5 +1,5 @@
import { AdvancedCameraCardError, Message } from '../../types';
import { dispatchAdvancedCameraCardEvent } from '../../utils/basic';
import { fireAdvancedCameraCardEvent } from '../../utils/fire-advanced-camera-card-event';
// Facilitates correct typing of event handlers.
export interface AdvancedCameraCardMessageEventTarget extends EventTarget {
@@ -44,7 +44,7 @@ export const dispatchAdvancedCameraCardErrorEvent = (
error: unknown,
): void => {
if (error instanceof Error) {
dispatchAdvancedCameraCardEvent<Message>(element, 'message', {
fireAdvancedCameraCardEvent<Message>(element, 'message', {
message: error.message,
type: 'error',
...(error instanceof AdvancedCameraCardError && { context: error.context }),
+8 -8
View File
@@ -1,11 +1,11 @@
import { HomeAssistant } from '@dermotduffy/custom-card-helpers';
import { CameraManager } from '../../camera-manager/manager';
import { dispatchActionExecutionRequest } from '../../card-controller/actions/utils/execution-request';
import { PTZAction } from '../../config/ptz';
import { Actions, ActionsConfig, PTZControlsConfig } from '../../config/types';
import { Interaction } from '../../types';
import { createPTZMultiAction, getActionConfigGivenAction } from '../../utils/action';
import { SubmenuInteraction } from '../../components/submenu/types';
import { CameraManager } from '../../camera-manager/manager.js';
import { dispatchActionExecutionRequest } from '../../card-controller/actions/utils/execution-request.js';
import { SubmenuInteraction } from '../../components/submenu/types.js';
import { PTZAction } from '../../config/ptz.js';
import { Actions, ActionsConfig, PTZControlsConfig } from '../../config/types.js';
import { HomeAssistant } from '../../ha/types.js';
import { Interaction } from '../../types.js';
import { createPTZMultiAction, getActionConfigGivenAction } from '../../utils/action.js';
import { PTZControllerActions } from './types';
export class PTZController {
+1 -2
View File
@@ -1,4 +1,3 @@
import { HASSDomEvent } from '@dermotduffy/custom-card-helpers';
import { LitElement } from 'lit';
import isEqual from 'lodash-es/isEqual';
import orderBy from 'lodash-es/orderBy';
@@ -76,7 +75,7 @@ export class StatusBarController {
}
public actionHandler(
ev: HASSDomEvent<{ action: string; config?: ActionsConfig }>,
ev: CustomEvent<{ action: string; config?: ActionsConfig }>,
config?: ActionsConfig,
): void {
// These interactions should only be handled by the status bar, as nothing
+6 -9
View File
@@ -1,11 +1,8 @@
import Panzoom, { PanzoomEventDetail, PanzoomObject } from '@dermotduffy/panzoom';
import round from 'lodash-es/round';
import throttle from 'lodash-es/throttle';
import {
arefloatsApproximatelyEqual,
dispatchAdvancedCameraCardEvent,
isHoverableDevice,
} from '../../utils/basic';
import { arefloatsApproximatelyEqual, isHoverableDevice } from '../../utils/basic';
import { fireAdvancedCameraCardEvent } from '../../utils/fire-advanced-camera-card-event';
import {
PartialZoomSettings,
ZOOM_DEFAULT_PAN_X,
@@ -76,7 +73,7 @@ export class ZoomController {
// Even though the click is stopped,the card still needs to gain focus so
// that keyboard shortcuts will work immediately after the card is clicked
// upon.
dispatchAdvancedCameraCardEvent(this._element, 'focus');
fireAdvancedCameraCardEvent(this._element, 'focus');
}
this._allowClick = true;
};
@@ -211,11 +208,11 @@ export class ZoomController {
if (unzoomed && this._zoomed) {
this._zoomed = false;
this._setTouchAction(true);
dispatchAdvancedCameraCardEvent(this._element, 'zoom:unzoomed');
fireAdvancedCameraCardEvent(this._element, 'zoom:unzoomed');
} else if (!unzoomed && !this._zoomed) {
this._zoomed = true;
this._setTouchAction(false);
dispatchAdvancedCameraCardEvent(this._element, 'zoom:zoomed');
fireAdvancedCameraCardEvent(this._element, 'zoom:zoomed');
}
const converted = this._convertXYPanToPercent(pz.x, pz.y, pz.scale);
@@ -229,7 +226,7 @@ export class ZoomController {
unzoomed: unzoomed,
};
dispatchAdvancedCameraCardEvent(this._element, 'zoom:change', observed);
fireAdvancedCameraCardEvent(this._element, 'zoom:change', observed);
}
protected _isZoomEqual(a: PartialZoomSettings, b: PartialZoomSettings): boolean {