mirror of
https://github.com/home-assistant/frontend.git
synced 2025-10-22 10:09:47 +00:00
Compare commits
5 Commits
fix-rtl-pr
...
sec_pypi_p
Author | SHA1 | Date | |
---|---|---|---|
![]() |
19e9de39c5 | ||
![]() |
f22f01e513 | ||
![]() |
3f86f144b5 | ||
![]() |
4efef5ed16 | ||
![]() |
cac7ae2a40 |
6
.github/workflows/codeql-analysis.yml
vendored
6
.github/workflows/codeql-analysis.yml
vendored
@@ -36,14 +36,14 @@ jobs:
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@16140ae1a102900babc80a33c44059580f687047 # v4.30.9
|
||||
uses: github/codeql-action/init@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v4.30.8
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@16140ae1a102900babc80a33c44059580f687047 # v4.30.9
|
||||
uses: github/codeql-action/autobuild@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v4.30.8
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@@ -57,4 +57,4 @@ jobs:
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@16140ae1a102900babc80a33c44059580f687047 # v4.30.9
|
||||
uses: github/codeql-action/analyze@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v4.30.8
|
||||
|
13
.github/workflows/release.yaml
vendored
13
.github/workflows/release.yaml
vendored
@@ -19,8 +19,11 @@ jobs:
|
||||
release:
|
||||
name: Release
|
||||
runs-on: ubuntu-latest
|
||||
environment: pypi
|
||||
permissions:
|
||||
contents: write # Required to upload release assets
|
||||
id-token: write # For "Trusted Publisher" to PyPi
|
||||
if: github.repository_owner == 'home-assistant'
|
||||
steps:
|
||||
- name: Checkout the repository
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
@@ -46,14 +49,18 @@ jobs:
|
||||
run: ./script/translations_download
|
||||
env:
|
||||
LOKALISE_TOKEN: ${{ secrets.LOKALISE_TOKEN }}
|
||||
|
||||
- name: Build and release package
|
||||
run: |
|
||||
python3 -m pip install twine build
|
||||
export TWINE_USERNAME="__token__"
|
||||
export TWINE_PASSWORD="${{ secrets.TWINE_TOKEN }}"
|
||||
python3 -m pip install build
|
||||
export SKIP_FETCH_NIGHTLY_TRANSLATIONS=1
|
||||
script/release
|
||||
|
||||
- name: Publish to PyPI
|
||||
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
|
||||
with:
|
||||
skip-existing: true
|
||||
|
||||
- name: Upload release assets
|
||||
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # v2.4.1
|
||||
with:
|
||||
|
@@ -53,7 +53,7 @@
|
||||
"@fullcalendar/luxon3": "6.1.19",
|
||||
"@fullcalendar/timegrid": "6.1.19",
|
||||
"@home-assistant/webawesome": "3.0.0-beta.6.ha.5",
|
||||
"@lezer/highlight": "1.2.2",
|
||||
"@lezer/highlight": "1.2.1",
|
||||
"@lit-labs/motion": "1.0.9",
|
||||
"@lit-labs/observers": "2.0.6",
|
||||
"@lit-labs/virtualizer": "2.1.1",
|
||||
@@ -122,7 +122,7 @@
|
||||
"lit": "3.3.1",
|
||||
"lit-html": "3.3.1",
|
||||
"luxon": "3.7.2",
|
||||
"marked": "16.4.1",
|
||||
"marked": "16.4.0",
|
||||
"memoize-one": "6.0.0",
|
||||
"node-vibrant": "4.0.3",
|
||||
"object-hash": "3.0.0",
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#!/bin/sh
|
||||
# Pushes a new version to PyPi.
|
||||
|
||||
# Stop on errors
|
||||
set -e
|
||||
@@ -12,5 +11,4 @@ yarn install
|
||||
script/build_frontend
|
||||
|
||||
rm -rf dist home_assistant_frontend.egg-info
|
||||
python3 -m build
|
||||
python3 -m twine upload dist/*.whl --skip-existing
|
||||
python3 -m build -q
|
||||
|
@@ -20,7 +20,6 @@ import "../chips/ha-chip-set";
|
||||
import "../chips/ha-input-chip";
|
||||
import "../ha-combo-box";
|
||||
import type { HaComboBox } from "../ha-combo-box";
|
||||
import "../ha-input-helper-text";
|
||||
import "../ha-sortable";
|
||||
|
||||
interface EntityNameOption {
|
||||
@@ -240,6 +239,7 @@ export class HaEntityNamePicker extends LitElement {
|
||||
.autofocus=${this.autofocus}
|
||||
.disabled=${this.disabled}
|
||||
.required=${this.required && !value.length}
|
||||
.helper=${this.helper}
|
||||
.items=${options}
|
||||
allow-custom-value
|
||||
item-id-path="value"
|
||||
@@ -253,20 +253,9 @@ export class HaEntityNamePicker extends LitElement {
|
||||
</ha-combo-box>
|
||||
</mwc-menu-surface>
|
||||
</div>
|
||||
${this._renderHelper()}
|
||||
`;
|
||||
}
|
||||
|
||||
private _renderHelper() {
|
||||
return this.helper
|
||||
? html`
|
||||
<ha-input-helper-text .disabled=${this.disabled}>
|
||||
${this.helper}
|
||||
</ha-input-helper-text>
|
||||
`
|
||||
: nothing;
|
||||
}
|
||||
|
||||
private _onClosed(ev) {
|
||||
ev.stopPropagation();
|
||||
this._opened = false;
|
||||
@@ -521,11 +510,6 @@ export class HaEntityNamePicker extends LitElement {
|
||||
.sortable-drag {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
ha-input-helper-text {
|
||||
display: block;
|
||||
margin: var(--ha-space-2) 0 0;
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
|
@@ -179,7 +179,7 @@ export class HaGenericPicker extends LitElement {
|
||||
}
|
||||
ha-input-helper-text {
|
||||
display: block;
|
||||
margin: var(--ha-space-2) 0 0;
|
||||
margin: 8px 0 0;
|
||||
}
|
||||
`,
|
||||
];
|
||||
|
@@ -36,8 +36,6 @@ export class HaDeviceSelector extends LitElement {
|
||||
|
||||
@property() public helper?: string;
|
||||
|
||||
@property() public placeholder?: string;
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
@property({ type: Boolean }) public required = true;
|
||||
@@ -104,7 +102,6 @@ export class HaDeviceSelector extends LitElement {
|
||||
.entityFilter=${this.selector.device?.entity
|
||||
? this._filterEntities
|
||||
: undefined}
|
||||
.placeholder=${this.placeholder}
|
||||
.disabled=${this.disabled}
|
||||
.required=${this.required}
|
||||
allow-custom-entity
|
||||
|
@@ -29,8 +29,6 @@ export class HaEntitySelector extends LitElement {
|
||||
|
||||
@property() public helper?: string;
|
||||
|
||||
@property() public placeholder?: any;
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
@property({ type: Boolean }) public required = true;
|
||||
@@ -71,7 +69,6 @@ export class HaEntitySelector extends LitElement {
|
||||
.excludeEntities=${this.selector.entity?.exclude_entities}
|
||||
.entityFilter=${this._filterEntities}
|
||||
.createDomains=${this._createDomains}
|
||||
.placeholder=${this.placeholder}
|
||||
.disabled=${this.disabled}
|
||||
.required=${this.required}
|
||||
allow-custom-entity
|
||||
@@ -89,7 +86,6 @@ export class HaEntitySelector extends LitElement {
|
||||
.reorder=${this.selector.entity.reorder ?? false}
|
||||
.entityFilter=${this._filterEntities}
|
||||
.createDomains=${this._createDomains}
|
||||
.placeholder=${this.placeholder}
|
||||
.disabled=${this.disabled}
|
||||
.required=${this.required}
|
||||
></ha-entities-picker>
|
||||
|
@@ -876,20 +876,13 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
||||
}
|
||||
|
||||
ha-md-list-item.user {
|
||||
--md-list-item-leading-space: 0;
|
||||
--md-list-item-trailing-space: 0;
|
||||
--md-list-item-leading-icon-size: 40px;
|
||||
--md-list-item-leading-space: 4px;
|
||||
}
|
||||
|
||||
ha-user-badge {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
ha-user-badge::part(picture) {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
margin-right: -8px;
|
||||
}
|
||||
|
||||
.spacer {
|
||||
|
@@ -76,16 +76,6 @@ export class HaSlider extends Slider {
|
||||
outline: var(--wa-focus-ring);
|
||||
}
|
||||
|
||||
#track:after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: calc(-50% - 4px);
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: calc(var(--track-size) * 2 + 8px);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#indicator {
|
||||
background-color: var(
|
||||
--ha-slider-indicator-color,
|
||||
|
@@ -457,9 +457,6 @@ export class HaTargetPickerItemRow extends LitElement {
|
||||
}
|
||||
if (
|
||||
(this.type === "area" && entity.area_id === this.itemId) ||
|
||||
(this.type === "floor" &&
|
||||
entity.area_id &&
|
||||
entries.referenced_areas.includes(entity.area_id)) ||
|
||||
(this.type === "label" && entity.labels.includes(this.itemId)) ||
|
||||
entries.referenced_devices.includes(entity.device_id || "")
|
||||
) {
|
||||
|
@@ -54,7 +54,6 @@ class UserBadge extends LitElement {
|
||||
backgroundImage: `url(${this.hass.hassUrl(picture)})`,
|
||||
})}
|
||||
class="picture"
|
||||
part="picture"
|
||||
></div>`;
|
||||
}
|
||||
const initials = computeUserInitials(this.user.name);
|
||||
|
@@ -76,7 +76,7 @@ export const floorCompare =
|
||||
const floorA = entries?.[a];
|
||||
const floorB = entries?.[b];
|
||||
if (floorA && floorB && floorA.level !== floorB.level) {
|
||||
return (floorA.level ?? 9999) - (floorB.level ?? 9999);
|
||||
return (floorA.level ?? 0) - (floorB.level ?? 0);
|
||||
}
|
||||
const nameA = floorA?.name ?? a;
|
||||
const nameB = floorB?.name ?? b;
|
||||
|
@@ -10,10 +10,8 @@ import {
|
||||
optional,
|
||||
string,
|
||||
union,
|
||||
array,
|
||||
} from "superstruct";
|
||||
import { createDurationData } from "../../../../../common/datetime/create_duration_data";
|
||||
import { ensureArray } from "../../../../../common/array/ensure-array";
|
||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||
import "../../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../../components/ha-form/types";
|
||||
@@ -27,7 +25,7 @@ const stateConditionStruct = object({
|
||||
condition: literal("state"),
|
||||
entity_id: optional(string()),
|
||||
attribute: optional(string()),
|
||||
state: optional(union([string(), array(string())])),
|
||||
state: optional(string()),
|
||||
for: optional(union([number(), string(), forDictStruct])),
|
||||
enabled: optional(boolean()),
|
||||
});
|
||||
@@ -71,7 +69,7 @@ const SCHEMA = [
|
||||
name: "state",
|
||||
required: true,
|
||||
selector: {
|
||||
state: { multiple: true },
|
||||
state: {},
|
||||
},
|
||||
context: {
|
||||
filter_entity: "entity_id",
|
||||
@@ -90,7 +88,7 @@ export class HaStateCondition extends LitElement implements ConditionElement {
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
public static get defaultConfig(): StateCondition {
|
||||
return { condition: "state", entity_id: "", state: [] };
|
||||
return { condition: "state", entity_id: "", state: "" };
|
||||
}
|
||||
|
||||
public shouldUpdate(changedProperties: PropertyValues) {
|
||||
@@ -107,11 +105,7 @@ export class HaStateCondition extends LitElement implements ConditionElement {
|
||||
|
||||
protected render() {
|
||||
const trgFor = createDurationData(this.condition.for);
|
||||
const data = {
|
||||
...this.condition,
|
||||
state: ensureArray(this.condition.state) || [],
|
||||
for: trgFor,
|
||||
};
|
||||
const data = { ...this.condition, for: trgFor };
|
||||
|
||||
return html`
|
||||
<ha-form
|
||||
@@ -135,9 +129,10 @@ export class HaStateCondition extends LitElement implements ConditionElement {
|
||||
: {}
|
||||
);
|
||||
|
||||
// Ensure `state` stays an array for multi-select. If absent, set to []
|
||||
if (newCondition.state === undefined || newCondition.state === "") {
|
||||
newCondition.state = [];
|
||||
// We should not cleanup state in the above, as it is required.
|
||||
// Set it to empty string if it is undefined.
|
||||
if (!newCondition.state) {
|
||||
newCondition.state = "";
|
||||
}
|
||||
|
||||
fireEvent(this, "value-changed", { value: newCondition });
|
||||
|
@@ -134,8 +134,8 @@ export class HaDeviceCard extends LitElement {
|
||||
}
|
||||
|
||||
protected _getAddresses() {
|
||||
return this.device.connections.filter((conn) =>
|
||||
["mac", "bluetooth", "zigbee"].includes(conn[0])
|
||||
return this.device.connections.filter(
|
||||
(conn) => conn[0] === "mac" || conn[0] === "bluetooth"
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -38,6 +38,7 @@ export class HaDeviceInfoZha extends LitElement {
|
||||
}
|
||||
return html`
|
||||
<ha-expansion-panel header="Zigbee info">
|
||||
<div>IEEE: ${this._zhaDevice.ieee}</div>
|
||||
<div>Nwk: ${formatAsPaddedHex(this._zhaDevice.nwk)}</div>
|
||||
<div>Device Type: ${this._zhaDevice.device_type}</div>
|
||||
<div>
|
||||
|
@@ -528,20 +528,18 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
</ha-button>
|
||||
`
|
||||
: nothing}
|
||||
${this._manifest?.integration_type !== "hardware"
|
||||
? html`<ha-button
|
||||
.appearance=${canAddDevice ? "filled" : "accent"}
|
||||
@click=${this._addIntegration}
|
||||
>
|
||||
${this._manifest?.integration_type
|
||||
? this.hass.localize(
|
||||
`ui.panel.config.integrations.integration_page.add_${this._manifest.integration_type}`
|
||||
)
|
||||
: this.hass.localize(
|
||||
`ui.panel.config.integrations.integration_page.add_entry`
|
||||
)}
|
||||
</ha-button>`
|
||||
: nothing}
|
||||
<ha-button
|
||||
.appearance=${canAddDevice ? "filled" : "accent"}
|
||||
@click=${this._addIntegration}
|
||||
>
|
||||
${this._manifest?.integration_type
|
||||
? this.hass.localize(
|
||||
`ui.panel.config.integrations.integration_page.add_${this._manifest.integration_type}`
|
||||
)
|
||||
: this.hass.localize(
|
||||
`ui.panel.config.integrations.integration_page.add_entry`
|
||||
)}
|
||||
</ha-button>
|
||||
${Array.from(supportedSubentryTypes).map(
|
||||
(flowType) =>
|
||||
html`<ha-button
|
||||
|
@@ -9,14 +9,13 @@ import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import { computeCssColor } from "../../../common/color/compute-color";
|
||||
import { DOMAINS_TOGGLE } from "../../../common/const";
|
||||
import { transform } from "../../../common/decorators/transform";
|
||||
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
|
||||
import { stateActive } from "../../../common/entity/state_active";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import {
|
||||
stateColorBrightness,
|
||||
stateColorCss,
|
||||
@@ -41,7 +40,6 @@ import type { FrontendLocaleData } from "../../../data/translation";
|
||||
import type { Themes } from "../../../data/ws-themes";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { actionHandler } from "../common/directives/action-handler-directive";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
import { findEntities } from "../common/find-entities";
|
||||
import { hasAction } from "../common/has-action";
|
||||
import { createEntityNotFoundWarning } from "../components/hui-warning";
|
||||
@@ -51,6 +49,8 @@ import type {
|
||||
LovelaceGridOptions,
|
||||
} from "../types";
|
||||
import type { ButtonCardConfig } from "./types";
|
||||
import { computeCssColor } from "../../../common/color/compute-color";
|
||||
import { stateActive } from "../../../common/entity/state_active";
|
||||
|
||||
export const getEntityDefaultButtonAction = (entityId?: string) =>
|
||||
entityId && DOMAINS_TOGGLE.has(computeDomain(entityId))
|
||||
@@ -183,11 +183,9 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
|
||||
`;
|
||||
}
|
||||
|
||||
const name = computeLovelaceEntityName(
|
||||
this.hass,
|
||||
stateObj,
|
||||
this._config.name
|
||||
);
|
||||
const name = this._config.show_name
|
||||
? this._config.name || (stateObj ? computeStateName(stateObj) : "")
|
||||
: "";
|
||||
|
||||
return html`
|
||||
<ha-card
|
||||
@@ -197,7 +195,8 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
|
||||
hasDoubleClick: hasAction(this._config!.double_tap_action),
|
||||
})}
|
||||
role="button"
|
||||
aria-label=${name}
|
||||
aria-label=${this._config.name ||
|
||||
(stateObj ? computeStateName(stateObj) : "")}
|
||||
tabindex=${ifDefined(
|
||||
hasAction(this._config.tap_action) ? "0" : undefined
|
||||
)}
|
||||
|
@@ -272,6 +272,7 @@ export class HuiTileCard extends LitElement implements LovelaceCard {
|
||||
.stateObj=${stateObj}
|
||||
.hass=${this.hass}
|
||||
.content=${this._config.state_content}
|
||||
.name=${name}
|
||||
>
|
||||
</state-display>
|
||||
`;
|
||||
|
@@ -4,7 +4,6 @@ import {
|
||||
type EntityNameItem,
|
||||
} from "../../../../common/entity/compute_entity_name_display";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import { ensureArray } from "../../../../common/array/ensure-array";
|
||||
|
||||
/**
|
||||
* Computes the display name for an entity in Lovelace (cards and badges).
|
||||
@@ -16,24 +15,9 @@ import { ensureArray } from "../../../../common/array/ensure-array";
|
||||
*/
|
||||
export const computeLovelaceEntityName = (
|
||||
hass: HomeAssistant,
|
||||
stateObj: HassEntity | undefined,
|
||||
stateObj: HassEntity,
|
||||
nameConfig: string | EntityNameItem | EntityNameItem[] | undefined
|
||||
): string => {
|
||||
if (typeof nameConfig === "string") {
|
||||
return nameConfig;
|
||||
}
|
||||
const config = nameConfig || DEFAULT_ENTITY_NAME;
|
||||
if (stateObj) {
|
||||
return hass.formatEntityName(stateObj, config);
|
||||
}
|
||||
// If entity is not found, fall back to text parts in config
|
||||
// This allows for static names even when the entity is missing
|
||||
// e.g. for a card that doesn't require an entity
|
||||
const textParts = ensureArray(config)
|
||||
.filter((item) => item.type === "text")
|
||||
.map((item) => ("text" in item ? item.text : ""));
|
||||
if (textParts.length) {
|
||||
return textParts.join(" ");
|
||||
}
|
||||
return "";
|
||||
};
|
||||
): string =>
|
||||
typeof nameConfig === "string"
|
||||
? nameConfig
|
||||
: hass.formatEntityName(stateObj, nameConfig || DEFAULT_ENTITY_NAME);
|
||||
|
@@ -5,7 +5,6 @@ import { customElement, property, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { assert, assign, boolean, object, optional, string } from "superstruct";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { DEFAULT_ENTITY_NAME } from "../../../../common/entity/compute_entity_name_display";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type {
|
||||
HaFormSchema,
|
||||
@@ -17,14 +16,13 @@ import type { ButtonCardConfig } from "../../cards/types";
|
||||
import type { LovelaceCardEditor } from "../../types";
|
||||
import { actionConfigStruct } from "../structs/action-struct";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import { entityNameStruct } from "../structs/entity-name-struct";
|
||||
import { configElementStyle } from "./config-elements-style";
|
||||
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
entity: optional(string()),
|
||||
name: optional(entityNameStruct),
|
||||
name: optional(string()),
|
||||
show_name: optional(boolean()),
|
||||
icon: optional(string()),
|
||||
show_icon: optional(boolean()),
|
||||
@@ -70,13 +68,7 @@ export class HuiButtonCardEditor
|
||||
(entityId: string | undefined) =>
|
||||
[
|
||||
{ name: "entity", selector: { entity: {} } },
|
||||
{
|
||||
name: "name",
|
||||
selector: {
|
||||
entity_name: { default_name: DEFAULT_ENTITY_NAME },
|
||||
},
|
||||
context: { entity: "entity" },
|
||||
},
|
||||
{ name: "name", selector: { text: {} } },
|
||||
{
|
||||
name: "",
|
||||
type: "grid",
|
||||
|
@@ -13,7 +13,6 @@ import {
|
||||
union,
|
||||
} from "superstruct";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { DEFAULT_ENTITY_NAME } from "../../../../common/entity/compute_entity_name_display";
|
||||
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||
import "../../../../components/ha-expansion-panel";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
@@ -28,7 +27,6 @@ import type { LovelaceGenericElementEditor } from "../../types";
|
||||
import "../conditions/ha-card-conditions-editor";
|
||||
import { configElementStyle } from "../config-elements/config-elements-style";
|
||||
import { actionConfigStruct } from "../structs/action-struct";
|
||||
import { entityNameStruct } from "../structs/entity-name-struct";
|
||||
|
||||
export const DEFAULT_CONFIG: Partial<EntityHeadingBadgeConfig> = {
|
||||
type: "entity",
|
||||
@@ -39,7 +37,7 @@ export const DEFAULT_CONFIG: Partial<EntityHeadingBadgeConfig> = {
|
||||
const entityConfigStruct = object({
|
||||
type: optional(string()),
|
||||
entity: optional(string()),
|
||||
name: optional(entityNameStruct),
|
||||
name: optional(string()),
|
||||
icon: optional(string()),
|
||||
state_content: optional(union([string(), array(string())])),
|
||||
show_state: optional(boolean()),
|
||||
@@ -94,11 +92,8 @@ export class HuiHeadingEntityEditor
|
||||
{
|
||||
name: "name",
|
||||
selector: {
|
||||
entity_name: {
|
||||
default_name: DEFAULT_ENTITY_NAME,
|
||||
},
|
||||
text: {},
|
||||
},
|
||||
context: { entity: "entity" },
|
||||
},
|
||||
{
|
||||
name: "icon",
|
||||
|
@@ -7,6 +7,7 @@ import memoizeOne from "memoize-one";
|
||||
import { computeCssColor } from "../../../common/color/compute-color";
|
||||
import { hsv2rgb, rgb2hex, rgb2hsv } from "../../../common/color/convert-color";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import { stateActive } from "../../../common/entity/state_active";
|
||||
import { stateColorCss } from "../../../common/entity/state_color";
|
||||
import "../../../components/ha-heading-badge";
|
||||
@@ -15,7 +16,6 @@ import type { ActionHandlerEvent } from "../../../data/lovelace/action_handler";
|
||||
import "../../../state-display/state-display";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { actionHandler } from "../common/directives/action-handler-directive";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
import { handleAction } from "../common/handle-action";
|
||||
import { hasAction } from "../common/has-action";
|
||||
import { DEFAULT_CONFIG } from "../editor/heading-badge-editor/hui-entity-heading-badge-editor";
|
||||
@@ -137,11 +137,7 @@ export class HuiEntityHeadingBadge
|
||||
"--icon-color": color,
|
||||
};
|
||||
|
||||
const name = computeLovelaceEntityName(
|
||||
this.hass,
|
||||
stateObj,
|
||||
this._config.name
|
||||
);
|
||||
const name = config.name || computeStateName(stateObj);
|
||||
|
||||
return html`
|
||||
<ha-heading-badge
|
||||
@@ -170,7 +166,7 @@ export class HuiEntityHeadingBadge
|
||||
.hass=${this.hass}
|
||||
.stateObj=${stateObj}
|
||||
.content=${config.state_content}
|
||||
.name=${name}
|
||||
.name=${config.name}
|
||||
dash-unavailable
|
||||
></state-display>
|
||||
`
|
||||
|
@@ -390,14 +390,11 @@ class HUIRoot extends LitElement {
|
||||
<ha-button-menu slot="actionItems">
|
||||
<ha-icon-button
|
||||
slot="trigger"
|
||||
id="dashboardmenu"
|
||||
.label=${this.hass!.localize("ui.panel.lovelace.editor.menu.open")}
|
||||
.path=${mdiDotsVertical}
|
||||
></ha-icon-button>
|
||||
${listItems}
|
||||
</ha-button-menu>
|
||||
<ha-tooltip placement="bottom" for="dashboardmenu">
|
||||
${this.hass!.localize("ui.panel.lovelace.editor.menu.open")}
|
||||
</ha-tooltip>
|
||||
`);
|
||||
}
|
||||
return html`${result}`;
|
||||
|
@@ -5,6 +5,7 @@ import { customElement, property } from "lit/decorators";
|
||||
import { join } from "lit/directives/join";
|
||||
import { ensureArray } from "../common/array/ensure-array";
|
||||
import { computeStateDomain } from "../common/entity/compute_state_domain";
|
||||
import { computeStateName } from "../common/entity/compute_state_name";
|
||||
import "../components/ha-relative-time";
|
||||
import { isUnavailableState } from "../data/entity";
|
||||
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../data/sensor";
|
||||
@@ -99,8 +100,8 @@ class StateDisplay extends LitElement {
|
||||
|
||||
return this.hass!.formatEntityState(stateObj);
|
||||
}
|
||||
if (content === "name" && this.name) {
|
||||
return html`${this.name}`;
|
||||
if (content === "name") {
|
||||
return html`${this.name || computeStateName(stateObj)}`;
|
||||
}
|
||||
|
||||
let relativeDateTime: string | Date | undefined;
|
||||
|
@@ -24,16 +24,10 @@ describe("absoluteTime", () => {
|
||||
|
||||
it("should format date correctly for same year", () => {
|
||||
const from = new Date();
|
||||
from.setUTCMonth(9, 20);
|
||||
from.setUTCHours(13, 23);
|
||||
if (from.getUTCMonth() === 9 && from.getUTCDate() === 20) {
|
||||
from.setUTCMonth(10, 20);
|
||||
const result = absoluteTime(from, locale, config);
|
||||
expect(result).toBe("Nov 20, 13:23");
|
||||
} else {
|
||||
from.setUTCMonth(9, 20);
|
||||
const result = absoluteTime(from, locale, config);
|
||||
expect(result).toBe("Oct 20, 13:23");
|
||||
}
|
||||
const result = absoluteTime(from, locale, config);
|
||||
expect(result).toBe("Oct 20, 13:23");
|
||||
});
|
||||
|
||||
it("should format date with year correctly", () => {
|
||||
|
@@ -41,18 +41,18 @@ describe("floorCompare", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("treats null level as 9999, placing it at the end", () => {
|
||||
it("treats null level as 0", () => {
|
||||
const entries = {
|
||||
floor1: { name: "Ground Floor", level: 0 } as FloorRegistryEntry,
|
||||
floor2: { name: "First Floor", level: 1 } as FloorRegistryEntry,
|
||||
floor3: { name: "Unassigned", level: null } as FloorRegistryEntry,
|
||||
floor3: { name: "Basement", level: null } as FloorRegistryEntry,
|
||||
};
|
||||
const floors = ["floor2", "floor3", "floor1"];
|
||||
|
||||
expect(floors.sort(floorCompare(entries))).toEqual([
|
||||
"floor3",
|
||||
"floor1",
|
||||
"floor2",
|
||||
"floor3",
|
||||
]);
|
||||
});
|
||||
|
||||
|
@@ -77,71 +77,4 @@ describe("computeLovelaceEntityName", () => {
|
||||
expect(mockFormatEntityName).toHaveBeenCalledTimes(1);
|
||||
expect(mockFormatEntityName).toHaveBeenCalledWith(stateObj, nameConfig);
|
||||
});
|
||||
|
||||
describe("when stateObj is undefined", () => {
|
||||
it("returns empty string when nameConfig is undefined", () => {
|
||||
const mockFormatEntityName = vi.fn();
|
||||
const hass = createMockHass(mockFormatEntityName);
|
||||
|
||||
const result = computeLovelaceEntityName(hass, undefined, undefined);
|
||||
|
||||
expect(result).toBe("");
|
||||
expect(mockFormatEntityName).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns text from single text EntityNameItem", () => {
|
||||
const mockFormatEntityName = vi.fn();
|
||||
const hass = createMockHass(mockFormatEntityName);
|
||||
const nameConfig = { type: "text" as const, text: "Custom Text" };
|
||||
|
||||
const result = computeLovelaceEntityName(hass, undefined, nameConfig);
|
||||
|
||||
expect(result).toBe("Custom Text");
|
||||
expect(mockFormatEntityName).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns joined text from multiple text EntityNameItems", () => {
|
||||
const mockFormatEntityName = vi.fn();
|
||||
const hass = createMockHass(mockFormatEntityName);
|
||||
const nameConfig = [
|
||||
{ type: "text" as const, text: "First" },
|
||||
{ type: "text" as const, text: "Second" },
|
||||
];
|
||||
|
||||
const result = computeLovelaceEntityName(hass, undefined, nameConfig);
|
||||
|
||||
expect(result).toBe("First Second");
|
||||
expect(mockFormatEntityName).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns only text items when mixed with non-text items", () => {
|
||||
const mockFormatEntityName = vi.fn();
|
||||
const hass = createMockHass(mockFormatEntityName);
|
||||
const nameConfig = [
|
||||
{ type: "text" as const, text: "Prefix" },
|
||||
{ type: "device" as const },
|
||||
{ type: "text" as const, text: "Suffix" },
|
||||
{ type: "entity" as const },
|
||||
];
|
||||
|
||||
const result = computeLovelaceEntityName(hass, undefined, nameConfig);
|
||||
|
||||
expect(result).toBe("Prefix Suffix");
|
||||
expect(mockFormatEntityName).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns empty string when no text items in config", () => {
|
||||
const mockFormatEntityName = vi.fn();
|
||||
const hass = createMockHass(mockFormatEntityName);
|
||||
const nameConfig = [
|
||||
{ type: "device" as const },
|
||||
{ type: "entity" as const },
|
||||
];
|
||||
|
||||
const result = computeLovelaceEntityName(hass, undefined, nameConfig);
|
||||
|
||||
expect(result).toBe("");
|
||||
expect(mockFormatEntityName).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
30
yarn.lock
30
yarn.lock
@@ -2286,19 +2286,19 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@lezer/common@npm:^1.0.0, @lezer/common@npm:^1.1.0, @lezer/common@npm:^1.3.0":
|
||||
version: 1.3.0
|
||||
resolution: "@lezer/common@npm:1.3.0"
|
||||
checksum: 10/8e195a8e426bc18d4339b3f2a1a7ad39c3b2cfa740c7108657a241985f63bdee5255a5f5cf8d863b878881744288bcb679d16170f0e5bcebb141188b53cfd8c0
|
||||
"@lezer/common@npm:^1.0.0, @lezer/common@npm:^1.1.0":
|
||||
version: 1.2.3
|
||||
resolution: "@lezer/common@npm:1.2.3"
|
||||
checksum: 10/dad24e353e4e67d88b203191361ca1dff26c01c2b7b4ae829b668a1d115929334d077217367683e39180c0556510ed2066ea8ddba2b079be7c08a7152208cc87
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@lezer/highlight@npm:1.2.2, @lezer/highlight@npm:^1.0.0":
|
||||
version: 1.2.2
|
||||
resolution: "@lezer/highlight@npm:1.2.2"
|
||||
"@lezer/highlight@npm:1.2.1, @lezer/highlight@npm:^1.0.0":
|
||||
version: 1.2.1
|
||||
resolution: "@lezer/highlight@npm:1.2.1"
|
||||
dependencies:
|
||||
"@lezer/common": "npm:^1.3.0"
|
||||
checksum: 10/73cb339de042b354cbc0b9e83978a91d2448435edae865a192cfc50d536e0b7d2e3cd563aabeb59eb6c86b0c38b3edc6f2871da8482c5dd8dca4a0899e743f7f
|
||||
"@lezer/common": "npm:^1.0.0"
|
||||
checksum: 10/fec3082419ee87fb265039b680fbac6796f862d8e3042dcb860e8c5a34291503a74927302b568ff1a626f0d2b5cf8dae02a51cfd200084eb329e5fd1236c3163
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -9274,7 +9274,7 @@ __metadata:
|
||||
"@fullcalendar/luxon3": "npm:6.1.19"
|
||||
"@fullcalendar/timegrid": "npm:6.1.19"
|
||||
"@home-assistant/webawesome": "npm:3.0.0-beta.6.ha.5"
|
||||
"@lezer/highlight": "npm:1.2.2"
|
||||
"@lezer/highlight": "npm:1.2.1"
|
||||
"@lit-labs/motion": "npm:1.0.9"
|
||||
"@lit-labs/observers": "npm:2.0.6"
|
||||
"@lit-labs/virtualizer": "npm:2.1.1"
|
||||
@@ -9398,7 +9398,7 @@ __metadata:
|
||||
lodash.template: "npm:4.5.0"
|
||||
luxon: "npm:3.7.2"
|
||||
map-stream: "npm:0.0.7"
|
||||
marked: "npm:16.4.1"
|
||||
marked: "npm:16.4.0"
|
||||
memoize-one: "npm:6.0.0"
|
||||
node-vibrant: "npm:4.0.3"
|
||||
object-hash: "npm:3.0.0"
|
||||
@@ -11052,12 +11052,12 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"marked@npm:16.4.1":
|
||||
version: 16.4.1
|
||||
resolution: "marked@npm:16.4.1"
|
||||
"marked@npm:16.4.0":
|
||||
version: 16.4.0
|
||||
resolution: "marked@npm:16.4.0"
|
||||
bin:
|
||||
marked: bin/marked.js
|
||||
checksum: 10/b5f475dbe297162dc988b7f345b559d03248fde1023822b9f2a68f50cbca0981c78c42f380c3aa5e133b5f5c069a2c6cd683413c12c83710e983a7bc46cdf4a2
|
||||
checksum: 10/5174b345ccc61e2030c2eb8abb3e5cbebeb6697a6d2b609f64ffa2ff6e482f5f1e1fda1912db19c747f43971b1fa54ae53c1ab1ce5d2f58566d6db4bc3016833
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
Reference in New Issue
Block a user