Compare commits

..
Author SHA1 Message Date
Paul Bottein fd87f0fd2d Preview the cover while dragging in the cover dialog 2026-12-03 16:26:58 +01:00
489 changed files with 1775 additions and 2492 deletions

No files matched your search

+2 -2
View File
@@ -62,7 +62,7 @@ Use entity-scoped helpers when the component watches an entity ID held on the ho
```ts
@state() @consumeEntityState({ entityIdPath: ["_config", "entity"] })
private _stateObj?: HassEntityState;
private _stateObj?: HassEntity;
@state() @consumeEntityRegistryEntry({ entityIdPath: ["_config", "entity"] })
private _entity?: EntityRegistryDisplayEntry;
@@ -75,7 +75,7 @@ Use `consumeEntityStates` when the host property contains one or more entity IDs
```ts
@state() @consumeEntityStates({ entityIdPath: ["_config", "entities"] })
private _stateObjs?: Record<string, HassEntityState>;
private _stateObjs?: Record<string, HassEntity>;
```
For a single field from a grouped context, pair `@consume` with `@transform`:
+1 -2
View File
@@ -20,9 +20,8 @@ runs:
steps:
- name: Build ${{ inputs.target }}
shell: bash
run: ./node_modules/.bin/gulp "$TARGET"
run: ./node_modules/.bin/gulp ${{ inputs.target }}
env:
TARGET: ${{ inputs.target }}
GITHUB_TOKEN: ${{ inputs.github-token }}
IS_TEST: ${{ inputs.is-test }}
RSPACK_CACHE: ${{ inputs.rspack-cache }}
-19
View File
@@ -40,22 +40,3 @@ jobs:
curl -sSfL "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz" \
| tar -xz actionlint
./actionlint -color
zizmor:
name: Check workflow security
runs-on: ubuntu-latest
env:
# renovate: datasource=github-releases depName=zizmorcore/zizmor
ZIZMOR_VERSION: 1.33.1
steps:
- name: Check out files from GitHub
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Run zizmor
env:
GH_TOKEN: ${{ github.token }}
run: |
curl -sSfL "https://github.com/zizmorcore/zizmor/releases/download/v${ZIZMOR_VERSION}/zizmor-x86_64-unknown-linux-gnu.tar.gz" \
| tar -xz zizmor
./zizmor --format=github .
+1 -3
View File
@@ -47,6 +47,4 @@ jobs:
site-id: ${{ secrets.NETLIFY_GALLERY_SITE_ID }}
- name: Generate summary
env:
NETLIFY_URL: ${{ steps.deploy.outputs.netlify_url }}
run: echo "$NETLIFY_URL" >> "$GITHUB_STEP_SUMMARY"
run: echo "${{ steps.deploy.outputs.netlify_url }}" >> "$GITHUB_STEP_SUMMARY"
-3
View File
@@ -2,8 +2,6 @@ name: "Pull Request Labeler"
on: pull_request_target # zizmor: ignore[dangerous-triggers] -- safe: checks out base repo scripts only and reads PR files through the API, never PR head code
permissions: {}
# Runs one at a time per pull request, so an older run can't undo a newer one
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
@@ -15,7 +13,6 @@ jobs:
contents: read
pull-requests: write
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Apply labels
id: labeler
@@ -20,7 +20,6 @@ jobs:
check:
name: Check pull request follows contribution standards
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
pull-requests: write # To label and comment on pull requests
steps:
+8
View File
@@ -28,10 +28,18 @@ AI can be a helpful tool for writing code and documentation. However, due to the
All contributions must be reviewed and understood by the contributor before submission. You should be able to explain every change in a pull request you submit. Pull requests that appear to be unreviewed AI output will be closed without review.
## Design contributions
AI can be a helpful tool to explore ideas and build mockups and prototypes. But AI tends to give the most common answer, not the one that fits Home Assistant and its users. So we require a human who brings the point of view and owns the design decisions.
You should be able to explain the problem your design solves and why you made your choices. If a mockup or prototype was mostly generated with AI, say so when you share it. Check your work against the [design guidelines](https://contributors.home-assistant.io/design/), as AI tools often make up components, colors, or spacing that don't exist in Home Assistant. Design proposals that look like unreviewed AI output may be closed or hidden.
## Our use of AI
Some of our projects use AI tools to assist with code reviews, issue triaging, reporting, and other project management tasks. These tools may leave comments on pull requests or issues. As with any automated tooling, these comments are not always correct.
We also use AI to help keep the design system, the Figma kit, and the code in sync. The design decisions behind them are made by people.
If an AI tool leaves a comment on your contribution, treat it as you would any other review comment. If you believe it is incorrect, say so; a brief explanation is sufficient. Maintainers always have the final say. If in doubt, ask a maintainer.
## Enforcement
+2 -2
View File
@@ -1,5 +1,5 @@
import { ContextProvider, provide } from "@lit/context";
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
@@ -317,6 +317,6 @@ declare global {
"ha-embed-provider": HaEmbedProvider;
}
interface HASSDomEvents {
"states-changed": { states: HassEntityStates };
"states-changed": { states: HassEntities };
}
}
+4 -4
View File
@@ -1,10 +1,10 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { HistoryStates } from "../../../src/data/history";
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
import { driftedValue, hashFraction } from "./drift";
const generateStateHistory = (
state: HassEntityState,
state: HassEntity,
deltas,
start_date: Date,
end_date: Date
@@ -50,7 +50,7 @@ const NUMBER_POINTS = 96;
// An on/off entity, such as a light, switches a few times over the range, at
// times picked from its entity ID, and ends in its state
const generateOnOffHistory = (
state: HassEntityState,
state: HassEntity,
start: Date,
end: Date
): HistoryStates[string] => {
@@ -78,7 +78,7 @@ const generateOnOffHistory = (
// A number drifts around its state over the range, the same on every load,
// with as many decimals as its state, and ends in its state
const generateNumberHistory = (
state: HassEntityState,
state: HassEntity,
value: number,
start: Date,
end: Date
+3 -3
View File
@@ -15,7 +15,7 @@ import {
startOfWeek,
startOfYear,
} from "date-fns";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { HaDurationData } from "../../../src/components/ha-duration-input";
import type {
Statistic,
@@ -416,14 +416,14 @@ const derivedBatteryFlows: Record<string, { source: string; share: number }> = {
},
};
const hasSum = (stateObj: HassEntityState | undefined): boolean =>
const hasSum = (stateObj: HassEntity | undefined): boolean =>
stateObj?.attributes.state_class === "total" ||
stateObj?.attributes.state_class === "total_increasing";
// Like Core, statistics are given in the unit asked for, such as power in kW
// for the energy dashboard while the demo's power sensors are in W
const unitFactor = (
stateObj: HassEntityState | undefined,
stateObj: HassEntity | undefined,
units?: StatisticsUnitConfiguration
): number => {
const unit = stateObj?.attributes.unit_of_measurement;
+7 -7
View File
@@ -1,6 +1,6 @@
import type {
HassEntityState,
HassEntityStateAttributeBase,
HassEntity,
HassEntityAttributeBase,
} from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit";
@@ -94,7 +94,7 @@ const BINARY_SENSOR_DEVICE_CLASSES = [
"window",
];
const ENTITIES: HassEntityState[] = [
const ENTITIES: HassEntity[] = [
// Alarm control panel
createEntity("alarm_control_panel.disarmed", "disarmed"),
createEntity("alarm_control_panel.armed_home", "armed_home"),
@@ -305,8 +305,8 @@ function createEntity(
entity_id: string,
state: string,
device_class?: string,
attributes?: HassEntityStateAttributeBase | HassEntityState["attributes"]
): HassEntityState {
attributes?: HassEntityAttributeBase | HassEntity["attributes"]
): HassEntity {
return {
entity_id,
state,
@@ -325,14 +325,14 @@ function createEntity(
}
interface EntityRowData {
stateObj: HassEntityState;
stateObj: HassEntity;
entity_id: string;
state: string;
device_class?: string;
domain: string;
}
function createRowData(stateObj: HassEntityState): EntityRowData {
function createRowData(stateObj: HassEntity): EntityRowData {
return {
stateObj,
entity_id: stateObj.entity_id,
+2 -2
View File
@@ -109,7 +109,7 @@
"lit": "3.3.3",
"lit-html": "3.3.3",
"maplibre-gl": "6.20.0",
"marked": "18.4.0",
"marked": "18.3.0",
"marked-footnote": "1.4.0",
"marked-gfm-heading-id": "4.1.4",
"memoize-one": "7.0.0",
@@ -212,7 +212,7 @@
"rspack-manifest-plugin": "5.2.2",
"serve": "14.2.8",
"sinon": "22.1.0",
"tar": "8.0.4",
"tar": "8.0.3",
"terser-webpack-plugin": "5.6.1",
"ts-lit-plugin": "2.0.2",
"typescript": "6.0.3",
+16 -16
View File
@@ -407,14 +407,14 @@ importers:
specifier: 6.20.0
version: 6.20.0
marked:
specifier: 18.4.0
version: 18.4.0
specifier: 18.3.0
version: 18.3.0
marked-footnote:
specifier: 1.4.0
version: 1.4.0(marked@18.4.0)
version: 1.4.0(marked@18.3.0)
marked-gfm-heading-id:
specifier: 4.1.4
version: 4.1.4(marked@18.4.0)
version: 4.1.4(marked@18.3.0)
memoize-one:
specifier: 7.0.0
version: 7.0.0
@@ -711,8 +711,8 @@ importers:
specifier: 22.1.0
version: 22.1.0
tar:
specifier: 8.0.4
version: 8.0.4
specifier: 8.0.3
version: 8.0.3
terser-webpack-plugin:
specifier: 5.6.1
version: 5.6.1([email protected])([email protected])([email protected])([email protected])([email protected])
@@ -6575,8 +6575,8 @@ packages:
engines: {node: '>= 20'}
hasBin: true
marked@18.4.0:
resolution: {integrity: sha512-evbvoaiBPFO2lk2kSkIbrwjPMuX/HjKyefPdZbtwccsJWY91xlLF/SzB5hRsAOwStztmKC09i+IGsUcTYMt//A==}
marked@18.3.0:
resolution: {integrity: sha512-ed8zmPXlBb3UfGXN5iHMQyMhFpdqLgoV5umUXx/Q1R+FW3q8VpqpyoKUwlENL9appo2UMvNLURDVaT3AMOryGA==}
engines: {node: '>= 20'}
hasBin: true
@@ -7801,8 +7801,8 @@ packages:
resolution: {integrity: sha512-to/OxuCk5DeVONcjjODT7aeoRq5NIPPlfPc0tNML+wLlnf6u5BcJz97Uukv3pT3jzorkFhUevylkAiBr+ZmV2w==}
engines: {node: '>=18'}
[email protected].4:
resolution: {integrity: sha512-efl2GHJOnqAV5jVrxbM8T3KrLyCAdcwtqF7tJOEJAe1S8rUJSkGrPu6nSZLJP6/KE7U2hDpMcktnKLx3iPwcZQ==}
[email protected].3:
resolution: {integrity: sha512-S+Gnl5H2+dD5DF7h4e6BOftgFcCqPv3rDRXCvhPLPeX7o2hnQ/aCax5bjdzRBb886xvBGR1vs+wHComyXbnRhQ==}
engines: {node: '>=22'}
[email protected]:
@@ -15020,20 +15020,20 @@ snapshots:
- react
- use-sync-external-store
[email protected](marked@18.4.0):
[email protected](marked@18.3.0):
dependencies:
marked: 18.4.0
marked: 18.3.0
[email protected](marked@18.4.0):
[email protected](marked@18.3.0):
dependencies:
github-slugger: 2.0.0
marked: 18.4.0
marked: 18.3.0
[email protected]: {}
[email protected]: {}
marked@18.4.0: {}
marked@18.3.0: {}
[email protected]: {}
@@ -16458,7 +16458,7 @@ snapshots:
minizlib: 3.1.0
yallist: 5.0.0
[email protected].4: {}
[email protected].3: {}
[email protected]:
dependencies:
-9
View File
@@ -62,15 +62,6 @@
"datasourceTemplate": "github-releases",
"extractVersionTemplate": "^v(?<version>.+)$"
},
{
"description": "Keep zizmor used in CI up to date",
"customType": "regex",
"managerFilePatterns": ["/^\\.github/workflows/actionlint\\.yaml$/"],
"matchStrings": ["ZIZMOR_VERSION: (?<currentValue>\\S+)"],
"depNameTemplate": "zizmorcore/zizmor",
"datasourceTemplate": "github-releases",
"extractVersionTemplate": "^v(?<version>.+)$"
},
{
"description": "Keep gh-actions-lock in CI and Renovate's lockfile generator on the same version",
"customType": "regex",
@@ -1,7 +1,7 @@
import type { ReactiveControllerHost } from "@lit/reactive-element/reactive-controller";
import type {
Connection,
HassEntityStates,
HassEntities,
UnsubscribeFunc,
} from "home-assistant-js-websocket";
import { subscribeCondition } from "../../data/automation";
@@ -393,7 +393,7 @@ export class ConditionEvaluator {
*/
export class ConditionEvaluatorController extends ContextController {
@consumeContext({ context: statesContext, subscribe: true })
private _states?: HassEntityStates | null;
private _states?: HassEntities | null;
@consumeContext({ context: configContext, subscribe: true })
private _hassConfig?: HomeAssistantConfig | null;
@@ -2,7 +2,7 @@ import type {
ReactiveController,
ReactiveControllerHost,
} from "@lit/reactive-element/reactive-controller";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { timerTimeRemaining } from "../../data/timer";
/**
@@ -17,7 +17,7 @@ export class TimerRemainingTimeController implements ReactiveController {
private _host: ReactiveControllerHost;
private _stateObj?: HassEntityState;
private _stateObj?: HassEntity;
private _interval?: number;
@@ -26,7 +26,7 @@ export class TimerRemainingTimeController implements ReactiveController {
host.addController(this);
}
public setStateObj(stateObj: HassEntityState | undefined): void {
public setStateObj(stateObj: HassEntity | undefined): void {
this._stateObj = stateObj;
this._startInterval();
}
+12 -15
View File
@@ -1,8 +1,5 @@
import type { Context } from "@lit/context";
import type {
HassEntityStates,
HassEntityState,
} from "home-assistant-js-websocket";
import type { HassEntities, HassEntity } from "home-assistant-js-websocket";
import type {
HomeAssistant,
HomeAssistantInternationalization,
@@ -31,9 +28,9 @@ const resolveAtPath = (host: unknown, path: readonly string[]) => {
return cur;
};
/** Reuse `previous` when every entry still references the same `HassEntityState`. */
/** Reuse `previous` when every entry still references the same `HassEntity`. */
export const preserveUnchangedEntityStatesRecord = <
T extends Record<string, HassEntityState | undefined>,
T extends Record<string, HassEntity | undefined>,
>(
previous: T | undefined,
next: T
@@ -83,7 +80,7 @@ const composeDecorator = <T, V>(
};
/**
* Consumes `statesContext` and narrows it to the `HassEntityState` for the entity
* Consumes `statesContext` and narrows it to the `HassEntity` for the entity
* ID found at `entityIdPath` on the host (e.g. `["_config", "entity"]`).
*
* The first path segment is watched on the host — changes to it re-run the
@@ -91,7 +88,7 @@ const composeDecorator = <T, V>(
* nullish values.
*/
export const consumeEntityState = (config: ConsumeEntryConfig) =>
composeDecorator<HassEntityStates, HassEntityState>(
composeDecorator<HassEntities, HassEntity>(
statesContext,
config.entityIdPath[0],
function (states) {
@@ -109,10 +106,10 @@ export const consumeEntityState = (config: ConsumeEntryConfig) =>
*/
export const consumeEntityStates = (config: ConsumeEntryConfig) => {
const watchKey = config.entityIdPath[0];
const buildRecord = function (this: unknown, states: HassEntityStates) {
const buildRecord = function (this: unknown, states: HassEntities) {
const ids = ensureArray(resolveAtPath(this, config.entityIdPath));
if (!ids || !states) return undefined;
const result: Record<string, HassEntityState> = {};
const result: Record<string, HassEntity> = {};
for (const id of ids) {
if (typeof id !== "string") continue;
const state = states[id];
@@ -124,22 +121,22 @@ export const consumeEntityStates = (config: ConsumeEntryConfig) => {
return (proto: unknown, propertyKey: string) => {
const key = String(propertyKey);
const transformDec = transform<
HassEntityStates,
Record<string, HassEntityState> | undefined
HassEntities,
Record<string, HassEntity> | undefined
>({
transformer: function (this: unknown, states: HassEntityStates) {
transformer: function (this: unknown, states: HassEntities) {
const next = buildRecord.call(this, states);
if (next === undefined) {
return undefined;
}
const previous = (this as Record<string, unknown>)[
`__transform_${key}`
] as Record<string, HassEntityState> | undefined;
] as Record<string, HassEntity> | undefined;
return preserveUnchangedEntityStatesRecord(previous, next);
},
watch: watchKey ? [watchKey] : [],
});
const consumeDec = subscribeContext<HassEntityStates>(statesContext);
const consumeDec = subscribeContext<HassEntities>(statesContext);
transformDec(proto as never, propertyKey);
consumeDec(proto as never, propertyKey);
};
-12
View File
@@ -1,12 +0,0 @@
import { getShadowRootHost } from "./get-shadow-root-host";
/** The element and its ancestors, crossing shadow root boundaries. */
export const composedAncestors = (element: Element | null): Element[] => {
const ancestors: Element[] = [];
let current = element;
while (current) {
ancestors.push(current);
current = current.parentElement ?? getShadowRootHost(current);
}
return ancestors;
};
+3 -3
View File
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { computeCssColor } from "../color/compute-color";
import { computeDomain } from "./compute_domain";
import { stateColorCss } from "./state_color";
@@ -23,11 +23,11 @@ export const computeAlertActiveStates = (entityId: string): string[] => {
}
};
export const isAlertActive = (stateObj: HassEntityState): boolean =>
export const isAlertActive = (stateObj: HassEntity): boolean =>
computeAlertActiveStates(stateObj.entity_id).includes(stateObj.state);
export const computeAlertColor = (
stateObj: HassEntityState,
stateObj: HassEntity,
color: string
): string | undefined => {
if (color === "none") {
+2 -2
View File
@@ -1,7 +1,7 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
export const attributeClassNames = (
stateObj: HassEntityState,
stateObj: HassEntity,
attributes: string[]
): string => {
if (!stateObj) {
+2 -2
View File
@@ -12,7 +12,7 @@ import {
mdiBatteryAlertVariantOutline,
mdiBatteryUnknown,
} from "@mdi/js";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
const BATTERY_ICONS = {
10: "mdi:battery-10",
@@ -51,7 +51,7 @@ const BATTERY_CHARGING_ICONS = {
100: "mdi:battery-charging",
};
export const batteryIcon = (stateObj: HassEntityState, state?: string) => {
export const batteryIcon = (stateObj: HassEntity, state?: string) => {
const level = state ?? stateObj.state;
return batteryLevelIcon(level);
};
+4 -4
View File
@@ -1,6 +1,6 @@
import type {
HassEntityStates,
HassEntityState,
HassEntities,
HassEntity,
HassServices,
} from "home-assistant-js-websocket";
import { canToggleDomain } from "./can_toggle_domain";
@@ -9,9 +9,9 @@ import { supportsFeature } from "./supports-feature";
import { SPECIAL_TOGGLE_ACTIONS } from "./get_toggle_action";
export const canToggleState = (
states: HassEntityStates,
states: HassEntities,
services: HassServices,
stateObj: HassEntityState
stateObj: HassEntity
) => {
const domain = computeStateDomain(stateObj);
@@ -1,4 +1,4 @@
import type { HassConfig, HassEntityState } from "home-assistant-js-websocket";
import type { HassConfig, HassEntity } from "home-assistant-js-websocket";
import {
DOMAIN_ATTRIBUTES_FORMATERS,
DOMAIN_ATTRIBUTES_UNITS,
@@ -25,7 +25,7 @@ import { computeStateDomain } from "./compute_state_domain";
export const computeAttributeValueDisplay = (
localize: LocalizeFunc,
stateObj: HassEntityState,
stateObj: HassEntity,
locale: FrontendLocaleData,
config: HassConfig,
entities: HomeAssistant["entities"],
@@ -47,7 +47,7 @@ export const computeAttributeValueDisplay = (
export const computeAttributeValueToParts = (
localize: LocalizeFunc,
stateObj: HassEntityState,
stateObj: HassEntity,
locale: FrontendLocaleData,
config: HassConfig,
entities: HomeAssistant["entities"],
@@ -205,7 +205,7 @@ export const computeAttributeValueToParts = (
// effects of a light group, so use the translation of a member.
const computeMemberAttributeValueDisplay = (
localize: LocalizeFunc,
stateObj: HassEntityState,
stateObj: HassEntity,
entities: HomeAssistant["entities"],
attribute: string,
attributeValue: string
@@ -224,7 +224,7 @@ const computeMemberAttributeValueDisplay = (
export const computeAttributeNameDisplay = (
localize: LocalizeFunc,
stateObj: HassEntityState,
stateObj: HassEntity,
entities: HomeAssistant["entities"],
attribute: string
): string => {
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type {
EntityRegistryDisplayEntry,
EntityRegistryEntry,
@@ -56,7 +56,7 @@ const computeTextOnlyName = (
* while the real formatter is still loading.
*/
export const computeEntityNameDisplayWithoutContext = (
stateObj: HassEntityState,
stateObj: HassEntity,
name?: string | EntityNameItem | EntityNameItem[],
options?: EntityNameOptions
): string => {
@@ -125,7 +125,7 @@ export const computeEntityEntryNameParts = (
};
export const computeEntityNameParts = (
stateObj: HassEntityState,
stateObj: HassEntity,
registries: HomeAssistantRegistries,
options?: EntityNamePartsOptions
): EntityNameParts => {
@@ -139,7 +139,7 @@ export const computeEntityNameParts = (
};
export const computeDefaultEntityNameItems = (
stateObj: HassEntityState,
stateObj: HassEntity,
registries: HomeAssistantRegistries
): EntityNameItem[] => {
const parts = computeEntityNameParts(stateObj, registries);
@@ -147,7 +147,7 @@ export const computeDefaultEntityNameItems = (
};
export const computeEntityNameDisplay = (
stateObj: HassEntityState,
stateObj: HassEntity,
name: string | EntityNameItem | EntityNameItem[] | undefined,
registries: HomeAssistantRegistries,
options?: EntityNameOptions
@@ -194,7 +194,7 @@ export const computeEntityNameDisplay = (
};
export const computeEntitySearchLabels = (
stateObj: HassEntityState,
stateObj: HassEntity,
registries: HomeAssistantRegistries
) => {
const parts = computeEntityNameParts(stateObj, registries, {
@@ -221,7 +221,7 @@ export interface EntityPickerDisplayOptions extends HomeAssistantRegistries {
export const computeEntityPickerDisplay = (
options: EntityPickerDisplayOptions,
stateObj: HassEntityState
stateObj: HassEntity
): EntityPickerDisplay => {
const parts = computeEntityNameParts(stateObj, options);
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { UNAVAILABLE, UNKNOWN } from "../../data/entity/entity";
import type { HomeAssistantFormatters } from "../../types";
import { unitFromParts } from "./value_parts";
@@ -19,7 +19,7 @@ interface EntityUnitStubConfig {
*/
export const computeEntityUnitDisplay = (
formatters: HomeAssistantFormatters,
stateObj: HassEntityState | undefined,
stateObj: HassEntity | undefined,
config: EntityUnitStubConfig
): string => {
if (
+5 -5
View File
@@ -1,5 +1,5 @@
import { parseISO } from "date-fns";
import type { HassConfig, HassEntityState } from "home-assistant-js-websocket";
import type { HassConfig, HassEntity } from "home-assistant-js-websocket";
import { UNAVAILABLE, UNKNOWN } from "../../data/entity/entity";
import type { EntityRegistryDisplayEntry } from "../../data/entity/entity_registry";
import type { FrontendLocaleData } from "../../data/translation";
@@ -44,7 +44,7 @@ const NUMERICAL_DOMAINS = ["counter", "input_number", "number"];
export const computeStateDisplay = (
localize: LocalizeFunc,
stateObj: HassEntityState,
stateObj: HassEntity,
locale: FrontendLocaleData,
config: HassConfig,
entities: HomeAssistant["entities"],
@@ -146,7 +146,7 @@ const computeStateToPartsFromEntityAttributes = (
minimumFractionDigits: 2,
// Override monetary options with number format
...getNumberFormatOptions(
{ state, attributes } as HassEntityState,
{ state, attributes } as HassEntity,
entity
),
});
@@ -177,7 +177,7 @@ const computeStateToPartsFromEntityAttributes = (
const value = formatNumber(
state,
locale,
getNumberFormatOptions({ state, attributes } as HassEntityState, entity)
getNumberFormatOptions({ state, attributes } as HassEntity, entity)
);
const unit =
@@ -298,7 +298,7 @@ const computeStateToPartsFromEntityAttributes = (
export const computeStateToParts = (
localize: LocalizeFunc,
stateObj: HassEntityState,
stateObj: HassEntity,
locale: FrontendLocaleData,
config: HassConfig,
entities: HomeAssistant["entities"],
+2 -2
View File
@@ -1,5 +1,5 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { computeDomain } from "./compute_domain";
export const computeStateDomain = (stateObj: HassEntityState) =>
export const computeStateDomain = (stateObj: HassEntity) =>
computeDomain(stateObj.entity_id);
+2 -2
View File
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { computeObjectId } from "./compute_object_id";
export const computeStateNameFromEntityAttributes = (
@@ -9,5 +9,5 @@ export const computeStateNameFromEntityAttributes = (
? computeObjectId(entityId).replace(/_/g, " ")
: (attributes.friendly_name ?? "").toString();
export const computeStateName = (stateObj: HassEntityState): string =>
export const computeStateName = (stateObj: HassEntity): string =>
computeStateNameFromEntityAttributes(stateObj.entity_id, stateObj.attributes);
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { AreaRegistryEntry } from "../../../data/area/area_registry";
import type { DeviceRegistryEntry } from "../../../data/device/device_registry";
import type {
@@ -19,7 +19,7 @@ interface EntityContext {
}
export const getEntityContext = (
stateObj: HassEntityState,
stateObj: HassEntity,
entities: HomeAssistant["entities"],
devices: HomeAssistant["devices"],
areas: HomeAssistant["areas"],
+3 -3
View File
@@ -9,9 +9,9 @@ import {
mdiGate,
mdiGateOpen,
} from "@mdi/js";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
export const computeOpenIcon = (stateObj: HassEntityState): string => {
export const computeOpenIcon = (stateObj: HassEntity): string => {
switch (stateObj.attributes.device_class) {
case "door":
return mdiDoorOpen;
@@ -26,7 +26,7 @@ export const computeOpenIcon = (stateObj: HassEntityState): string => {
}
};
export const computeCloseIcon = (stateObj: HassEntityState): string => {
export const computeCloseIcon = (stateObj: HassEntity): string => {
switch (stateObj.attributes.device_class) {
case "door":
return mdiDoorClosed;
+2 -5
View File
@@ -1,9 +1,6 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
export const deviceTrackerIcon = (
stateObj: HassEntityState,
state?: string
) => {
export const deviceTrackerIcon = (stateObj: HassEntity, state?: string) => {
const compareState = state ?? stateObj.state;
if (stateObj?.attributes.source_type === "router") {
return compareState === "home" ? "mdi:lan-connect" : "mdi:lan-disconnect";
+2 -2
View File
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import memoizeOne from "memoize-one";
import type { HomeAssistant } from "../../types";
import { ensureArray } from "../array/ensure-array";
@@ -68,7 +68,7 @@ export const generateEntityFilter = (
: undefined;
return (entityId: string) => {
const stateObj = states[entityId] as HassEntityState | undefined;
const stateObj = states[entityId] as HassEntity | undefined;
if (!stateObj) {
return false;
}
+2 -2
View File
@@ -1,9 +1,9 @@
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import type { GroupEntity } from "../../data/group";
import { DEFAULT_VIEW_ENTITY_ID } from "../const";
// Return an ordered array of available views
export const extractViews = (entities: HassEntityStates): GroupEntity[] => {
export const extractViews = (entities: HassEntities): GroupEntity[] => {
const views: GroupEntity[] = [];
Object.keys(entities).forEach((entityId) => {
+5 -8
View File
@@ -1,7 +1,4 @@
import type {
HassEntityStates,
HassEntityState,
} from "home-assistant-js-websocket";
import type { HassEntities, HassEntity } from "home-assistant-js-websocket";
import { computeStateDomain } from "./compute_state_domain";
export interface EntityLocation {
@@ -12,8 +9,8 @@ export interface EntityLocation {
export const findFirstActiveZone = (
inZones: readonly string[],
states: HassEntityStates
): HassEntityState | undefined => {
states: HassEntities
): HassEntity | undefined => {
for (const zoneId of inZones) {
const zone = states[zoneId];
if (
@@ -29,8 +26,8 @@ export const findFirstActiveZone = (
};
export const getEntityLocation = (
stateObj: HassEntityState,
states: HassEntityStates
stateObj: HassEntity,
states: HassEntities
): EntityLocation | undefined => {
const {
latitude,
+2 -2
View File
@@ -1,8 +1,8 @@
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import type { GroupEntity } from "../../data/group";
export const getGroupEntities = (
entities: HassEntityStates,
entities: HassEntities,
group: GroupEntity
) => {
const result = {};
+4 -7
View File
@@ -1,7 +1,4 @@
import type {
HassEntityStates,
HassEntityState,
} from "home-assistant-js-websocket";
import type { HassEntities, HassEntity } from "home-assistant-js-websocket";
import { HVAC_MODES } from "../../data/climate";
import { UNAVAILABLE, UNKNOWN } from "../../data/entity/entity";
import { OPERATION_MODES } from "../../data/water_heater";
@@ -252,7 +249,7 @@ const FIXED_DOMAIN_ATTRIBUTE_STATES = {
};
export const getStatesDomain = (
states: HassEntityStates,
states: HassEntities,
language: string,
domain: string,
attribute?: string | undefined
@@ -411,9 +408,9 @@ export const getValueAttribute = (
): string | undefined => DOMAIN_VALUE_ATTRIBUTES[domain]?.[optionsAttribute];
export const getStates = (
states: HassEntityStates,
states: HassEntities,
language: string,
stateObj: HassEntityState,
stateObj: HassEntity,
attribute: string | undefined = undefined
): string[] => {
const domain = computeStateDomain(stateObj);
-2
View File
@@ -3,7 +3,6 @@ import { ClimateEntityFeature } from "../../data/feature/climate_entity_feature"
import { CoverEntityFeature } from "../../data/feature/cover_entity_feature";
import { MediaPlayerEntityFeature } from "../../data/feature/media-player_entity_feature";
import { SirenEntityFeature } from "../../data/feature/siren_entity_feature";
import { ValveEntityFeature } from "../../data/feature/valve_entity_feature";
// These are domains which have nonstandard 'toggle' behavior.
// Otherwise, any domain with a turn_on and turn_off service may be toggled.
@@ -59,7 +58,6 @@ export const SPECIAL_TOGGLE_ACTIONS: Record<string, SpecialToggleAction> = {
valve: {
on: "open_valve",
off: "close_valve",
feature: [ValveEntityFeature.OPEN, ValveEntityFeature.CLOSE],
},
};
+3 -3
View File
@@ -1,4 +1,4 @@
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import type { GroupEntity } from "../../data/group";
import { computeDomain } from "./compute_domain";
import { getGroupEntities } from "./get_group_entities";
@@ -6,9 +6,9 @@ import { getGroupEntities } from "./get_group_entities";
// Return an object containing all entities that the view will show
// including embedded groups.
export const getViewEntities = (
entities: HassEntityStates,
entities: HassEntities,
view: GroupEntity
): HassEntityStates => {
): HassEntities => {
const viewEntities = {};
view.attributes.entity_id.forEach((entityId) => {
+3 -5
View File
@@ -1,12 +1,10 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { UNAVAILABLE, UNKNOWN } from "../../data/entity/entity";
import type { HomeAssistant } from "../../types";
import { computeStateDomain } from "./compute_state_domain";
import { getToggleAction } from "./get_toggle_action";
export const computeGroupEntitiesState = (
states: HassEntityState[]
): string => {
export const computeGroupEntitiesState = (states: HassEntity[]): string => {
if (!states.length) {
return UNAVAILABLE;
}
@@ -46,7 +44,7 @@ export const computeGroupEntitiesState = (
export const toggleGroupEntities = (
hass: Pick<HomeAssistant, "callService">,
states: HassEntityState[]
states: HassEntity[]
) => {
if (!states.length) {
return;
+2 -2
View File
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
export const hasLocation = (stateObj: HassEntityState) =>
export const hasLocation = (stateObj: HassEntity) =>
"latitude" in stateObj.attributes && "longitude" in stateObj.attributes;
+3 -3
View File
@@ -1,13 +1,13 @@
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import type { GroupEntity } from "../../data/group";
import { computeDomain } from "./compute_domain";
// Split a collection into a list of groups and a 'rest' list of ungrouped
// entities.
// Returns { groups: [], ungrouped: {} }
export const splitByGroups = (entities: HassEntityStates) => {
export const splitByGroups = (entities: HassEntities) => {
const groups: GroupEntity[] = [];
const ungrouped: HassEntityStates = {};
const ungrouped: HassEntities = {};
Object.keys(entities).forEach((entityId) => {
const entity = entities[entityId];
+2 -5
View File
@@ -1,12 +1,9 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { OFF, UNAVAILABLE, UNKNOWN } from "../../data/entity/entity";
import { computeDomain } from "./compute_domain";
import { TIMESTAMP_STATE_DOMAINS } from "../const";
export function stateActive(
stateObj: HassEntityState,
state?: string
): boolean {
export function stateActive(stateObj: HassEntity, state?: string): boolean {
const domain = computeDomain(stateObj.entity_id);
const compareState = state !== undefined ? state : stateObj?.state;
+4 -4
View File
@@ -1,6 +1,6 @@
import type {
HassEntityStates,
HassEntityState,
HassEntities,
HassEntity,
HassServices,
} from "home-assistant-js-websocket";
import { UNAVAILABLE } from "../../data/entity/entity";
@@ -9,9 +9,9 @@ import { canToggleState } from "./can_toggle_state";
import { computeStateDomain } from "./compute_state_domain";
export const stateCardType = (
states: HassEntityStates,
states: HassEntities,
services: HassServices,
stateObj: HassEntityState
stateObj: HassEntity
) => {
if (stateObj.state === UNAVAILABLE) {
return "display";
+5 -5
View File
@@ -1,5 +1,5 @@
/** Return a color representing a state. */
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { UNAVAILABLE } from "../../data/entity/entity";
import type { GroupEntity } from "../../data/group";
import { computeGroupDomain } from "../../data/group";
@@ -44,7 +44,7 @@ const STATE_COLORED_DOMAIN = new Set([
"weather",
]);
export const stateColorCss = (stateObj: HassEntityState, state?: string) => {
export const stateColorCss = (stateObj: HassEntity, state?: string) => {
const compareState = state !== undefined ? state : stateObj?.state;
if (compareState === UNAVAILABLE) {
return `var(--state-unavailable-color)`;
@@ -60,7 +60,7 @@ export const stateColorCss = (stateObj: HassEntityState, state?: string) => {
export const domainStateColorProperties = (
domain: string,
stateObj: HassEntityState,
stateObj: HassEntity,
state?: string
): string[] => {
const compareState = state !== undefined ? state : stateObj.state;
@@ -99,7 +99,7 @@ export const domainColorProperties = (
};
export const stateColorProperties = (
stateObj: HassEntityState,
stateObj: HassEntity,
state?: string
): string[] | undefined => {
const compareState = state !== undefined ? state : stateObj?.state;
@@ -129,7 +129,7 @@ export const stateColorProperties = (
return undefined;
};
export const stateColorBrightness = (stateObj: HassEntityState): string => {
export const stateColorBrightness = (stateObj: HassEntity): string => {
if (
stateObj.attributes.brightness &&
computeDomain(stateObj.entity_id) !== "plant"
+2 -2
View File
@@ -1,10 +1,10 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { computeStateDomain } from "./compute_state_domain";
import { updateIcon } from "./update_icon";
import { deviceTrackerIcon } from "./device_tracker_icon";
export const stateIcon = (
stateObj: HassEntityState,
stateObj: HassEntity,
state?: string
): string | undefined => {
const domain = computeStateDomain(stateObj);
+2 -2
View File
@@ -1,7 +1,7 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
export const supportsFeature = (
stateObj: HassEntityState,
stateObj: HassEntity,
feature: number
): boolean => supportsFeatureFromAttributes(stateObj.attributes, feature);
+2 -2
View File
@@ -1,8 +1,8 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { UpdateEntity } from "../../data/update";
import { updateIsInstalling } from "../../data/update";
export const updateIcon = (stateObj: HassEntityState, state?: string) => {
export const updateIcon = (stateObj: HassEntity, state?: string) => {
const compareState = state ?? stateObj.state;
// An install can be in progress even when the state is "off", e.g. when
// downgrading firmware. Show the installing icon regardless of state.
@@ -1,5 +1,4 @@
import { html } from "lit";
import type { HassConfig } from "home-assistant-js-websocket";
import { getConfigEntries } from "../../data/config_entries";
import { domainToName } from "../../data/integration";
import { getIntegrationDescriptions } from "../../data/integrations";
@@ -7,11 +6,7 @@ import { showConfigFlowDialog } from "../../dialogs/config-flow/show-dialog-conf
import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box";
import { showMatterAddDeviceDialog } from "../../panels/config/integrations/integration-panels/matter/show-dialog-add-matter-device";
import { showZWaveJSAddNodeDialog } from "../../panels/config/integrations/integration-panels/zwave_js/add-node/show-dialog-zwave_js-add-node";
import type { LocalizeFunc } from "../translations/localize";
import type {
HomeAssistantApi,
HomeAssistantInternationalization,
} from "../../types";
import type { HomeAssistant } from "../../types";
import { documentationUrl } from "../../util/documentation-url";
import { isComponentLoaded } from "../config/is_component_loaded";
import { navigate } from "../navigate";
@@ -20,20 +15,17 @@ export const PROTOCOL_INTEGRATIONS = ["zha", "zwave_js", "matter"] as const;
export const protocolIntegrationPicked = async (
element: HTMLElement,
callWS: HomeAssistantApi["callWS"],
localize: LocalizeFunc,
loadBackendTranslation: HomeAssistantInternationalization["loadBackendTranslation"],
hassConfig: HassConfig,
hass: HomeAssistant,
domain: string,
options?: { brand?: string; domain?: string; config_entry?: string }
) => {
if (options?.domain) {
const titleLocalize = await loadBackendTranslation("title", options.domain);
options.domain = domainToName(titleLocalize, options.domain);
const localize = await hass.loadBackendTranslation("title", options.domain);
options.domain = domainToName(localize, options.domain);
}
if (options?.brand) {
const integrationDescriptions = await getIntegrationDescriptions(callWS);
const integrationDescriptions = await getIntegrationDescriptions(hass);
options.brand =
integrationDescriptions.core.integration[options.brand]?.name ||
options.brand;
@@ -43,40 +35,37 @@ export const protocolIntegrationPicked = async (
const entries = options?.config_entry
? undefined
: (
await getConfigEntries(
{ callWS },
{
domain,
}
)
await getConfigEntries(hass, {
domain,
})
).filter((e) => !e.disabled_by);
if (
!isComponentLoaded(hassConfig, "zwave_js") ||
!isComponentLoaded(hass.config, "zwave_js") ||
(!options?.config_entry && !entries?.length)
) {
// If the component isn't loaded, ask them to load the integration first
showConfirmationDialog(element, {
title: localize(
title: hass.localize(
"ui.panel.config.integrations.config_flow.missing_zwave_zigbee_title",
{ integration: "Z-Wave" }
),
text: localize(
text: hass.localize(
"ui.panel.config.integrations.config_flow.missing_zwave_zigbee",
{
integration: "Z-Wave",
brand: options?.brand || options?.domain || "Z-Wave",
supported_hardware_link: html`<a
href=${documentationUrl({ config: hassConfig }, "/docs/z-wave/controllers")}
href=${documentationUrl(hass, "/docs/z-wave/controllers")}
target="_blank"
rel="noreferrer"
>${localize(
>${hass.localize(
"ui.panel.config.integrations.config_flow.supported_hardware"
)}</a
>`,
}
),
confirmText: localize(
confirmText: hass.localize(
"ui.panel.config.integrations.config_flow.proceed"
),
confirm: () => {
@@ -95,43 +84,40 @@ export const protocolIntegrationPicked = async (
const entries = options?.config_entry
? undefined
: (
await getConfigEntries(
{ callWS },
{
domain,
}
)
await getConfigEntries(hass, {
domain,
})
).filter((e) => !e.disabled_by);
if (
!isComponentLoaded(hassConfig, "zha") ||
!isComponentLoaded(hass.config, "zha") ||
(!options?.config_entry && !entries?.length)
) {
// If the component isn't loaded, ask them to load the integration first
showConfirmationDialog(element, {
title: localize(
title: hass.localize(
"ui.panel.config.integrations.config_flow.missing_zwave_zigbee_title",
{ integration: "Zigbee" }
),
text: localize(
text: hass.localize(
"ui.panel.config.integrations.config_flow.missing_zwave_zigbee",
{
integration: "Zigbee",
brand: options?.brand || options?.domain || "Zigbee",
supported_hardware_link: html`<a
href=${documentationUrl(
{ config: hassConfig },
hass,
"/integrations/zha/#known-working-zigbee-radio-modules"
)}
target="_blank"
rel="noreferrer"
>${localize(
>${hass.localize(
"ui.panel.config.integrations.config_flow.supported_hardware"
)}</a
>`,
}
),
confirmText: localize(
confirmText: hass.localize(
"ui.panel.config.integrations.config_flow.proceed"
),
confirm: () => {
@@ -148,39 +134,36 @@ export const protocolIntegrationPicked = async (
const entries = options?.config_entry
? undefined
: (
await getConfigEntries(
{ callWS },
{
domain,
}
)
await getConfigEntries(hass, {
domain,
})
).filter((e) => !e.disabled_by);
if (
!isComponentLoaded(hassConfig, domain) ||
!isComponentLoaded(hass.config, domain) ||
(!options?.config_entry && !entries?.length)
) {
// If the component isn't loaded, ask them to load the integration first
showConfirmationDialog(element, {
title: localize(
title: hass.localize(
"ui.panel.config.integrations.config_flow.missing_zwave_zigbee_title",
{ integration: "Matter" }
),
text: localize(
text: hass.localize(
"ui.panel.config.integrations.config_flow.missing_matter",
{
integration: "Matter",
brand: options?.brand || options?.domain || "Matter",
supported_hardware_link: html`<a
href=${documentationUrl({ config: hassConfig }, "/integrations/matter")}
href=${documentationUrl(hass, "/integrations/matter")}
target="_blank"
rel="noreferrer"
>${localize(
>${hass.localize(
"ui.panel.config.integrations.config_flow.supported_hardware"
)}</a
>`,
}
),
confirmText: localize(
confirmText: hass.localize(
"ui.panel.config.integrations.config_flow.proceed"
),
confirm: () => {
+3 -1
View File
@@ -1,6 +1,5 @@
import {
closeAllDialogs,
DIALOG_WAIT_TIMEOUT,
updateClosedDialogSearch,
} from "../dialogs/make-dialog-manager";
import { fireEvent } from "./dom/fire_event";
@@ -26,6 +25,9 @@ export interface NavigateOptions {
keepDialogs?: boolean;
}
// max time to wait for dialogs to close before navigating
const DIALOG_WAIT_TIMEOUT = 500;
/**
* State of the current history entry. Always read through this, the app writes
* to the main window and a panel running in an iframe has its own history.
+5 -5
View File
@@ -1,6 +1,6 @@
import type {
HassEntityState,
HassEntityStateAttributeBase,
HassEntity,
HassEntityAttributeBase,
} from "home-assistant-js-websocket";
import type { EntityRegistryDisplayEntry } from "../../data/entity/entity_registry";
import type { FrontendLocaleData } from "../../data/translation";
@@ -12,11 +12,11 @@ import { blankBeforeUnit } from "../translations/blank_before_unit";
* Returns true if the entity is considered numeric based on the attributes it has
* @param stateObj The entity state object
*/
export const isNumericState = (stateObj: HassEntityState): boolean =>
export const isNumericState = (stateObj: HassEntity): boolean =>
isNumericFromAttributes(stateObj.attributes);
export const isNumericFromAttributes = (
attributes: HassEntityStateAttributeBase
attributes: HassEntityAttributeBase
): boolean => !!attributes.unit_of_measurement || !!attributes.state_class;
export const numberFormatToLocale = (
@@ -152,7 +152,7 @@ export const formatNumberToParts = (
* @returns An `Intl.NumberFormatOptions` object with `maximumFractionDigits` set to 0, or `undefined`
*/
export const getNumberFormatOptions = (
entityState?: HassEntityState,
entityState?: HassEntity,
entity?: EntityRegistryDisplayEntry
): Intl.NumberFormatOptions | undefined => {
const precision = entity?.display_precision;
+7 -7
View File
@@ -1,4 +1,4 @@
import type { HassConfig, HassEntityState } from "home-assistant-js-websocket";
import type { HassConfig, HassEntity } from "home-assistant-js-websocket";
import type { FrontendLocaleData } from "../../data/translation";
import type { HomeAssistant, ValuePart } from "../../types";
import {
@@ -9,30 +9,30 @@ import {
import type { LocalizeFunc } from "./localize";
export type FormatEntityStateFunc = (
stateObj: HassEntityState,
stateObj: HassEntity,
state?: string
) => string;
export type FormatEntityStateToPartsFunc = (
stateObj: HassEntityState,
stateObj: HassEntity,
state?: string
) => ValuePart[];
export type FormatEntityAttributeValueFunc = (
stateObj: HassEntityState,
stateObj: HassEntity,
attribute: string,
value?: any
) => string;
export type FormatEntityAttributeValueToPartsFunc = (
stateObj: HassEntityState,
stateObj: HassEntity,
attribute: string,
value?: any
) => ValuePart[];
export type FormatEntityAttributeNameFunc = (
stateObj: HassEntityState,
stateObj: HassEntity,
attribute: string
) => string;
export type FormatEntityNameFunc = (
stateObj: HassEntityState,
stateObj: HassEntity,
name?: string | EntityNameItem | EntityNameItem[],
options?: EntityNameOptions
) => string;
@@ -1,6 +1,6 @@
import type { LineSeriesOption } from "echarts/charts";
import type { VisualMapComponentOption } from "echarts/components";
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import { getGraphColorByIndex } from "../../common/color/colors";
import { CLIMATE_HVAC_ACTION_TO_MODE } from "../../data/climate";
import type { LineChartEntity, LineChartState } from "../../data/history";
@@ -21,7 +21,7 @@ export const CLIMATE_MODE_CONFIGS = [
export interface StateHistoryChartLineDataParams {
localize: LocalizeFunc;
states: HassEntityStates;
states: HassEntities;
data: LineChartEntity[];
endTime: Date;
names?: Record<string, string>;
@@ -1,4 +1,4 @@
import type { HassConfig, HassEntityStates } from "home-assistant-js-websocket";
import type { HassConfig, HassEntities } from "home-assistant-js-websocket";
import type { PropertyValues, TemplateResult } from "lit";
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -145,7 +145,7 @@ export class StateHistoryChartLine extends LitElement {
private _entities!: HomeAssistant["entities"];
@consume({ context: statesContext, subscribe: true })
private _states?: HassEntityStates;
private _states?: HassEntities;
private _optionsEntityStates: Record<string, string | undefined> = {};
@@ -2,7 +2,7 @@ import type {
CustomSeriesOption,
CustomSeriesRenderItem,
} from "echarts/types/dist/shared";
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import { hex2rgb } from "../../common/color/convert-color";
import { luminosity } from "../../common/color/rgb";
import type { TimelineEntity } from "../../data/history";
@@ -10,7 +10,7 @@ import { snapFrameSize } from "./down-sample";
import { computeTimelineColor } from "./timeline-color";
export interface StateHistoryChartTimelineDataParams {
states: HassEntityStates;
states: HassEntities;
data: TimelineEntity[];
startTime: Date;
endTime: Date;
@@ -1,4 +1,4 @@
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -88,7 +88,7 @@ export class StateHistoryChartTimeline extends LitElement {
private _hassConfig!: HomeAssistantConfig;
@consume({ context: statesContext, subscribe: true })
private _states?: HassEntityStates;
private _states?: HassEntities;
protected render() {
return html`
@@ -3,7 +3,7 @@ import type {
LineSeriesOption,
ZRColor,
} from "echarts/types/dist/shared";
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import { getGraphColorByIndex } from "../../common/color/colors";
import type { LocalizeFunc } from "../../common/translations/localize";
import type {
@@ -30,7 +30,7 @@ export interface StatisticsChartLegendItem {
}
export interface StatisticsChartDataParams {
states: HassEntityStates;
states: HassEntities;
formatEntityName: HomeAssistantFormatters["formatEntityName"];
localize: LocalizeFunc;
statisticsData: Statistics;
+2 -2
View File
@@ -2,7 +2,7 @@ import type {
BarSeriesOption,
LineSeriesOption,
} from "echarts/types/dist/shared";
import type { HassConfig, HassEntityStates } from "home-assistant-js-websocket";
import type { HassConfig, HassEntities } from "home-assistant-js-websocket";
import type { PropertyValues, TemplateResult } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
@@ -186,7 +186,7 @@ export class StatisticsChart extends LitElement {
private _themes!: Themes;
@consume({ context: statesContext, subscribe: true })
private _states!: HassEntityStates;
private _states!: HassEntities;
@consume({ context: entitiesContext, subscribe: true })
private _entities!: HomeAssistant["entities"];
+4 -4
View File
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { getGraphColorByIndex } from "../../common/color/colors";
import { hex2rgb, lab2hex, rgb2lab } from "../../common/color/convert-color";
import { labBrighten } from "../../common/color/lab";
@@ -23,7 +23,7 @@ const DOMAIN_STATE_SHADES: Record<string, Record<string, number>> = {
function computeTimelineStateColor(
state: string,
computedStyles: CSSStyleDeclaration,
stateObj?: HassEntityState
stateObj?: HassEntity
): string | undefined {
if (!stateObj || state === UNAVAILABLE) {
return computeCssValue("--history-unavailable-color", computedStyles);
@@ -74,7 +74,7 @@ const stateColorMap = new Map<string, string>();
function computeTimelineEnumColor(
state: string,
computedStyles: CSSStyleDeclaration,
stateObj?: HassEntityState
stateObj?: HassEntity
): string | undefined {
if (!stateObj) {
return undefined;
@@ -111,7 +111,7 @@ function computeTimeLineGenericColor(
export function computeTimelineColor(
state: string,
computedStyles: CSSStyleDeclaration,
stateObj?: HassEntityState
stateObj?: HassEntity
): string {
return (
computeTimelineStateColor(state, computedStyles, stateObj) ||
@@ -1,6 +1,6 @@
import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize";
import type { ContextType } from "@lit/context";
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { html, LitElement, nothing } from "lit";
import { property, state } from "lit/decorators";
@@ -69,13 +69,13 @@ export abstract class HaDeviceAutomationPicker<
@state()
@consume({ context: statesContext, subscribe: true })
@transform<HassEntityStates, HassEntityStates>({
@transform<HassEntities, HassEntities>({
transformer: function (
this: HaDeviceAutomationPicker<DeviceAutomation>,
states
) {
const registryById = entityRegistryById(this._entityReg ?? []);
const picked: HassEntityStates = {};
const picked: HassEntities = {};
[...(this._automations ?? []), this.value].forEach((automation) => {
const id = automation?.entity_id;
const entityId = id?.includes(".")
@@ -89,7 +89,7 @@ export abstract class HaDeviceAutomationPicker<
},
watch: ["_automations", "value", "_entityReg"],
})
private _states: HassEntityStates = {};
private _states: HassEntities = {};
@state()
@consume({ context: formattersContext, subscribe: true })
@@ -119,7 +119,7 @@ export abstract class HaDeviceAutomationPicker<
private _localizeDeviceAutomation: (
localize: LocalizeFunc,
states: HassEntityStates,
states: HassEntities,
formatEntityName: HomeAssistantFormatters["formatEntityName"],
entityRegistry: EntityRegistryEntry[],
automation: T
@@ -214,7 +214,7 @@ export abstract class HaDeviceAutomationPicker<
automations: T[] | undefined,
localize: LocalizeFunc,
language: string,
states: HassEntityStates,
states: HassEntities,
formatEntityName: HomeAssistantFormatters["formatEntityName"],
entityReg: EntityRegistryEntry[]
) => {
+2 -4
View File
@@ -1,6 +1,6 @@
import { mdiSwapHorizontal } from "@mdi/js";
import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { css, html, LitElement, nothing, type PropertyValues } from "lit";
import type { ContextType } from "@lit/context";
import { customElement, property, query, state } from "lit/decorators";
@@ -55,9 +55,7 @@ export type HaDevicePickerDeviceFilterFunc = (
device: DeviceRegistryEntry
) => boolean;
export type HaDevicePickerEntityFilterFunc = (
entity: HassEntityState
) => boolean;
export type HaDevicePickerEntityFilterFunc = (entity: HassEntity) => boolean;
@customElement("ha-device-picker")
export class HaDevicePicker extends LitElement {
+3 -4
View File
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { batteryLevelIcon } from "../../common/entity/battery_icon";
@@ -6,10 +6,9 @@ import "../ha-icon";
@customElement("ha-battery-icon")
export class HaBatteryIcon extends LitElement {
@property({ attribute: false }) public batteryStateObj?: HassEntityState;
@property({ attribute: false }) public batteryStateObj?: HassEntity;
@property({ attribute: false })
public batteryChargingStateObj?: HassEntityState;
@property({ attribute: false }) public batteryChargingStateObj?: HassEntity;
protected render() {
if (!this.batteryStateObj) return nothing;
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { LitElement, html } from "lit";
import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
@@ -50,7 +50,7 @@ class HaEntityAttributePicker extends LitElement {
@state()
@consumeEntityStates({ entityIdPath: ["entityId"] })
private _stateObjs?: Record<string, HassEntityState>;
private _stateObjs?: Record<string, HassEntity>;
@state()
@consume({ context: formattersContext, subscribe: true })
@@ -64,7 +64,7 @@ class HaEntityAttributePicker extends LitElement {
private _getItemsMemoized = memoizeOne(
(
entityId: string | string[] | undefined,
stateObjs: Record<string, HassEntityState> | undefined,
stateObjs: Record<string, HassEntity> | undefined,
hideAttributes: string[] | undefined,
formatEntityAttributeName: FormatEntityAttributeName
): PickerComboBoxItem[] => {
@@ -1,7 +1,7 @@
import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize";
import type { ContextType } from "@lit/context";
import { mdiDragHorizontalVariant, mdiPlus, mdiRestore } from "@mdi/js";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
@@ -101,7 +101,7 @@ export class HaEntityNamePicker extends LitElement {
@state()
@consumeEntityState({ entityIdPath: ["entityId"] })
private _stateObj?: HassEntityState;
private _stateObj?: HassEntity;
@state()
@consume({ context: registriesContext, subscribe: true })
@@ -423,7 +423,7 @@ export class HaEntityNamePicker extends LitElement {
private _defaultItems = memoizeOne(
(
stateObj: HassEntityState | undefined,
stateObj: HassEntity | undefined,
registries: ContextType<typeof registriesContext>
): EntityNameItem[] => {
if (!stateObj) {
@@ -470,7 +470,7 @@ export class HaEntityNamePicker extends LitElement {
private _validTypes = memoizeOne(
(
stateObj: HassEntityState | undefined,
stateObj: HassEntity | undefined,
registries: ContextType<typeof registriesContext>
) => {
if (!stateObj) {
@@ -497,7 +497,7 @@ export class HaEntityNamePicker extends LitElement {
private _getItems = memoizeOne(
(
stateObj: HassEntityState | undefined,
stateObj: HassEntity | undefined,
registries: ContextType<typeof registriesContext>,
localize: LocalizeFunc,
formatEntityName: HomeAssistantFormatters["formatEntityName"]
@@ -1,6 +1,6 @@
import type { ContextType } from "@lit/context";
import { mdiDragHorizontalVariant, mdiPlus } from "@mdi/js";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { repeat } from "lit/directives/repeat";
@@ -118,7 +118,7 @@ export class HaStateContentPicker extends LitElement {
@state()
@consumeEntityState({ entityIdPath: ["entityId"] })
private _stateObj?: HassEntityState;
private _stateObj?: HassEntity;
@state()
@consume({ context: registriesContext, subscribe: true })
@@ -138,7 +138,7 @@ export class HaStateContentPicker extends LitElement {
private _getItems = memoizeOne(
(
entityId: string | undefined,
stateObj: HassEntityState | undefined,
stateObj: HassEntity | undefined,
allowName: boolean,
allowContext: boolean,
localize: LocalizeFunc,
@@ -1,8 +1,5 @@
import type { ContextType } from "@lit/context";
import type {
HassEntityStates,
HassEntityState,
} from "home-assistant-js-websocket";
import type { HassEntities, HassEntity } from "home-assistant-js-websocket";
import { LitElement, html } from "lit";
import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
@@ -48,7 +45,7 @@ const keepsStatesOrder = (
};
export const computeEntityStateItems = (
states: HassEntityStates | null | undefined,
states: HassEntities | null | undefined,
formatters: HomeAssistantFormatters,
language: string,
entityId: string | string[] | undefined,
@@ -58,11 +55,11 @@ export const computeEntityStateItems = (
): PickerComboBoxItem[] => {
const entityIds = entityId ? ensureArray(entityId) : [];
const stateObjsByState = new Map<string, HassEntityState>();
const stateObjsByState = new Map<string, HassEntity>();
for (const entityIdItem of entityIds) {
const stateObj =
states?.[entityIdItem] ||
({ entity_id: entityIdItem, attributes: {} } as HassEntityState);
({ entity_id: entityIdItem, attributes: {} } as HassEntity);
const entityStates = getStates(states ?? {}, language, stateObj, attribute);
for (const s of entityStates) {
if (!hideStates?.includes(s) && !stateObjsByState.has(s)) {
@@ -108,7 +105,7 @@ export const computeEntityStateItems = (
export const computeDefaultStateLabel = (
i18n: ContextType<typeof internationalizationContext>,
formatters: HomeAssistantFormatters,
stateObjs: Record<string, HassEntityState> | undefined,
stateObjs: Record<string, HassEntity> | undefined,
entityId: string | string[] | undefined,
attribute: string | undefined
): string => {
@@ -151,7 +148,7 @@ export class HaEntityStatePicker extends LitElement {
@state()
@consumeEntityStates({ entityIdPath: ["entityId"] })
private _stateObjs?: Record<string, HassEntityState>;
private _stateObjs?: Record<string, HassEntity>;
@consume({ context: statesContext, subscribe: true })
private _states?: ContextType<typeof statesContext>;
@@ -1,8 +1,5 @@
import type { ContextType } from "@lit/context";
import type {
HassEntityStates,
HassEntityState,
} from "home-assistant-js-websocket";
import type { HassEntities, HassEntity } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -56,7 +53,7 @@ export class HaEntityStatesPicker extends LitElement {
@state()
@consumeEntityStates({ entityIdPath: ["entityId"] })
private _stateObjs?: Record<string, HassEntityState>;
private _stateObjs?: Record<string, HassEntity>;
@consume({ context: statesContext, subscribe: true })
private _states?: ContextType<typeof statesContext>;
@@ -71,7 +68,7 @@ export class HaEntityStatesPicker extends LitElement {
private _chipsSelector = memoizeOne(
(
states: HassEntityStates | null | undefined,
states: HassEntities | null | undefined,
formatters: HomeAssistantFormatters,
language: string,
entityId: string | string[] | undefined,
+3 -3
View File
@@ -1,6 +1,6 @@
import type { ContextType } from "@lit/context";
import { mdiFlash, mdiFlashOff } from "@mdi/js";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { PropertyValues, TemplateResult } from "lit";
import { LitElement, css, html } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -16,7 +16,7 @@ import "../ha-switch";
import { getToggleAction } from "../../common/entity/get_toggle_action";
import type { LocalizeFunc } from "../../common/translations/localize";
const isOn = (stateObj?: HassEntityState) =>
const isOn = (stateObj?: HassEntity) =>
stateObj !== undefined &&
!STATES_OFF.includes(stateObj.state) &&
stateObj.state !== UNAVAILABLE &&
@@ -43,7 +43,7 @@ export class HaEntityToggle extends LitElement {
@consumeLocalize()
private _localize!: LocalizeFunc;
@property({ attribute: false }) public stateObj?: HassEntityState;
@property({ attribute: false }) public stateObj?: HassEntity;
@property() public label?: string;
@@ -1,6 +1,6 @@
import type { ContextType } from "@lit/context";
import { mdiDelete } from "@mdi/js";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { consume } from "../../common/decorators/consume";
@@ -32,7 +32,7 @@ export class HaFavoriteEntityListItem extends LitElement {
@state()
@consumeEntityState({ entityIdPath: ["entityId"] })
private _stateObj?: HassEntityState;
private _stateObj?: HassEntity;
@state()
@consume({ context: registriesContext, subscribe: true })
@@ -1,6 +1,6 @@
import type { ContextType } from "@lit/context";
import { mdiAlert } from "@mdi/js";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { PropertyValues, TemplateResult } from "lit";
import { css, html, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -57,7 +57,7 @@ export class HaStateLabelBadge extends LitElement {
@consumeEntityRegistryEntry({ entityIdPath: ["state", "entity_id"] })
private _entry?: EntityRegistryDisplayEntry;
@property({ attribute: false }) public state?: HassEntityState;
@property({ attribute: false }) public state?: HassEntity;
@property() public name?: string;
@@ -170,7 +170,7 @@ export class HaStateLabelBadge extends LitElement {
private _computeValue(
domain: string,
entityState: HassEntityState,
entityState: HassEntity,
entry?: EntityRegistryDisplayEntry
) {
switch (domain) {
@@ -203,7 +203,7 @@ export class HaStateLabelBadge extends LitElement {
private _computeShowIcon(
domain: string,
entityState: HassEntityState,
entityState: HassEntity,
entry?: EntityRegistryDisplayEntry
): boolean {
if (entityState.state === UNAVAILABLE) {
@@ -228,7 +228,7 @@ export class HaStateLabelBadge extends LitElement {
private _computeLabel(
domain: string,
entityState: HassEntityState,
entityState: HassEntity,
_timerTimeRemaining = 0
) {
// For unavailable states or certain domains, use a special translation that is truncated to fit within the badge label
+2 -2
View File
@@ -6,7 +6,7 @@ import {
mdiPencil,
mdiShape,
} from "@mdi/js";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { html, LitElement, nothing, type PropertyValues } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import memoizeOne from "memoize-one";
@@ -54,7 +54,7 @@ type StatisticItemType = "entity" | "external" | "no_state";
interface StatisticComboBoxItem extends PickerComboBoxItem {
statistic_id?: string;
stateObj?: HassEntityState;
stateObj?: HassEntity;
domainName?: string;
type?: StatisticItemType;
}
+2 -2
View File
@@ -1,6 +1,6 @@
import type { ContextType } from "@lit/context";
import { mdiAlert } from "@mdi/js";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { CSSResultGroup, PropertyValues } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -30,7 +30,7 @@ import "../ha-state-icon";
@customElement("state-badge")
export class StateBadge extends LitElement {
@property({ attribute: false }) public stateObj?: HassEntityState;
@property({ attribute: false }) public stateObj?: HassEntity;
@property({ attribute: false }) public overrideIcon?: string;
+2 -2
View File
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { styleMap } from "lit/directives/style-map";
@@ -14,7 +14,7 @@ import "./state-badge";
@customElement("state-info")
class StateInfo extends LitElement {
@property({ attribute: false }) public stateObj?: HassEntityState;
@property({ attribute: false }) public stateObj?: HassEntity;
@property({ attribute: "in-dialog", type: Boolean }) public inDialog = false;
+2 -2
View File
@@ -1,5 +1,5 @@
import type { ContextType } from "@lit/context";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import Fuse from "fuse.js";
@@ -29,7 +29,7 @@ import "./ha-state-icon";
export interface AreaControlPickerItem extends PickerComboBoxItem {
type?: "domain" | "entity";
stateObj?: HassEntityState;
stateObj?: HassEntity;
domain?: string;
deviceClass?: string;
}
+2 -2
View File
@@ -1,6 +1,6 @@
import type { ContextType } from "@lit/context";
import { mdiPlus, mdiTextureBox } from "@mdi/js";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { LitElement, html, nothing } from "lit";
import type { TemplateResult, PropertyValues } from "lit";
import { customElement, property, query, state } from "lit/decorators";
@@ -85,7 +85,7 @@ export class HaAreaPicker extends LitElement {
public deviceFilter?: HaDevicePickerDeviceFilterFunc;
@property({ attribute: false })
public entityFilter?: (entity: HassEntityState) => boolean;
public entityFilter?: (entity: HassEntity) => boolean;
@property({ type: Boolean }) public disabled = false;
+2 -2
View File
@@ -1,5 +1,5 @@
import { mdiDragHorizontalVariant } from "@mdi/js";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { fireEvent } from "../common/dom/fire_event";
@@ -48,7 +48,7 @@ export class HaAreasPicker extends LitElement {
public deviceFilter?: HaDevicePickerDeviceFilterFunc;
@property({ attribute: false })
public entityFilter?: (entity: HassEntityState) => boolean;
public entityFilter?: (entity: HassEntity) => boolean;
@property({ attribute: "picked-area-label" })
public pickedAreaLabel?: string;
+2 -2
View File
@@ -1,6 +1,6 @@
import type { ContextType } from "@lit/context";
import { initialState } from "@lit/task";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { consume } from "../common/decorators/consume";
@@ -16,7 +16,7 @@ import "./ha-svg-icon";
@customElement("ha-attribute-icon")
export class HaAttributeIcon extends LitElement {
@property({ attribute: false }) public stateObj?: HassEntityState;
@property({ attribute: false }) public stateObj?: HassEntity;
@property() public attribute?: string;
+2 -2
View File
@@ -1,6 +1,6 @@
import type { ContextType } from "@lit/context";
import { initialState } from "@lit/task";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { consume } from "../common/decorators/consume";
@@ -20,7 +20,7 @@ class HaAttributeValue extends LitElement {
@consume({ context: formattersContext, subscribe: true })
private _formatters?: ContextType<typeof formattersContext>;
@property({ attribute: false }) public stateObj?: HassEntityState;
@property({ attribute: false }) public stateObj?: HassEntity;
@property() public attribute!: string;
+2 -2
View File
@@ -22,7 +22,7 @@ import {
mdiRedo,
mdiUndo,
} from "@mdi/js";
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import type { CSSResultGroup, PropertyValues } from "lit";
import { css, html, ReactiveElement, render } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -1096,7 +1096,7 @@ export class HaCodeEditor extends ReactiveElement {
private _getStates = memoizeOne(
(
states: HassEntityStates,
states: HassEntities,
formatEntityName: HomeAssistantFormatters["formatEntityName"],
registries: HomeAssistantRegistries
): Completion[] => {
+4 -4
View File
@@ -1,5 +1,5 @@
import type { ContextType } from "@lit/context";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { TemplateResult } from "lit";
import { LitElement, html } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -26,7 +26,7 @@ export interface EntitiesDisplayValue {
export class HaEntitiesDisplayEditor extends LitElement {
@state()
@consumeEntityStates({ entityIdPath: ["entitiesIds"] })
private _entityStates?: Record<string, HassEntityState>;
private _entityStates?: Record<string, HassEntity>;
@consume({ context: entitiesContext, subscribe: true })
@state()
@@ -85,7 +85,7 @@ export class HaEntitiesDisplayEditor extends LitElement {
private _items = memoizeOne(
(
entitiesIds: string[],
entityStates: Record<string, HassEntityState> | undefined,
entityStates: Record<string, HassEntity> | undefined,
entitiesReg: ContextType<typeof entitiesContext>,
config: ContextType<typeof configContext>,
connection: ContextType<typeof connectionContext>,
@@ -93,7 +93,7 @@ export class HaEntitiesDisplayEditor extends LitElement {
): DisplayItem[] => {
const entities = entitiesIds
.map((entityId) => entityStates?.[entityId])
.filter((stateObj): stateObj is HassEntityState => Boolean(stateObj));
.filter((stateObj): stateObj is HassEntity => Boolean(stateObj));
return entities.map((entity) => ({
value: entity.entity_id,
+2 -2
View File
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { html, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators";
import { consumeEntityState } from "../common/decorators/consume-context-entry";
@@ -10,7 +10,7 @@ import "./ha-state-icon";
export class HaEntityIdIcon extends LitElement {
@state()
@consumeEntityState({ entityIdPath: ["entityId"] })
private stateObj?: HassEntityState;
private stateObj?: HassEntity;
@property({ attribute: false }) public entityId!: string;
+2 -2
View File
@@ -1,5 +1,5 @@
import type { ContextType } from "@lit/context";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { mdiFilterVariantRemove } from "@mdi/js";
import type { CSSResultGroup, PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit";
@@ -34,7 +34,7 @@ import type { HaListSelectableVirtualized } from "./list/ha-list-selectable-virt
import type { HaListVirtualizedItem } from "./list/ha-list-virtualized";
interface EntityItem extends HaListVirtualizedItem {
stateObj: HassEntityState;
stateObj: HassEntity;
name: string;
}
+2 -2
View File
@@ -1,7 +1,7 @@
import type { ContextType } from "@lit/context";
import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize";
import { mdiPlus, mdiTextureBox } from "@mdi/js";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { LitElement, html } from "lit";
import type { TemplateResult, PropertyValues } from "lit";
import { customElement, property, query, state } from "lit/decorators";
@@ -105,7 +105,7 @@ export class HaFloorPicker extends LitElement {
public deviceFilter?: HaDevicePickerDeviceFilterFunc;
@property({ attribute: false })
public entityFilter?: (entity: HassEntityState) => boolean;
public entityFilter?: (entity: HassEntity) => boolean;
@property({ type: Boolean }) public disabled = false;
+2 -2
View File
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { css, html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
import { fireEvent } from "../common/dom/fire_event";
@@ -46,7 +46,7 @@ export class HaFloorsPicker extends LitElement {
public deviceFilter?: HaDevicePickerDeviceFilterFunc;
@property({ attribute: false })
public entityFilter?: (entity: HassEntityState) => boolean;
public entityFilter?: (entity: HassEntity) => boolean;
@property({ attribute: "picked-floor-label" })
public pickedFloorLabel?: string;
+2 -2
View File
@@ -1,7 +1,7 @@
import type { ContextType } from "@lit/context";
import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize";
import { mdiPlus } from "@mdi/js";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { LitElement, html, nothing } from "lit";
import type { TemplateResult, PropertyValues } from "lit";
import {
@@ -107,7 +107,7 @@ export class HaLabelPicker extends LitElement {
public deviceFilter?: HaDevicePickerDeviceFilterFunc;
@property({ attribute: false })
public entityFilter?: (entity: HassEntityState) => boolean;
public entityFilter?: (entity: HassEntity) => boolean;
@property({ type: Boolean }) public disabled = false;
+2 -2
View File
@@ -1,6 +1,6 @@
import type { ContextType } from "@lit/context";
import { mdiPlaylistPlus } from "@mdi/js";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { TemplateResult } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
@@ -75,7 +75,7 @@ export class HaLabelsPicker extends LitElement {
public deviceFilter?: HaDevicePickerDeviceFilterFunc;
@property({ attribute: false })
public entityFilter?: (entity: HassEntityState) => boolean;
public entityFilter?: (entity: HassEntity) => boolean;
@property({ type: Boolean }) public disabled = false;
+2 -2
View File
@@ -1,5 +1,5 @@
import { mdiDelete, mdiPlayBox, mdiPlus } from "@mdi/js";
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -59,7 +59,7 @@ export class HaMediaItemPicker extends LitElement {
@state()
@consume({ context: statesContext, subscribe: true })
@transform<HassEntityStates | null, boolean>({
@transform<HassEntities | null, boolean>({
transformer: function (this: HaMediaItemPicker, states) {
const entityId = this._getActiveEntityId();
if (!entityId) {
+7 -10
View File
@@ -5,10 +5,7 @@ import {
mdiTransitConnectionVariant,
} from "@mdi/js";
import type { ContextType } from "@lit/context";
import type {
HassEntityStates,
HassEntityState,
} from "home-assistant-js-websocket";
import type { HassEntities, HassEntity } from "home-assistant-js-websocket";
import type { CSSResultGroup, PropertyValues } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -77,9 +74,9 @@ export class HaRelatedItems extends LitElement {
@state()
@consume({ context: statesContext, subscribe: true })
@transform<HassEntityStates, HassEntityStates>({
@transform<HassEntities, HassEntities>({
transformer: function (this: HaRelatedItems, states) {
const related: HassEntityStates = {};
const related: HassEntities = {};
ENTITY_SECTIONS.forEach((section) => {
this._related?.[section]?.forEach((entityId) => {
if (states?.[entityId]) {
@@ -91,7 +88,7 @@ export class HaRelatedItems extends LitElement {
},
watch: ["_related"],
})
private _states: HassEntityStates = {};
private _states: HassEntities = {};
@state()
@consume({ context: devicesContext, subscribe: true })
@@ -183,14 +180,14 @@ export class HaRelatedItems extends LitElement {
private _relatedEntities = memoizeOne(
(
related: RelatedResult,
states: HassEntityStates,
states: HassEntities,
formatEntityName: HomeAssistantFormatters["formatEntityName"],
language: string
) => {
const toEntities = (entityIds: string[] = []) =>
entityIds
.map((entityId) => states[entityId])
.filter((entity): entity is HassEntityState => entity !== undefined)
.filter((entity): entity is HassEntity => entity !== undefined)
.sort((a, b) =>
caseInsensitiveStringCompare(
formatEntityName(a),
@@ -480,7 +477,7 @@ export class HaRelatedItems extends LitElement {
`;
}
private _renderEntityRow(entity: HassEntityState) {
private _renderEntityRow(entity: HassEntity) {
return html`
<ha-list-item-button
.headline=${this._formatEntityName(entity)}
@@ -1,5 +1,5 @@
import type { ContextType } from "@lit/context";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -137,7 +137,7 @@ export class HaAreaSelector extends LitElement {
`;
}
private _filterEntities = (entity: HassEntityState): boolean => {
private _filterEntities = (entity: HassEntity): boolean => {
if (!this.selector.area?.entity) {
return true;
}
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { html, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -28,7 +28,7 @@ export class HaSelectorAttribute extends LitElement {
@state()
@consumeEntityStates({ entityIdPath: ["context", "filter_entity"] })
private _filterEntityStates?: Record<string, HassEntityState>;
private _filterEntityStates?: Record<string, HassEntity>;
protected render() {
return html`
@@ -1,4 +1,4 @@
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { html, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators";
import { styleMap } from "lit/directives/style-map";
@@ -35,7 +35,7 @@ export class HaColorTempSelector extends LitElement {
@state()
@consumeEntityStates({ entityIdPath: ["context", "filter_entity"] })
private _filterEntityStates?: Record<string, HassEntityState>;
private _filterEntityStates?: Record<string, HassEntity>;
protected render() {
const { min, max } = this._bounds();
@@ -1,5 +1,5 @@
import type { ContextType } from "@lit/context";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -153,7 +153,7 @@ export class HaDeviceSelector extends LitElement {
);
};
private _filterEntities = (entity: HassEntityState): boolean =>
private _filterEntities = (entity: HassEntity): boolean =>
ensureArray(this.selector.device!.entity).some((filter) =>
filterSelectorEntities(
filter,
@@ -1,5 +1,5 @@
import type { ContextType } from "@lit/context";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -210,7 +210,7 @@ export class HaEntitySelector extends LitElement {
entitySources: EntitySources | undefined,
configEntries: ConfigEntry[] | undefined
) =>
(entity: HassEntityState): boolean => {
(entity: HassEntity): boolean => {
if (!selector.entity?.filter) {
return true;
}
@@ -1,5 +1,5 @@
import type { ContextType } from "@lit/context";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -136,7 +136,7 @@ export class HaFloorSelector extends LitElement {
`;
}
private _filterEntities = (entity: HassEntityState): boolean => {
private _filterEntities = (entity: HassEntity): boolean => {
if (!this.selector.floor?.entity) {
return true;
}
@@ -2,7 +2,7 @@ import type { ContextType } from "@lit/context";
import { initialState } from "@lit/task";
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { consume } from "../../common/decorators/consume";
import { AsyncValueTask } from "../../common/controllers/async-value-task";
import { consumeEntityState } from "../../common/decorators/consume-context-entry";
@@ -37,7 +37,7 @@ export class HaIconSelector extends LitElement {
@state()
@consumeEntityState({ entityIdPath: ["context", "icon_entity"] })
private _stateObj?: HassEntityState;
private _stateObj?: HassEntity;
@state()
@consume({ context: entitiesContext, subscribe: true })
@@ -5,7 +5,7 @@ import {
mdiPencil,
} from "@mdi/js";
import deepClone from "deep-clone-simple";
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import { css, html, LitElement, nothing, type PropertyValues } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import memoizeOne from "memoize-one";
@@ -71,7 +71,7 @@ export class HaObjectSelector extends LitElement {
@state()
@consume({ context: statesContext, subscribe: true })
private _states!: HassEntityStates;
private _states!: HassEntities;
@state()
@consume({ context: formattersContext, subscribe: true })
@@ -265,7 +265,7 @@ export class HaObjectSelector extends LitElement {
(
i18n: HomeAssistantInternationalization,
registries: HomeAssistantRegistries,
states: HassEntityStates,
states: HassEntities,
formatEntityName: HomeAssistantFormatters["formatEntityName"]
): FormatSelectorValueOptions => ({
locale: i18n.locale,
@@ -1,5 +1,5 @@
import type { ContextType } from "@lit/context";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -149,7 +149,7 @@ export class HaTargetSelector extends LitElement {
if (!filters) {
return ALL_ENTITIES;
}
return (entity: HassEntityState): boolean =>
return (entity: HassEntity): boolean =>
ensureArray(filters).some((filter) =>
filterSelectorEntities(
filter,
+2 -2
View File
@@ -1,6 +1,6 @@
import type { ContextType } from "@lit/context";
import { initialState } from "@lit/task";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -23,7 +23,7 @@ import "./ha-svg-icon";
@customElement("ha-state-icon")
export class HaStateIcon extends LitElement {
@property({ attribute: false }) public stateObj?: HassEntityState;
@property({ attribute: false }) public stateObj?: HassEntity;
@state()
@consume({ context: formattersContext, subscribe: true })
+4 -4
View File
@@ -1,5 +1,5 @@
import type { ContextType } from "@lit/context";
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -60,9 +60,9 @@ export class HaSTTPicker extends LitElement {
@state()
@consume({ context: statesContext, subscribe: true })
@transform<HassEntityStates, HassEntityStates>({
@transform<HassEntities, HassEntities>({
transformer: function (this: HaSTTPicker, states) {
const engineStates: HassEntityStates = {};
const engineStates: HassEntities = {};
this._engines?.forEach(({ engine_id }) => {
if (states?.[engine_id]) {
engineStates[engine_id] = states[engine_id];
@@ -72,7 +72,7 @@ export class HaSTTPicker extends LitElement {
},
watch: ["_engines"],
})
private _states: HassEntityStates = {};
private _states: HassEntities = {};
@state()
@consume({ context: formattersContext, subscribe: true })
+4 -4
View File
@@ -1,5 +1,5 @@
import type { ContextType } from "@lit/context";
import type { HassEntityStates } from "home-assistant-js-websocket";
import type { HassEntities } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -60,9 +60,9 @@ export class HaTTSPicker extends LitElement {
@state()
@consume({ context: statesContext, subscribe: true })
@transform<HassEntityStates, HassEntityStates>({
@transform<HassEntities, HassEntities>({
transformer: function (this: HaTTSPicker, states) {
const engineStates: HassEntityStates = {};
const engineStates: HassEntities = {};
this._engines?.forEach(({ engine_id }) => {
if (states?.[engine_id]) {
engineStates[engine_id] = states[engine_id];
@@ -72,7 +72,7 @@ export class HaTTSPicker extends LitElement {
},
watch: ["_engines"],
})
private _states: HassEntityStates = {};
private _states: HassEntities = {};
@state()
@consume({ context: formattersContext, subscribe: true })
+2 -2
View File
@@ -2,7 +2,7 @@ import type { ContextType } from "@lit/context";
import type { CSSResultGroup, TemplateResult } from "lit";
import { LitElement, css, html } from "lit";
import { customElement, property, state } from "lit/decorators";
import type { HassEntityState } from "home-assistant-js-websocket";
import type { HassEntity } from "home-assistant-js-websocket";
import { consume } from "../common/decorators/consume";
import { consumeLocalize } from "../common/decorators/consume-context-entry";
import type { LocalizeFunc } from "../common/translations/localize";
@@ -55,7 +55,7 @@ export class HaVacuumState extends LitElement {
@consume({ context: apiContext, subscribe: true })
private _api!: ContextType<typeof apiContext>;
@property({ attribute: false }) public stateObj!: HassEntityState;
@property({ attribute: false }) public stateObj!: HassEntity;
protected render(): TemplateResult {
const interceptable = this._computeInterceptable(
Loaded 100 of 489 files, more files were not shown because too many files have changed in this diff. Show more