Skip to content

Commit

Permalink
20240906.0 (#21911)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Sep 6, 2024
2 parents b457d27 + 30d9186 commit ba770f8
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 75 deletions.
3 changes: 3 additions & 0 deletions gallery/src/pages/components/ha-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const DEVICES: DeviceRegistryEntry[] = [
labels: [],
created_at: 0,
modified_at: 0,
primary_config_entry: null,
},
{
area_id: "backyard",
Expand All @@ -86,6 +87,7 @@ const DEVICES: DeviceRegistryEntry[] = [
labels: [],
created_at: 0,
modified_at: 0,
primary_config_entry: null,
},
{
area_id: null,
Expand All @@ -108,6 +110,7 @@ const DEVICES: DeviceRegistryEntry[] = [
labels: [],
created_at: 0,
modified_at: 0,
primary_config_entry: null,
},
];

Expand Down
3 changes: 3 additions & 0 deletions gallery/src/pages/components/ha-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const DEVICES: DeviceRegistryEntry[] = [
labels: [],
created_at: 0,
modified_at: 0,
primary_config_entry: null,
},
{
area_id: "backyard",
Expand All @@ -86,6 +87,7 @@ const DEVICES: DeviceRegistryEntry[] = [
labels: [],
created_at: 0,
modified_at: 0,
primary_config_entry: null,
},
{
area_id: null,
Expand All @@ -108,6 +110,7 @@ const DEVICES: DeviceRegistryEntry[] = [
labels: [],
created_at: 0,
modified_at: 0,
primary_config_entry: null,
},
];

Expand Down
1 change: 1 addition & 0 deletions gallery/src/pages/misc/integration-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ const createDeviceRegistryEntries = (
labels: [],
created_at: 0,
modified_at: 0,
primary_config_entry: null,
},
];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
"husky": "9.1.5",
"instant-mocha": "1.5.2",
"jszip": "3.10.1",
"lint-staged": "15.2.9",
"lint-staged": "15.2.10",
"lit-analyzer": "2.0.3",
"lodash.merge": "4.6.2",
"lodash.template": "4.5.0",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "home-assistant-frontend"
version = "20240904.0"
version = "20240906.0"
license = {text = "Apache-2.0"}
description = "The Home Assistant frontend"
readme = "README.md"
Expand Down
4 changes: 3 additions & 1 deletion src/components/ha-selector/ha-selector-number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export class HaNumberSelector extends LitElement {
}

return html`
${this.label ? html`${this.label}${this.required ? "*" : ""}` : nothing}
${this.label && !isBox
? html`${this.label}${this.required ? "*" : ""}`
: nothing}
<div class="input">
${!isBox
? html`
Expand Down
31 changes: 15 additions & 16 deletions src/data/config_entries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
import type { HomeAssistant } from "../types";
import type { IntegrationManifest, IntegrationType } from "./integration";
import type { IntegrationType } from "./integration";

export interface ConfigEntry {
entry_id: string;
Expand Down Expand Up @@ -149,20 +149,19 @@ export const enableConfigEntry = (hass: HomeAssistant, configEntryId: string) =>

export const sortConfigEntries = (
configEntries: ConfigEntry[],
manifestLookup: { [domain: string]: IntegrationManifest }
primaryConfigEntry: string | null
): ConfigEntry[] => {
const sortedConfigEntries = [...configEntries];

const getScore = (entry: ConfigEntry) => {
const manifest = manifestLookup[entry.domain] as
| IntegrationManifest
| undefined;
const isHelper = manifest?.integration_type === "helper";
return isHelper ? -1 : 1;
};

const configEntriesCompare = (a: ConfigEntry, b: ConfigEntry) =>
getScore(b) - getScore(a);

return sortedConfigEntries.sort(configEntriesCompare);
if (!primaryConfigEntry) {
return configEntries;
}
const primaryEntry = configEntries.find(
(e) => e.entry_id === primaryConfigEntry
);
if (!primaryEntry) {
return configEntries;
}
const otherEntries = configEntries.filter(
(e) => e.entry_id !== primaryConfigEntry
);
return [primaryEntry, ...otherEntries];
};
1 change: 1 addition & 0 deletions src/data/device_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface DeviceRegistryEntry extends RegistryEntry {
entry_type: "service" | null;
disabled_by: "user" | "integration" | "config_entry" | null;
configuration_url: string | null;
primary_config_entry: string | null;
}

export interface DeviceEntityDisplayLookup {
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/devices/ha-config-device-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class HaConfigDevicePage extends LitElement {
.filter((entId) => entId in entryLookup)
.map((entry) => entryLookup[entry]);

return sortConfigEntries(deviceEntries, manifestLookup);
return sortConfigEntries(deviceEntries, device.primary_config_entry);
}
);

Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/devices/ha-config-devices-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
device.config_entries
.filter((entId) => entId in entryLookup)
.map((entId) => entryLookup[entId]),
manifestLookup
device.primary_config_entry
);

const labels = labelReg && device?.labels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ import {
mdiCloseCircle,
mdiProgressClock,
} from "@mdi/js";
import { UnsubscribeFunc } from "home-assistant-js-websocket";
import {
css,
CSSResultGroup,
html,
LitElement,
nothing,
PropertyValues,
TemplateResult,
css,
html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import memoizeOne from "memoize-one";
import { groupBy } from "../../../../../common/util/group-by";
import "../../../../../components/ha-alert";
import "../../../../../components/ha-card";
import "../../../../../components/ha-icon-next";
Expand All @@ -27,25 +26,19 @@ import "../../../../../components/ha-settings-row";
import "../../../../../components/ha-svg-icon";
import "../../../../../components/ha-switch";
import "../../../../../components/ha-textfield";
import { groupBy } from "../../../../../common/util/group-by";
import {
computeDeviceName,
DeviceRegistryEntry,
subscribeDeviceRegistry,
} from "../../../../../data/device_registry";
import { computeDeviceName } from "../../../../../data/device_registry";
import {
fetchZwaveNodeConfigParameters,
fetchZwaveNodeMetadata,
setZwaveNodeConfigParameter,
ZWaveJSNodeConfigParam,
ZWaveJSNodeConfigParams,
ZwaveJSNodeMetadata,
ZWaveJSSetConfigParamResult,
ZwaveJSNodeMetadata,
fetchZwaveNodeConfigParameters,
fetchZwaveNodeMetadata,
setZwaveNodeConfigParameter,
} from "../../../../../data/zwave_js";
import "../../../../../layouts/hass-error-screen";
import "../../../../../layouts/hass-loading-screen";
import "../../../../../layouts/hass-tabs-subpage";
import { SubscribeMixin } from "../../../../../mixins/subscribe-mixin";
import { haStyle } from "../../../../../resources/styles";
import type { HomeAssistant, Route } from "../../../../../types";
import "../../../ha-config-section";
Expand All @@ -57,16 +50,8 @@ const icons = {
error: mdiCloseCircle,
};

const getDevice = memoizeOne(
(
deviceId: string,
entries?: DeviceRegistryEntry[]
): DeviceRegistryEntry | undefined =>
entries?.find((device) => device.id === deviceId)
);

@customElement("zwave_js-node-config")
class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
class ZWaveJSNodeConfig extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;

@property({ attribute: false }) public route!: Route;
Expand All @@ -79,8 +64,6 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {

@property() public deviceId!: string;

@state() private _deviceRegistryEntries?: DeviceRegistryEntry[];

@state() private _nodeMetadata?: ZwaveJSNodeMetadata;

@state() private _config?: ZWaveJSNodeConfigParams;
Expand All @@ -94,19 +77,8 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
this.deviceId = this.route.path.substr(1);
}

public hassSubscribe(): UnsubscribeFunc[] {
return [
subscribeDeviceRegistry(this.hass.connection, (entries) => {
this._deviceRegistryEntries = entries;
}),
];
}

protected updated(changedProps: PropertyValues): void {
if (
(!this._config || changedProps.has("deviceId")) &&
changedProps.has("_deviceRegistryEntries")
) {
if (!this._config || changedProps.has("deviceId")) {
this._fetchData();
}
}
Expand All @@ -125,7 +97,7 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
return html`<hass-loading-screen></hass-loading-screen>`;
}

const device = this._device!;
const device = this.hass.devices[this.deviceId];

return html`
<hass-tabs-subpage
Expand Down Expand Up @@ -392,7 +364,7 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
try {
const result = await setZwaveNodeConfigParameter(
this.hass,
this._device!.id,
this.deviceId,
target.property,
target.endpoint,
value,
Expand Down Expand Up @@ -420,16 +392,12 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
this._results = { ...this._results, [key]: errorParam };
}

private get _device(): DeviceRegistryEntry | undefined {
return getDevice(this.deviceId, this._deviceRegistryEntries);
}

private async _fetchData() {
if (!this.configEntryId || !this._deviceRegistryEntries) {
if (!this.configEntryId) {
return;
}

const device = this._device;
const device = this.hass.devices[this.deviceId];
if (!device) {
this._error = "device_not_found";
return;
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9070,7 +9070,7 @@ __metadata:
jszip: "npm:3.10.1"
leaflet: "npm:1.9.4"
leaflet-draw: "npm:1.0.4"
lint-staged: "npm:15.2.9"
lint-staged: "npm:15.2.10"
lit: "npm:2.8.0"
lit-analyzer: "npm:2.0.3"
lodash.merge: "npm:4.6.2"
Expand Down Expand Up @@ -10497,23 +10497,23 @@ __metadata:
languageName: node
linkType: hard

"lint-staged@npm:15.2.9":
version: 15.2.9
resolution: "lint-staged@npm:15.2.9"
"lint-staged@npm:15.2.10":
version: 15.2.10
resolution: "lint-staged@npm:15.2.10"
dependencies:
chalk: "npm:~5.3.0"
commander: "npm:~12.1.0"
debug: "npm:~4.3.6"
execa: "npm:~8.0.1"
lilconfig: "npm:~3.1.2"
listr2: "npm:~8.2.4"
micromatch: "npm:~4.0.7"
micromatch: "npm:~4.0.8"
pidtree: "npm:~0.6.0"
string-argv: "npm:~0.3.2"
yaml: "npm:~2.5.0"
bin:
lint-staged: bin/lint-staged.js
checksum: 10/2f7342ca3fc7e2a8a0cc3db79ca8d2ad0269b98b13220f3a6745a514aacf1f83487a23a550569081ea962f9a576af7df8d687a8330a9c3c2c27348d5a4d5440e
checksum: 10/ab6930cd633dbb5b6ec7c81fc06c65df41e9f80d93dd22e0d79c6e272cdfd8110a0fbdec60303d46a06b30bcd92261153630e2c937531b77ec5ae41e7e9d90d3
languageName: node
linkType: hard

Expand Down Expand Up @@ -10937,7 +10937,7 @@ __metadata:
languageName: node
linkType: hard

"micromatch@npm:^4.0.2, micromatch@npm:^4.0.4, micromatch@npm:~4.0.7":
"micromatch@npm:^4.0.2, micromatch@npm:^4.0.4, micromatch@npm:~4.0.8":
version: 4.0.8
resolution: "micromatch@npm:4.0.8"
dependencies:
Expand Down

0 comments on commit ba770f8

Please sign in to comment.