Skip to content

Commit

Permalink
Merge branch 'dev' into conditional-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephAbbey authored May 6, 2024
2 parents f3f2bb9 + 43a422c commit 5197e86
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 108 deletions.
55 changes: 40 additions & 15 deletions build-scripts/gulp/translations.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable max-classes-per-file */

import { deleteAsync } from "del";
import { glob } from "glob";
import gulp from "gulp";
import merge from "gulp-merge-json";
import rename from "gulp-rename";
import merge from "lodash.merge";
import { createHash } from "node:crypto";
import { mkdir, readFile } from "node:fs/promises";
import { basename, join } from "node:path";
Expand Down Expand Up @@ -54,6 +56,39 @@ class CustomJSON extends Transform {
}
}

// Transform stream to merge Vinyl JSON files (buffer mode only).
class MergeJSON extends Transform {
_objects = [];

constructor(stem, startObj = {}, reviver = null) {
super({ objectMode: true, allowHalfOpen: false });
this._stem = stem;
this._startObj = structuredClone(startObj);
this._reviver = reviver;
}

async _transform(file, _, callback) {
try {
this._objects.push(JSON.parse(file.contents.toString(), this._reviver));
if (!this._outFile) this._outFile = file.clone({ contents: false });
callback(null);
} catch (err) {
callback(err);
}
}

async _flush(callback) {
try {
const mergedObj = merge(this._startObj, ...this._objects);
this._outFile.contents = Buffer.from(JSON.stringify(mergedObj));
this._outFile.stem = this._stem;
callback(null, this._outFile);
} catch (err) {
callback(err);
}
}
}

// Utility to flatten object keys to single level using separator
const flatten = (data, prefix = "", sep = ".") => {
const output = {};
Expand Down Expand Up @@ -131,12 +166,7 @@ const createMasterTranslation = () =>
gulp
.src([EN_SRC, ...(mergeBackend ? [`${inBackendDir}/en.json`] : [])])
.pipe(new CustomJSON(lokaliseTransform))
.pipe(
merge({
fileName: "en.json",
jsonSpace: undefined,
})
)
.pipe(new MergeJSON("en"))
.pipe(gulp.dest(workDir));

const FRAGMENTS = ["base"];
Expand Down Expand Up @@ -233,14 +263,9 @@ const createTranslations = async () => {
}
}
}
const mergeStream = gulp.src(mergeFiles, { allowEmpty: true }).pipe(
merge({
fileName: `${locale}.json`,
startObj: enMaster,
jsonReviver: emptyReviver,
jsonSpace: undefined,
})
);
const mergeStream = gulp
.src(mergeFiles, { allowEmpty: true })
.pipe(new MergeJSON(locale, enMaster, emptyReviver));
mergesFinished.push(finished(mergeStream));
mergeStream.pipe(hashStream, { end: false });
}
Expand Down
6 changes: 1 addition & 5 deletions build-scripts/webpack.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const WebpackBar = require("webpackbar");
const {
TransformAsyncModulesPlugin,
} = require("transform-async-modules-webpack-plugin");
const { dependencies } = require("../package.json");
const paths = require("./paths.cjs");
const bundle = require("./bundle.cjs");

