Fix some key type errors in cards

This commit is contained in:
Steve Repsher 2022-07-10 14:17:41 -04:00
parent 12239d7fe3
commit d23d774ec1
No known key found for this signature in database
GPG Key ID: 776C4F2DACF6131B
4 changed files with 11 additions and 9 deletions

View File

@ -34,7 +34,7 @@ import type {
} from "home-assistant-js-websocket"; } from "home-assistant-js-websocket";
import { supportsFeature } from "../common/entity/supports-feature"; import { supportsFeature } from "../common/entity/supports-feature";
import { MediaPlayerItemId } from "../components/media-player/ha-media-player-browse"; import { MediaPlayerItemId } from "../components/media-player/ha-media-player-browse";
import type { HomeAssistant } from "../types"; import type { HomeAssistant, TranslationDict } from "../types";
import { UNAVAILABLE_STATES } from "./entity"; import { UNAVAILABLE_STATES } from "./entity";
import { isTTSMediaSource } from "./tts"; import { isTTSMediaSource } from "./tts";
@ -170,7 +170,7 @@ export interface MediaPlayerThumbnail {
export interface ControlButton { export interface ControlButton {
icon: string; icon: string;
// Used as key for action as well as tooltip and aria-label translation key // Used as key for action as well as tooltip and aria-label translation key
action: string; action: keyof TranslationDict["ui"]["card"]["media_player"];
} }
export interface MediaPlayerItem { export interface MediaPlayerItem {

View File

@ -246,7 +246,7 @@ export class HuiEnergyUsageGraphCard
: "", : "",
totalReturned totalReturned
? this.hass.localize( ? this.hass.localize(
"ui.panel.lovelace.cards.energyenergy_usage_graph.total_returned", "ui.panel.lovelace.cards.energy.energy_usage_graph.total_returned",
{ num: formatNumber(totalReturned, locale) } { num: formatNumber(totalReturned, locale) }
) )
: "", : "",

View File

@ -85,7 +85,7 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard {
} }
const defaults = { const defaults = {
states: ["arm_away", "arm_home"], states: ["arm_away", "arm_home"] as const,
}; };
this._config = { ...defaults, ...config }; this._config = { ...defaults, ...config };
@ -166,7 +166,7 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard {
<div id="armActions" class="actions"> <div id="armActions" class="actions">
${(stateObj.state === "disarmed" ${(stateObj.state === "disarmed"
? this._config.states! ? this._config.states!
: ["disarm"] : (["disarm"] as const)
).map( ).map(
(stateAction) => html` (stateAction) => html`
<mwc-button <mwc-button
@ -221,7 +221,9 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard {
`; `;
} }
private _actionDisplay(entityState: string): string { private _actionDisplay(
entityState: NonNullable<AlarmPanelCardConfig["states"]>[number]
): string {
return this.hass!.localize(`ui.card.alarm_control_panel.${entityState}`); return this.hass!.localize(`ui.card.alarm_control_panel.${entityState}`);
} }

View File

@ -1,6 +1,6 @@
import { StatisticType } from "../../../data/history"; import { StatisticType } from "../../../data/history";
import { ActionConfig, LovelaceCardConfig } from "../../../data/lovelace"; import { ActionConfig, LovelaceCardConfig } from "../../../data/lovelace";
import { FullCalendarView } from "../../../types"; import { FullCalendarView, TranslationDict } from "../../../types";
import { Condition } from "../common/validate-condition"; import { Condition } from "../common/validate-condition";
import { HuiImage } from "../components/hui-image"; import { HuiImage } from "../components/hui-image";
import { LovelaceElementConfig } from "../elements/types"; import { LovelaceElementConfig } from "../elements/types";
@ -14,7 +14,7 @@ import { LovelaceHeaderFooterConfig } from "../header-footer/types";
export interface AlarmPanelCardConfig extends LovelaceCardConfig { export interface AlarmPanelCardConfig extends LovelaceCardConfig {
entity: string; entity: string;
name?: string; name?: string;
states?: string[]; states?: readonly (keyof TranslationDict["ui"]["card"]["alarm_control_panel"])[];
theme?: string; theme?: string;
} }
@ -411,7 +411,7 @@ export interface WeatherForecastCardConfig extends LovelaceCardConfig {
name?: string; name?: string;
show_current?: boolean; show_current?: boolean;
show_forecast?: boolean; show_forecast?: boolean;
secondary_info_attribute?: string; secondary_info_attribute?: keyof TranslationDict["ui"]["card"]["weather"]["attributes"];
theme?: string; theme?: string;
tap_action?: ActionConfig; tap_action?: ActionConfig;
hold_action?: ActionConfig; hold_action?: ActionConfig;