Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
karwosts committed May 13, 2024
1 parent 1b57cbf commit 5699c52
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class DialogAutomationMode extends LitElement implements HassDialog {
}

private _save(): void {
this._params.updateAutomation({
this._params.updateConfig({
...this._params.config,
mode: this._newMode,
max: this._newMax,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export const loadAutomationModeDialog = () =>

export interface AutomationModeDialog {
config: AutomationConfig;
updateAutomation: (config: AutomationConfig) => void;
updateConfig: (config: AutomationConfig) => void;
onClose: () => void;
}

export interface ScriptModeDialog {
config: ScriptConfig;
updateAutomation: (config: ScriptConfig) => void;
updateConfig: (config: ScriptConfig) => void;
onClose: () => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class DialogAutomationRename extends LitElement implements HassDialog {
this._error = "Name is required";
return;
}
this._params.updateAutomation({
this._params.updateConfig({
...this._params.config,
alias: this._newName,
description: this._newDescription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export const loadAutomationRenameDialog = () =>

export interface AutomationRenameDialog {
config: AutomationConfig;
updateAutomation: (config: AutomationConfig) => void;
updateConfig: (config: AutomationConfig) => void;
onClose: () => void;
}

export interface ScriptRenameDialog {
config: ScriptConfig;
updateAutomation: (config: ScriptConfig) => void;
updateConfig: (config: ScriptConfig) => void;
onClose: () => void;
}

Expand Down
4 changes: 2 additions & 2 deletions src/panels/config/automation/ha-automation-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
return new Promise((resolve) => {
showAutomationRenameDialog(this, {
config: this._config!,
updateAutomation: (config) => {
updateConfig: (config) => {
this._config = config;
this._dirty = true;
this.requestUpdate();
Expand All @@ -703,7 +703,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
return new Promise((resolve) => {
showAutomationModeDialog(this, {
config: this._config!,
updateAutomation: (config) => {
updateConfig: (config) => {
this._config = config;
this._dirty = true;
this.requestUpdate();
Expand Down
40 changes: 9 additions & 31 deletions src/panels/config/script/ha-script-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
<ha-list-item
graphic="icon"
@click=${this._promptAutomationAlias}
@click=${this._promptScriptAlias}
.disabled=${!this.scriptId ||
this._readOnly ||
this._mode === "yaml"}
Expand All @@ -198,7 +198,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
? html`
<ha-list-item
graphic="icon"
@click=${this._promptAutomationMode}
@click=${this._promptScriptMode}
.disabled=${this._readOnly || this._mode === "yaml"}
>
${this.hass.localize(
Expand Down Expand Up @@ -555,29 +555,6 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
}
}

private updateEntityId(
newId: string | undefined,
newAlias: string | undefined
) {
const currentAlias = this._config?.alias ?? "";
const currentEntityId = this._entityId ?? "";

if (newId !== this._entityId) {
this._setEntityId(newId || undefined);
return;
}

const currentComputedEntity = this._computeEntityIdFromAlias(currentAlias);

if (currentComputedEntity === currentEntityId || !this._entityId) {
const newComputedId = newAlias
? this._computeEntityIdFromAlias(newAlias)
: undefined;

this._setEntityId(newComputedId);
}
}

private _addFields() {
if ("fields" in this._config!) {
return;
Expand Down Expand Up @@ -673,11 +650,11 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
this._mode = "yaml";
}

private async _promptAutomationAlias(): Promise<boolean> {
private async _promptScriptAlias(): Promise<boolean> {
return new Promise((resolve) => {
showAutomationRenameDialog(this, {
config: this._config!,
updateAutomation: (config) => {
updateConfig: (config) => {
this._config = config;
this._dirty = true;
this.requestUpdate();
Expand All @@ -688,11 +665,11 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
});
}

private async _promptAutomationMode(): Promise<void> {
private async _promptScriptMode(): Promise<void> {
return new Promise((resolve) => {
showAutomationModeDialog(this, {
config: this._config!,
updateAutomation: (config) => {
updateConfig: (config) => {
this._config = config;
this._dirty = true;
this.requestUpdate();
Expand Down Expand Up @@ -720,11 +697,12 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
}

if (!this.scriptId) {
const saved = await this._promptAutomationAlias();
const saved = await this._promptScriptAlias();
if (!saved) {
return;
}
this.updateEntityId(undefined, this._config!.alias);
const entityId = this._computeEntityIdFromAlias(this._config!.alias);
this._setEntityId(entityId);
}
const id = this.scriptId || this._entityId || Date.now();

Expand Down

0 comments on commit 5699c52

Please sign in to comment.