Expand Down Expand Up @@ -157,10 +156,7 @@ const createWebpackConfig = ({
transform: (stats) => JSON.stringify(filterStats(stats)),
}),
!latestBuild &&
new TransformAsyncModulesPlugin({
browserslistEnv: "legacy",
runtime: { version: dependencies["@babel/runtime"] },
}),
new TransformAsyncModulesPlugin({ browserslistEnv: "legacy" }),
].filter(Boolean),
resolve: {
extensions: [".ts", ".js", ".json"],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
"@types/js-yaml": "4.0.9",
"@types/leaflet": "1.9.12",
"@types/leaflet-draw": "1.0.11",
"@types/lodash.merge": "4.6.9",
"@types/luxon": "3.4.2",
"@types/mocha": "10.0.6",
"@types/qrcode": "1.5.5",
Expand Down Expand Up @@ -209,7 +210,6 @@
"glob": "10.3.12",
"gulp": "5.0.0",
"gulp-json-transform": "0.5.0",
"gulp-merge-json": "2.2.1",
"gulp-rename": "2.0.0",
"gulp-zopfli-green": "6.0.1",
"html-minifier-terser": "7.2.0",
Expand All @@ -218,6 +218,7 @@
"jszip": "3.10.1",
"lint-staged": "15.2.2",
"lit-analyzer": "2.0.3",
"lodash.merge": "4.6.2",
"lodash.template": "4.5.0",
"magic-string": "0.30.10",
"map-stream": "0.0.7",
Expand Down
1 change: 1 addition & 0 deletions src/components/chips/ha-input-chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class HaInputChip extends MdInputChip {
0.15
);
--ha-input-chip-selected-container-opacity: 1;
--md-input-chip-label-text-font: Roboto, sans-serif;
}
/** Set the size of mdc icons **/
::slotted([slot="icon"]) {
Expand Down
44 changes: 19 additions & 25 deletions src/components/data-table/ha-data-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,36 +565,30 @@ export class HaDataTable extends LitElement {
}, {});
const groupedItems: DataTableRowData[] = [];
Object.entries(sorted).forEach(([groupName, rows]) => {
if (
groupName !== UNDEFINED_GROUP_KEY ||
Object.keys(sorted).length > 1
) {
groupedItems.push({
append: true,
content: html`<div
class="mdc-data-table__cell group-header"
role="cell"
.group=${groupName}
@click=${this._collapseGroup}
groupedItems.push({
append: true,
content: html`<div
class="mdc-data-table__cell group-header"
role="cell"
.group=${groupName}
@click=${this._collapseGroup}
>
<ha-icon-button
.path=${mdiChevronUp}
class=${this._collapsedGroups.includes(groupName)
? "collapsed"
: ""}
>
<ha-icon-button
.path=${mdiChevronUp}
class=${this._collapsedGroups.includes(groupName)
? "collapsed"
: ""}
>
</ha-icon-button>
${groupName === UNDEFINED_GROUP_KEY
? this.hass.localize("ui.components.data-table.ungrouped")
: groupName || ""}
</div>`,
});
}
</ha-icon-button>
${groupName === UNDEFINED_GROUP_KEY
? this.hass.localize("ui.components.data-table.ungrouped")
: groupName || ""}
</div>`,
});
if (!this._collapsedGroups.includes(groupName)) {
groupedItems.push(...rows);
}
});

items = groupedItems;
}

