Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/panels/lovelace/badges/hui-entity-filter-badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class EntityFilterBadge extends UpdatingElement implements LovelaceBadge {
private _oldEntities?: EntityFilterEntityConfig[];

public setConfig(config: EntityFilterBadgeConfig): void {
if (!config.entities || !Array.isArray(config.entities)) {
throw new Error("entities must be specified.");
if (!config.entities.length || !Array.isArray(config.entities)) {
throw new Error("Entities must be specified");
}

if (
Expand All @@ -37,7 +37,7 @@ class EntityFilterBadge extends UpdatingElement implements LovelaceBadge {
Array.isArray(entity.state_filter)
)
) {
throw new Error("Incorrect filter config.");
throw new Error("Incorrect filter config");
}

while (this.lastChild) {
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/cards/hui-alarm-panel-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard {
!config.entity ||
config.entity.split(".")[0] !== "alarm_control_panel"
) {
throw new Error("Invalid card configuration");
throw new Error("Invalid configuration");
}

const defaults = {
Expand Down
5 changes: 4 additions & 1 deletion src/panels/lovelace/cards/hui-button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
}

public setConfig(config: ButtonCardConfig): void {
if (!config.entity) {
throw new Error("Entity must be specified");
}
if (config.entity && !isValidEntityId(config.entity)) {
throw new Error("Invalid Entity");
throw new Error("Invalid entity");
}

this._config = {
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/cards/hui-calendar-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {

public setConfig(config: CalendarCardConfig): void {
if (!config.entities?.length) {
throw new Error("Entities must be defined");
throw new Error("Entities must be specified");
}

if (!Array.isArray(config.entities)) {
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/cards/hui-conditional-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class HuiConditionalCard extends HuiConditionalBase implements LovelaceCard {
this.validateConfig(config);

if (!config.card) {
throw new Error("No card configured.");
throw new Error("No card configured");
}

this._element = this._createCardElement(config.card);
Expand Down
4 changes: 4 additions & 0 deletions src/panels/lovelace/cards/hui-entities-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard {
}

public setConfig(config: EntitiesCardConfig): void {
if (!config || !config.entities.length) {
throw new Error("Entities must be specified");
}

const entities = processConfigEntities(config.entities);

this._config = config;
Expand Down
5 changes: 4 additions & 1 deletion src/panels/lovelace/cards/hui-entity-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
private _footerElement?: HuiErrorCard | LovelaceHeaderFooter;

public setConfig(config: EntityCardConfig): void {
if (!config.entity) {
throw new Error("Entity must be specified");
}
if (config.entity && !isValidEntityId(config.entity)) {
throw new Error("Invalid Entity");
throw new Error("Invalid entity");
}

this._config = config;
Expand Down
6 changes: 3 additions & 3 deletions src/panels/lovelace/cards/hui-entity-filter-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class EntityFilterCard extends UpdatingElement implements LovelaceCard {
}

public setConfig(config: EntityFilterCardConfig): void {
if (!config.entities || !Array.isArray(config.entities)) {
throw new Error("entities must be specified.");
if (!config.entities.length || !Array.isArray(config.entities)) {
throw new Error("Entities must be specified");
}

if (
Expand All @@ -49,7 +49,7 @@ class EntityFilterCard extends UpdatingElement implements LovelaceCard {
Array.isArray(entity.state_filter)
)
) {
throw new Error("Incorrect filter config.");
throw new Error("Incorrect filter config");
}

this._configEntities = processConfigEntities(config.entities);
Expand Down
20 changes: 17 additions & 3 deletions src/panels/lovelace/cards/hui-gauge-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { isValidEntityId } from "../../../common/entity/valid_entity_id";
import "../../../components/ha-card";
import "../../../components/ha-gauge";
import type { HomeAssistant } from "../../../types";
import { UNAVAILABLE } from "../../../data/entity";
import { findEntities } from "../common/find-entites";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import { createEntityNotFoundWarning } from "../components/hui-warning";
Expand Down Expand Up @@ -72,12 +73,13 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
}

public setConfig(config: GaugeCardConfig): void {
if (!config || !config.entity) {
throw new Error("Invalid card configuration");
if (!config.entity) {
throw new Error("Entity must be specified");
}
if (!isValidEntityId(config.entity)) {
throw new Error("Invalid Entity");
throw new Error("Invalid entity");
}

this._config = { min: 0, max: 100, ...config };
}

Expand All @@ -98,6 +100,18 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {

const state = Number(stateObj.state);

if (stateObj.state === UNAVAILABLE) {
return html`
<hui-warning
>${this.hass.localize(
"ui.panel.lovelace.warning.entity_unavailable",
"entity",
this._config.entity
)}</hui-warning
>
`;
}

if (isNaN(state)) {
return html`
<hui-warning
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/cards/hui-humidifier-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class HuiHumidifierCard extends LitElement implements LovelaceCard {

public setConfig(config: HumidifierCardConfig): void {
if (!config.entity || config.entity.split(".")[0] !== "humidifier") {
throw new Error("Specify an entity from within the humidifier domain.");
throw new Error("Specify an entity from within the humidifier domain");
}

this._config = config;
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/cards/hui-light-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class HuiLightCard extends LitElement implements LovelaceCard {

public setConfig(config: LightCardConfig): void {
if (!config.entity || config.entity.split(".")[0] !== "light") {
throw new Error("Specify an entity from within the light domain.");
throw new Error("Specify an entity from within the light domain");
}

this._config = {
Expand Down
4 changes: 4 additions & 0 deletions src/panels/lovelace/cards/hui-logbook-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard {
}

public setConfig(config: LogbookCardConfig): void {
if (!config.entities.length) {
throw new Error("Entities must be specified");
}

this._configEntities = processConfigEntities<EntityConfig>(config.entities);

this._config = {
Expand Down
4 changes: 2 additions & 2 deletions src/panels/lovelace/cards/hui-map-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ class HuiMapCard extends LitElement implements LovelaceCard {
throw new Error("Error in card configuration.");
}

if (!config.entities && !config.geo_location_sources) {
if (!config.entities?.length && !config.geo_location_sources) {
throw new Error(
"Either entities or geo_location_sources must be defined"
"Either entities or geo_location_sources must be specified"
);
}
if (config.entities && !Array.isArray(config.entities)) {
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/cards/hui-markdown-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class HuiMarkdownCard extends LitElement implements LovelaceCard {

public setConfig(config: MarkdownCardConfig): void {
if (!config.content) {
throw new Error("Invalid Configuration: Content Required");
throw new Error("Content required");
}

if (this._config?.content !== config.content) {
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/cards/hui-media-control-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {

public setConfig(config: MediaControlCardConfig): void {
if (!config.entity || config.entity.split(".")[0] !== "media_player") {
throw new Error("Specify an entity from within the media_player domain.");
throw new Error("Specify an entity from within the media_player domain");
}

this._config = config;
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/cards/hui-picture-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class HuiPictureCard extends LitElement implements LovelaceCard {

public setConfig(config: PictureCardConfig): void {
if (!config || !config.image) {
throw new Error("Invalid Configuration: 'image' required");
throw new Error("Image required");
}

this._config = config;
Expand Down
6 changes: 3 additions & 3 deletions src/panels/lovelace/cards/hui-picture-elements-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ class HuiPictureElementsCard extends LitElement implements LovelaceCard {

public setConfig(config: PictureElementsCardConfig): void {
if (!config) {
throw new Error("Invalid Configuration");
throw new Error("Invalid configuration");
} else if (
!(config.image || config.camera_image || config.state_image) ||
(config.state_image && !config.entity)
) {
throw new Error("Invalid Configuration: image required");
throw new Error("Image required");
} else if (!Array.isArray(config.elements)) {
throw new Error("Invalid Configuration: elements required");
throw new Error("Elements required");
}

this._config = config;
Expand Down
4 changes: 2 additions & 2 deletions src/panels/lovelace/cards/hui-picture-entity-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class HuiPictureEntityCard extends LitElement implements LovelaceCard {

public setConfig(config: PictureEntityCardConfig): void {
if (!config || !config.entity) {
throw new Error("Invalid Configuration: 'entity' required");
throw new Error("Entity must be specified");
}

if (
Expand All @@ -78,7 +78,7 @@ class HuiPictureEntityCard extends LitElement implements LovelaceCard {
!config.state_image &&
!config.camera_image
) {
throw new Error("No image source configured.");
throw new Error("No image source configured");
}

this._config = { show_name: true, show_state: true, ...config };
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/cards/hui-picture-glance-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
!(config.image || config.camera_image || config.state_image) ||
(config.state_image && !config.entity)
) {
throw new Error("Invalid card configuration");
throw new Error("Invalid configuration");
}

const entities = processConfigEntities(config.entities);
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/cards/hui-plant-status-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class HuiPlantStatusCard extends LitElement implements LovelaceCard {

public setConfig(config: PlantStatusCardConfig): void {
if (!config.entity || config.entity.split(".")[0] !== "plant") {
throw new Error("Specify an entity from within the plant domain.");
throw new Error("Specify an entity from within the plant domain");
}

this._config = config;
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/cards/hui-sensor-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class HuiSensorCard extends HuiEntityCard {

public setConfig(config: SensorCardConfig): void {
if (!config.entity || config.entity.split(".")[0] !== "sensor") {
throw new Error("Specify an entity from within the sensor domain.");
throw new Error("Specify an entity from within the sensor domain");
}

const { graph, detail, hours_to_show, ...cardConfig } = config;
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/cards/hui-stack-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export abstract class HuiStackCard<T extends StackCardConfig = StackCardConfig>

public setConfig(config: T): void {
if (!config || !config.cards || !Array.isArray(config.cards)) {
throw new Error("Card config incorrect");
throw new Error("Invalid configuration");
}
this._config = config;
this._cards = config.cards.map((card) => {
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/cards/hui-thermostat-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard {

public setConfig(config: ThermostatCardConfig): void {
if (!config.entity || config.entity.split(".")[0] !== "climate") {
throw new Error("Specify an entity from within the climate domain.");
throw new Error("Specify an entity from within the climate domain");
}

this._config = config;
Expand Down
6 changes: 3 additions & 3 deletions src/panels/lovelace/cards/hui-weather-forecast-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
}

public setConfig(config: WeatherForecastCardConfig): void {
if (!config || !config.entity) {
throw new Error("Invalid card configuration");
if (!config.entity) {
throw new Error("Entity must be specified");
}
if (!isValidEntityId(config.entity)) {
throw new Error("Invalid Entity");
throw new Error("Invalid entity");
}

this._config = config;
Expand Down
6 changes: 3 additions & 3 deletions src/panels/lovelace/components/hui-conditional-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export class HuiConditionalBase extends UpdatingElement {
config: ConditionalCardConfig | ConditionalRowConfig
): void {
if (!config.conditions) {
throw new Error("No conditions configured.");
throw new Error("No conditions configured");
}

if (!Array.isArray(config.conditions)) {
throw new Error("Conditions should be in an array.");
throw new Error("Conditions need to be an array");
}

if (!validateConditionalConfig(config.conditions)) {
throw new Error("Conditions are invalid.");
throw new Error("Conditions are invalid");
}

if (this.lastChild) {
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/components/hui-warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const createEntityNotFoundWarning = (
? hass.localize(
"ui.panel.lovelace.warning.entity_not_found",
"entity",
entityId
entityId || "[empty]"
)
: hass.localize("ui.panel.lovelace.warning.starting");
};
Expand Down
4 changes: 2 additions & 2 deletions src/panels/lovelace/create-element/create-element-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export const tryCreateLovelaceElement = <
// If domain types is given, we can derive a type from "entity"
(!domainTypes || !("entity" in config))
) {
throw new Error("No card type configured.");
throw new Error("No card type configured");
}

const customTag = config.type ? _getCustomTag(config.type) : undefined;
Expand All @@ -219,7 +219,7 @@ export const tryCreateLovelaceElement = <
}

if (type === undefined) {
throw new Error("No type specified.");
throw new Error("No type specified");
}

const tag = `hui-${type}-${tagSuffix}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class HuiButtonCardEditor extends LitElement
.label="${this.hass.localize(
"ui.panel.lovelace.editor.card.generic.entity"
)} (${this.hass.localize(
"ui.panel.lovelace.editor.card.config.optional"
"ui.panel.lovelace.editor.card.config.required"
)})"
.hass=${this.hass}
.value=${this._entity}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class HuiEntityCardEditor extends LitElement
.label="${this.hass.localize(
"ui.panel.lovelace.editor.card.generic.entity"
)} (${this.hass.localize(
"ui.panel.lovelace.editor.card.config.optional"
"ui.panel.lovelace.editor.card.config.required"
)})"
.hass=${this.hass}
.value=${this._entity}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class HuiPictureGlanceCardEditor extends LitElement
</div>
<ha-entity-picker
.label="${this.hass.localize(
"ui.panel.lovelace.editor.card.generic.entity"
"ui.panel.lovelace.editor.card.picture-glance.state_entity"
)} (${this.hass.localize(
"ui.panel.lovelace.editor.card.config.optional"
)})"
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/elements/hui-conditional-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class HuiConditionalElement extends HTMLElement implements LovelaceElement {
!Array.isArray(config.elements) ||
!validateConditionalConfig(config.conditions)
) {
throw new Error("Error in card configuration.");
throw new Error("Invalid configuration");
}

if (this._elements.length > 0) {
Expand Down
Loading