Fix localize key types to remove config_entry exception (#13257)

This commit is contained in:
Steve Repsher 2022-07-22 05:01:44 -04:00 committed by GitHub
parent 38f19b6180
commit 5be624f45d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 63 additions and 44 deletions

View File

@ -16,7 +16,6 @@ type LocalizeKeyExceptions =
| `state_attributes.${string}` | `state_attributes.${string}`
| `state_badge.${string}` | `state_badge.${string}`
| `groups.${string}` | `groups.${string}`
| `config_entry.${string}`
| `ui.${string}` | `ui.${string}`
| `${keyof TranslationDict["supervisor"]}.${string}` | `${keyof TranslationDict["supervisor"]}.${string}`
| `component.${string}`; | `component.${string}`;

View File

@ -13,8 +13,8 @@ export interface EntityRegistryEntry {
config_entry_id: string | null; config_entry_id: string | null;
device_id: string | null; device_id: string | null;
area_id: string | null; area_id: string | null;
disabled_by: string | null; disabled_by: "user" | "device" | "integration" | "config_entry" | null;
hidden_by: string | null; hidden_by: Exclude<EntityRegistryEntry["disabled_by"], "config_entry">;
entity_category: "config" | "diagnostic" | null; entity_category: "config" | "diagnostic" | null;
has_entity_name: boolean; has_entity_name: boolean;
original_name?: string; original_name?: string;

View File

@ -6,10 +6,14 @@ import "../../../../components/ha-area-picker";
import "../../../../components/ha-dialog"; import "../../../../components/ha-dialog";
import type { HaSwitch } from "../../../../components/ha-switch"; import type { HaSwitch } from "../../../../components/ha-switch";
import "../../../../components/ha-textfield"; import "../../../../components/ha-textfield";
import { computeDeviceName } from "../../../../data/device_registry"; import {
computeDeviceName,
DeviceRegistryEntry,
} from "../../../../data/device_registry";
import { haStyle, haStyleDialog } from "../../../../resources/styles"; import { haStyle, haStyleDialog } from "../../../../resources/styles";
import { HomeAssistant } from "../../../../types"; import { HomeAssistant } from "../../../../types";
import { DeviceRegistryDetailDialogParams } from "./show-dialog-device-registry-detail"; import { DeviceRegistryDetailDialogParams } from "./show-dialog-device-registry-detail";
import "../../../../components/ha-alert";
@customElement("dialog-device-registry-detail") @customElement("dialog-device-registry-detail")
class DialogDeviceRegistryDetail extends LitElement { class DialogDeviceRegistryDetail extends LitElement {
@ -21,11 +25,11 @@ class DialogDeviceRegistryDetail extends LitElement {
@state() private _params?: DeviceRegistryDetailDialogParams; @state() private _params?: DeviceRegistryDetailDialogParams;
@property() public _areaId?: string | null; @state() private _areaId!: string;
@state() private _disabledBy!: string | null; @state() private _disabledBy!: DeviceRegistryEntry["disabled_by"];
@state() private _submitting?: boolean; @state() private _submitting = false;
public async showDialog( public async showDialog(
params: DeviceRegistryDetailDialogParams params: DeviceRegistryDetailDialogParams
@ -33,7 +37,7 @@ class DialogDeviceRegistryDetail extends LitElement {
this._params = params; this._params = params;
this._error = undefined; this._error = undefined;
this._nameByUser = this._params.device.name_by_user || ""; this._nameByUser = this._params.device.name_by_user || "";
this._areaId = this._params.device.area_id; this._areaId = this._params.device.area_id || "";
this._disabledBy = this._params.device.disabled_by; this._disabledBy = this._params.device.disabled_by;
await this.updateComplete; await this.updateComplete;
} }

View File

@ -13,6 +13,7 @@ import {
subscribeDeviceRegistry, subscribeDeviceRegistry,
} from "../../../data/device_registry"; } from "../../../data/device_registry";
import { import {
EntityRegistryEntry,
EntityRegistryEntryUpdateParams, EntityRegistryEntryUpdateParams,
ExtEntityRegistryEntry, ExtEntityRegistryEntry,
updateEntityRegistryEntry, updateEntityRegistryEntry,
@ -25,7 +26,7 @@ import type { HomeAssistant } from "../../../types";
export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) { export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property() public entry!: ExtEntityRegistryEntry; @property({ attribute: false }) public entry!: ExtEntityRegistryEntry;
@state() private _origEntityId!: string; @state() private _origEntityId!: string;
@ -33,7 +34,7 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
@state() private _areaId?: string | null; @state() private _areaId?: string | null;
@state() private _disabledBy!: string | null; @state() private _disabledBy!: EntityRegistryEntry["disabled_by"];
@state() private _hiddenBy!: string | null; @state() private _hiddenBy!: string | null;
@ -41,7 +42,7 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
@state() private _device?: DeviceRegistryEntry; @state() private _device?: DeviceRegistryEntry;
@state() private _submitting?: boolean; @state() private _submitting = false;
public async updateEntry(): Promise<void> { public async updateEntry(): Promise<void> {
this._submitting = true; this._submitting = true;
@ -145,8 +146,8 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
></ha-textfield> ></ha-textfield>
<ha-area-picker <ha-area-picker
.hass=${this.hass} .hass=${this.hass}
.value=${this._areaId} .value=${this._areaId || undefined}
.placeholder=${this._device?.area_id} .placeholder=${this._device?.area_id || undefined}
@value-changed=${this._areaPicked} @value-changed=${this._areaPicked}
></ha-area-picker> ></ha-area-picker>
@ -182,8 +183,8 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
name="hiddendisabled" name="hiddendisabled"
value="enabled" value="enabled"
.checked=${!this._hiddenBy && !this._disabledBy} .checked=${!this._hiddenBy && !this._disabledBy}
.disabled=${this._device?.disabled_by || .disabled=${!!this._device?.disabled_by ||
(this._disabledBy && (this._disabledBy !== null &&
!( !(
this._disabledBy === "user" || this._disabledBy === "user" ||
this._disabledBy === "integration" this._disabledBy === "integration"
@ -200,8 +201,8 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
name="hiddendisabled" name="hiddendisabled"
value="hidden" value="hidden"
.checked=${this._hiddenBy !== null} .checked=${this._hiddenBy !== null}
.disabled=${this._device?.disabled_by || .disabled=${!!this._device?.disabled_by ||
(this._disabledBy && (this._disabledBy !== null &&
!( !(
this._disabledBy === "user" || this._disabledBy === "user" ||
this._disabledBy === "integration" this._disabledBy === "integration"
@ -218,8 +219,8 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
name="hiddendisabled" name="hiddendisabled"
value="disabled" value="disabled"
.checked=${this._disabledBy !== null} .checked=${this._disabledBy !== null}
.disabled=${this._device?.disabled_by || .disabled=${!!this._device?.disabled_by ||
(this._disabledBy && (this._disabledBy !== null &&
!( !(
this._disabledBy === "user" || this._disabledBy === "user" ||
this._disabledBy === "integration" this._disabledBy === "integration"
@ -302,3 +303,9 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
`; `;
} }
} }
declare global {
interface HTMLElementTagNameMap {
"ha-registry-basic-editor": HaEntityRegistryBasicEditor;
}
}

View File

@ -53,6 +53,7 @@ import {
updateDeviceRegistryEntry, updateDeviceRegistryEntry,
} from "../../../data/device_registry"; } from "../../../data/device_registry";
import { import {
EntityRegistryEntry,
EntityRegistryEntryUpdateParams, EntityRegistryEntryUpdateParams,
ExtEntityRegistryEntry, ExtEntityRegistryEntry,
fetchEntityRegistry, fetchEntityRegistry,
@ -128,7 +129,7 @@ const SWITCH_AS_DOMAINS = ["cover", "fan", "light", "lock", "siren"];
export class EntityRegistrySettings extends SubscribeMixin(LitElement) { export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property() public entry!: ExtEntityRegistryEntry; @property({ type: Object }) public entry!: ExtEntityRegistryEntry;
@state() private _name!: string; @state() private _name!: string;
@ -142,9 +143,9 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
@state() private _areaId?: string | null; @state() private _areaId?: string | null;
@state() private _disabledBy!: string | null; @state() private _disabledBy!: EntityRegistryEntry["disabled_by"];
@state() private _hiddenBy!: string | null; @state() private _hiddenBy!: EntityRegistryEntry["hidden_by"];
@state() private _device?: DeviceRegistryEntry; @state() private _device?: DeviceRegistryEntry;
@ -630,9 +631,10 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
name="hiddendisabled" name="hiddendisabled"
value="enabled" value="enabled"
.checked=${!this._hiddenBy && !this._disabledBy} .checked=${!this._hiddenBy && !this._disabledBy}
.disabled=${(this._hiddenBy && this._hiddenBy !== "user") || .disabled=${(this._hiddenBy !== null &&
this._device?.disabled_by || this._hiddenBy !== "user") ||
(this._disabledBy && !!this._device?.disabled_by ||
(this._disabledBy !== null &&
this._disabledBy !== "user" && this._disabledBy !== "user" &&
this._disabledBy !== "integration")} this._disabledBy !== "integration")}
@change=${this._viewStatusChanged} @change=${this._viewStatusChanged}

View File

@ -15,6 +15,7 @@ import { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, query, state } from "lit/decorators"; import { customElement, property, query, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map"; import { classMap } from "lit/directives/class-map";
import { ifDefined } from "lit/directives/if-defined";
import { styleMap } from "lit/directives/style-map"; import { styleMap } from "lit/directives/style-map";
import memoize from "memoize-one"; import memoize from "memoize-one";
import type { HASSDomEvent } from "../../../common/dom/fire_event"; import type { HASSDomEvent } from "../../../common/dom/fire_event";
@ -85,11 +86,11 @@ export interface EntityRow extends StateEntity {
export class HaConfigEntities extends SubscribeMixin(LitElement) { export class HaConfigEntities extends SubscribeMixin(LitElement) {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property() public isWide!: boolean; @property({ type: Boolean }) public isWide!: boolean;
@property() public narrow!: boolean; @property({ type: Boolean }) public narrow!: boolean;
@property() public route!: Route; @property({ attribute: false }) public route!: Route;
@state() private _entities?: EntityRegistryEntry[]; @state() private _entities?: EntityRegistryEntry[];
@ -174,7 +175,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
type: "icon", type: "icon",
template: (_, entry: EntityRow) => html` template: (_, entry: EntityRow) => html`
<ha-state-icon <ha-state-icon
.title=${entry.entity?.state} title=${ifDefined(entry.entity?.state)}
slot="item-icon" slot="item-icon"
.state=${entry.entity} .state=${entry.entity}
></ha-state-icon> ></ha-state-icon>
@ -237,12 +238,10 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
hidden: narrow || !showDisabled, hidden: narrow || !showDisabled,
filterable: true, filterable: true,
width: "15%", width: "15%",
template: (disabled_by) => template: (disabled_by: EntityRegistryEntry["disabled_by"]) =>
this.hass.localize( disabled_by === null
`ui.panel.config.devices.disabled_by.${disabled_by}` ? "—"
) || : this.hass.localize(`config_entry.disabled_by.${disabled_by}`),
disabled_by ||
"—",
}, },
status: { status: {
title: this.hass.localize( title: this.hass.localize(
@ -1012,3 +1011,9 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
]; ];
} }
} }
declare global {
interface HTMLElementTagNameMap {
"ha-config-entities": HaConfigEntities;
}
}

View File

@ -7,7 +7,7 @@ import {
mdiDotsVertical, mdiDotsVertical,
mdiOpenInNew, mdiOpenInNew,
} from "@mdi/js"; } from "@mdi/js";
import "@polymer/paper-item"; import "@polymer/paper-item/paper-item";
import "@polymer/paper-listbox"; import "@polymer/paper-listbox";
import "@polymer/paper-tooltip/paper-tooltip"; import "@polymer/paper-tooltip/paper-tooltip";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
@ -64,13 +64,15 @@ export class HaIntegrationCard extends LitElement {
@property() public domain!: string; @property() public domain!: string;
@property() public items!: ConfigEntryExtended[]; @property({ attribute: false }) public items!: ConfigEntryExtended[];
@property() public manifest?: IntegrationManifest; @property({ attribute: false }) public manifest?: IntegrationManifest;
@property() public entityRegistryEntries!: EntityRegistryEntry[]; @property({ attribute: false })
public entityRegistryEntries!: EntityRegistryEntry[];
@property() public deviceRegistryEntries!: DeviceRegistryEntry[]; @property({ attribute: false })
public deviceRegistryEntries!: DeviceRegistryEntry[];
@property() public selectedConfigEntryId?: string; @property() public selectedConfigEntryId?: string;
@ -179,7 +181,7 @@ export class HaIntegrationCard extends LitElement {
const services = this._getServices(item, this.deviceRegistryEntries); const services = this._getServices(item, this.deviceRegistryEntries);
const entities = this._getEntities(item, this.entityRegistryEntries); const entities = this._getEntities(item, this.entityRegistryEntries);
let stateText: [string, ...unknown[]] | undefined; let stateText: Parameters<typeof this.hass.localize> | undefined;
let stateTextExtra: TemplateResult | string | undefined; let stateTextExtra: TemplateResult | string | undefined;
if (item.disabled_by) { if (item.disabled_by) {
@ -225,7 +227,7 @@ export class HaIntegrationCard extends LitElement {
for (const [items, localizeKey] of [ for (const [items, localizeKey] of [
[devices, "devices"], [devices, "devices"],
[services, "services"], [services, "services"],
] as [DeviceRegistryEntry[], string][]) { ] as const) {
if (items.length === 0) { if (items.length === 0) {
continue; continue;
} }

View File

@ -12,13 +12,13 @@ import { brandsUrl } from "../../../util/brands-url";
export class HaIntegrationHeader extends LitElement { export class HaIntegrationHeader extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property() public banner!: string; @property() public banner?: string;
@property() public localizedDomainName?: string; @property() public localizedDomainName?: string;
@property() public domain!: string; @property() public domain!: string;
@property() public label!: string; @property() public label?: string;
@property({ attribute: false }) public manifest?: IntegrationManifest; @property({ attribute: false }) public manifest?: IntegrationManifest;