Expand Down
4 changes: 4 additions & 0 deletions src/components/entity/ha-entities-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class HaEntitiesPickerLight extends LitElement {
@property({ attribute: false })
public entityFilter?: HaEntityPickerEntityFilterFunc;

@property({ type: Array }) public createDomains?: string[];

protected render() {
if (!this.hass) {
return nothing;
Expand Down Expand Up @@ -103,6 +105,7 @@ class HaEntitiesPickerLight extends LitElement {
.value=${entityId}
.label=${this.pickedEntityLabel}
.disabled=${this.disabled}
.createDomains=${this.createDomains}
@value-changed=${this._entityChanged}
></ha-entity-picker>
</div>
Expand All @@ -122,6 +125,7 @@ class HaEntitiesPickerLight extends LitElement {
.label=${this.pickEntityLabel}
.helper=${this.helper}
.disabled=${this.disabled}
.createDomains=${this.createDomains}
.required=${this.required && !currentEntities.length}
@value-changed=${this._addEntity}
></ha-entity-picker>
Expand Down
15 changes: 13 additions & 2 deletions src/components/ha-conversation-agent-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { HomeAssistant } from "../types";
import "./ha-list-item";
import "./ha-select";
import type { HaSelect } from "./ha-select";
import { getExtendedEntityRegistryEntry } from "../data/entity_registry";

const NONE = "__NONE_OPTION__";

Expand Down Expand Up @@ -107,13 +108,23 @@ export class HaConversationAgentPicker extends LitElement {
}

private async _maybeFetchConfigEntry() {
if (!this.value || this.value === "homeassistant") {
if (!this.value || !(this.value in this.hass.entities)) {
this._configEntry = undefined;
return;
}
try {
const regEntry = await getExtendedEntityRegistryEntry(
this.hass,
this.value
);

if (!regEntry.config_entry_id) {
this._configEntry = undefined;
return;
}

this._configEntry = (
await getConfigEntry(this.hass, this.value)
await getConfigEntry(this.hass, regEntry.config_entry_id)
).config_entry;
} catch (err) {
this._configEntry = undefined;
Expand Down
1 change: 1 addition & 0 deletions src/components/ha-menu-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class HaMenuItem extends MdMenuItem {
--md-sys-color-on-primary-container: var(--primary-text-color);
--md-sys-color-on-secondary-container: var(--primary-text-color);
--md-menu-item-label-text-font: Roboto, sans-serif;
}
:host(.warning) {
--md-menu-item-label-text-color: var(--error-color);
Expand Down
12 changes: 11 additions & 1 deletion src/components/ha-selector/ha-selector-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
fetchEntitySourcesWithCache,
} from "../../data/entity_sources";
import type { EntitySelector } from "../../data/selector";
import { filterSelectorEntities } from "../../data/selector";
import {
filterSelectorEntities,
computeCreateDomains,
} from "../../data/selector";
import { HomeAssistant } from "../../types";
import "../entity/ha-entities-picker";
import "../entity/ha-entity-picker";
Expand All @@ -31,6 +34,8 @@ export class HaEntitySelector extends LitElement {

@property({ type: Boolean }) public required = true;

@state() private _createDomains: string[] | undefined;

private _hasIntegration(selector: EntitySelector) {
return (
selector.entity?.filter &&
Expand Down Expand Up @@ -64,6 +69,7 @@ export class HaEntitySelector extends LitElement {
.includeEntities=${this.selector.entity?.include_entities}
.excludeEntities=${this.selector.entity?.exclude_entities}
.entityFilter=${this._filterEntities}
.createDomains=${this._createDomains}
.disabled=${this.disabled}
.required=${this.required}
allow-custom-entity
Expand All @@ -79,6 +85,7 @@ export class HaEntitySelector extends LitElement {
.includeEntities=${this.selector.entity.include_entities}
.excludeEntities=${this.selector.entity.exclude_entities}
.entityFilter=${this._filterEntities}
.createDomains=${this._createDomains}
.disabled=${this.disabled}
.required=${this.required}
></ha-entities-picker>
Expand All @@ -96,6 +103,9 @@ export class HaEntitySelector extends LitElement {
this._entitySources = sources;
});
}
if (changedProps.has("selector")) {
this._createDomains = computeCreateDomains(this.selector);
}
}

private _filterEntities = (entity: HassEntity): boolean => {
Expand Down
8 changes: 7 additions & 1 deletion src/components/ha-selector/ha-selector-target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
filterSelectorDevices,
filterSelectorEntities,
TargetSelector,
computeCreateDomains,
} from "../../data/selector";
import type { HomeAssistant } from "../../types";
import "../ha-target-picker";
Expand All @@ -42,6 +43,8 @@ export class HaTargetSelector extends LitElement {

@state() private _entitySources?: EntitySources;

@state() private _createDomains: string[] | undefined;

private _deviceIntegrationLookup = memoizeOne(getDeviceIntegrationLookup);

private _hasIntegration(selector: TargetSelector) {
Expand All @@ -68,6 +71,9 @@ export class HaTargetSelector extends LitElement {
this._entitySources = sources;
});
}
if (changedProperties.has("selector")) {
this._createDomains = computeCreateDomains(this.selector);
}
}

protected render() {
Expand All @@ -82,7 +88,7 @@ export class HaTargetSelector extends LitElement {
.deviceFilter=${this._filterDevices}
.entityFilter=${this._filterEntities}
.disabled=${this.disabled}
.createDomains=${this.selector.target?.create_domains}
.createDomains=${this._createDomains}
></ha-target-picker>`;
}

Expand Down
12 changes: 3 additions & 9 deletions src/components/ha-service-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import "./ha-service-picker";
import "./ha-settings-row";
import "./ha-yaml-editor";
import type { HaYamlEditor } from "./ha-yaml-editor";
import { isHelperDomain } from "../panels/config/helpers/const";

const attributeFilter = (values: any[], attribute: any) => {
if (typeof attribute === "object") {
Expand Down Expand Up @@ -366,12 +365,8 @@ export class HaServiceControl extends LitElement {
}

private _targetSelector = memoizeOne(
(targetSelector: TargetSelector | null | undefined, domain?: string) => {
const create_domains = isHelperDomain(domain) ? [domain] : undefined;
return targetSelector
? { target: { ...targetSelector, create_domains } }
: { target: { create_domains } };
}
(targetSelector: TargetSelector | null | undefined) =>
targetSelector ? { target: { ...targetSelector } } : { target: {} }
);

protected render() {
Expand Down Expand Up @@ -462,8 +457,7 @@ export class HaServiceControl extends LitElement {
><ha-selector
.hass=${this.hass}
.selector=${this._targetSelector(
serviceData.target as TargetSelector,
domain
serviceData.target as TargetSelector
)}
.disabled=${this.disabled}
@value-changed=${this._targetChanged}
Expand Down
Loading

0 comments on commit 5197e86

Please sign in to comment.