mirror of
				https://github.com/home-assistant/frontend.git
				synced 2025-11-04 08:29:52 +00:00 
			
		
		
		
	Compare commits
	
		
			5 Commits
		
	
	
		
			20250903.2
			...
			check-mana
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					d0f799afc8 | ||
| 
						 | 
					4cf3aa18b1 | ||
| 
						 | 
					ba59b47fe6 | ||
| 
						 | 
					2dc72222f2 | ||
| 
						 | 
					71f1388a3f | 
							
								
								
									
										116
									
								
								hassio/src/dialogs/system_checks/dialog-hassio-system-checks.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								hassio/src/dialogs/system_checks/dialog-hassio-system-checks.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,116 @@
 | 
				
			|||||||
 | 
					import {
 | 
				
			||||||
 | 
					  CSSResult,
 | 
				
			||||||
 | 
					  customElement,
 | 
				
			||||||
 | 
					  html,
 | 
				
			||||||
 | 
					  LitElement,
 | 
				
			||||||
 | 
					  property,
 | 
				
			||||||
 | 
					  TemplateResult,
 | 
				
			||||||
 | 
					} from "lit-element";
 | 
				
			||||||
 | 
					import { fireEvent } from "../../../../src/common/dom/fire_event";
 | 
				
			||||||
 | 
					import "../../../../src/components/ha-circular-progress";
 | 
				
			||||||
 | 
					import { createCloseHeading } from "../../../../src/components/ha-dialog";
 | 
				
			||||||
 | 
					import "../../../../src/components/ha-settings-row";
 | 
				
			||||||
 | 
					import "../../../../src/components/ha-svg-icon";
 | 
				
			||||||
 | 
					import { extractApiErrorMessage } from "../../../../src/data/hassio/common";
 | 
				
			||||||
 | 
					import { setCheckOptions } from "../../../../src/data/hassio/resolution";
 | 
				
			||||||
 | 
					import { Supervisor } from "../../../../src/data/supervisor/supervisor";
 | 
				
			||||||
 | 
					import { showAlertDialog } from "../../../../src/dialogs/generic/show-dialog-box";
 | 
				
			||||||
 | 
					import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
 | 
				
			||||||
 | 
					import type { HomeAssistant } from "../../../../src/types";
 | 
				
			||||||
 | 
					import { SystemChecksParams } from "./show-dialog-system-checks";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@customElement("dialog-hassio-system-checks")
 | 
				
			||||||
 | 
					class HassioSystemChecksDialog extends LitElement {
 | 
				
			||||||
 | 
					  @property({ attribute: false }) public hass!: HomeAssistant;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @property({ attribute: false }) public supervisor?: Supervisor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  protected render(): TemplateResult {
 | 
				
			||||||
 | 
					    if (!this.supervisor) {
 | 
				
			||||||
 | 
					      return html``;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return html`
 | 
				
			||||||
 | 
					      <ha-dialog
 | 
				
			||||||
 | 
					        @closing=${this.closeDialog}
 | 
				
			||||||
 | 
					        .heading=${createCloseHeading(
 | 
				
			||||||
 | 
					          this.hass,
 | 
				
			||||||
 | 
					          this.supervisor.localize("dialog.system_check.title")
 | 
				
			||||||
 | 
					        )}
 | 
				
			||||||
 | 
					        hideActions
 | 
				
			||||||
 | 
					        open
 | 
				
			||||||
 | 
					      >
 | 
				
			||||||
 | 
					        <div class="form">
 | 
				
			||||||
 | 
					          ${this.supervisor.resolution.checks.map(
 | 
				
			||||||
 | 
					            (check) => html`
 | 
				
			||||||
 | 
					              <ha-settings-row three-line>
 | 
				
			||||||
 | 
					                <span slot="heading">
 | 
				
			||||||
 | 
					                  ${this.supervisor!.localize(
 | 
				
			||||||
 | 
					                    `dialog.system_check.check.${check.slug}.title`
 | 
				
			||||||
 | 
					                  ) || check.slug}
 | 
				
			||||||
 | 
					                </span>
 | 
				
			||||||
 | 
					                <span slot="description">
 | 
				
			||||||
 | 
					                  ${this.supervisor!.localize(
 | 
				
			||||||
 | 
					                    `dialog.system_check.check.${check.slug}.description`
 | 
				
			||||||
 | 
					                  )}
 | 
				
			||||||
 | 
					                </span>
 | 
				
			||||||
 | 
					                <ha-switch
 | 
				
			||||||
 | 
					                  .slug=${check.slug}
 | 
				
			||||||
 | 
					                  @change=${this._checkToggled}
 | 
				
			||||||
 | 
					                  .checked=${check.enabled}
 | 
				
			||||||
 | 
					                  haptic
 | 
				
			||||||
 | 
					                ></ha-switch>
 | 
				
			||||||
 | 
					              </ha-settings-row>
 | 
				
			||||||
 | 
					            `
 | 
				
			||||||
 | 
					          )}
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					      </ha-dialog>
 | 
				
			||||||
 | 
					    `;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public async showDialog(dialogParams: SystemChecksParams): Promise<void> {
 | 
				
			||||||
 | 
					    this.supervisor = dialogParams.supervisor;
 | 
				
			||||||
 | 
					    await this.updateComplete;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public closeDialog(): void {
 | 
				
			||||||
 | 
					    this.supervisor = undefined;
 | 
				
			||||||
 | 
					    fireEvent(this, "dialog-closed", { dialog: this.localName });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public focus(): void {
 | 
				
			||||||
 | 
					    this.updateComplete.then(() =>
 | 
				
			||||||
 | 
					      (this.shadowRoot?.querySelector(
 | 
				
			||||||
 | 
					        "[dialogInitialFocus]"
 | 
				
			||||||
 | 
					      ) as HTMLElement)?.focus()
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private async _checkToggled(ev: Event): Promise<void> {
 | 
				
			||||||
 | 
					    const check = ev.currentTarget as any;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      await setCheckOptions(this.hass, check.slug, { enabled: check.checked });
 | 
				
			||||||
 | 
					      fireEvent(this, "supervisor-collection-refresh", {
 | 
				
			||||||
 | 
					        collection: "resolution",
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    } catch (err) {
 | 
				
			||||||
 | 
					      showAlertDialog(this, {
 | 
				
			||||||
 | 
					        title: this.supervisor!.localize(
 | 
				
			||||||
 | 
					          "dialog.system_check.failed_to_set_option"
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					        text: extractApiErrorMessage(err),
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  static get styles(): CSSResult[] {
 | 
				
			||||||
 | 
					    return [haStyle, haStyleDialog];
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					declare global {
 | 
				
			||||||
 | 
					  interface HTMLElementTagNameMap {
 | 
				
			||||||
 | 
					    "dialog-hassio-system-checks": HassioSystemChecksDialog;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					import { fireEvent } from "../../../../src/common/dom/fire_event";
 | 
				
			||||||
 | 
					import { Supervisor } from "../../../../src/data/supervisor/supervisor";
 | 
				
			||||||
 | 
					import "./dialog-hassio-system-checks";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface SystemChecksParams {
 | 
				
			||||||
 | 
					  supervisor: Supervisor;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const showSystemChecksDialog = (
 | 
				
			||||||
 | 
					  element: HTMLElement,
 | 
				
			||||||
 | 
					  dialogParams: SystemChecksParams
 | 
				
			||||||
 | 
					): void => {
 | 
				
			||||||
 | 
					  fireEvent(element, "show-dialog", {
 | 
				
			||||||
 | 
					    dialogTag: "dialog-hassio-system-checks",
 | 
				
			||||||
 | 
					    dialogImport: () => import("./dialog-hassio-system-checks"),
 | 
				
			||||||
 | 
					    dialogParams,
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
@@ -1,3 +1,5 @@
 | 
				
			|||||||
 | 
					import { ActionDetail } from "@material/mwc-list";
 | 
				
			||||||
 | 
					import { mdiDotsVertical } from "@mdi/js";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  css,
 | 
					  css,
 | 
				
			||||||
  CSSResult,
 | 
					  CSSResult,
 | 
				
			||||||
@@ -11,6 +13,7 @@ import { Supervisor } from "../../../src/data/supervisor/supervisor";
 | 
				
			|||||||
import "../../../src/layouts/hass-tabs-subpage";
 | 
					import "../../../src/layouts/hass-tabs-subpage";
 | 
				
			||||||
import { haStyle } from "../../../src/resources/styles";
 | 
					import { haStyle } from "../../../src/resources/styles";
 | 
				
			||||||
import { HomeAssistant, Route } from "../../../src/types";
 | 
					import { HomeAssistant, Route } from "../../../src/types";
 | 
				
			||||||
 | 
					import { showSystemChecksDialog } from "../dialogs/system_checks/show-dialog-system-checks";
 | 
				
			||||||
import { supervisorTabs } from "../hassio-tabs";
 | 
					import { supervisorTabs } from "../hassio-tabs";
 | 
				
			||||||
import { hassioStyle } from "../resources/hassio-style";
 | 
					import { hassioStyle } from "../resources/hassio-style";
 | 
				
			||||||
import "./hassio-core-info";
 | 
					import "./hassio-core-info";
 | 
				
			||||||
@@ -42,6 +45,21 @@ class HassioSystem extends LitElement {
 | 
				
			|||||||
        <span slot="header">
 | 
					        <span slot="header">
 | 
				
			||||||
          ${this.supervisor.localize("panel.system")}
 | 
					          ${this.supervisor.localize("panel.system")}
 | 
				
			||||||
        </span>
 | 
					        </span>
 | 
				
			||||||
 | 
					        ${this.hass.userData?.showAdvanced
 | 
				
			||||||
 | 
					          ? html` <ha-button-menu
 | 
				
			||||||
 | 
					              corner="BOTTOM_START"
 | 
				
			||||||
 | 
					              slot="toolbar-icon"
 | 
				
			||||||
 | 
					              @action=${this._handleAction}
 | 
				
			||||||
 | 
					            >
 | 
				
			||||||
 | 
					              <mwc-icon-button slot="trigger" alt="menu">
 | 
				
			||||||
 | 
					                <ha-svg-icon .path=${mdiDotsVertical}></ha-svg-icon>
 | 
				
			||||||
 | 
					              </mwc-icon-button>
 | 
				
			||||||
 | 
					              <mwc-list-item>
 | 
				
			||||||
 | 
					                ${this.supervisor.localize("system.system_checks")}
 | 
				
			||||||
 | 
					              </mwc-list-item>
 | 
				
			||||||
 | 
					            </ha-button-menu>`
 | 
				
			||||||
 | 
					          : ""}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <div class="content">
 | 
					        <div class="content">
 | 
				
			||||||
          <div class="card-group">
 | 
					          <div class="card-group">
 | 
				
			||||||
            <hassio-core-info
 | 
					            <hassio-core-info
 | 
				
			||||||
@@ -66,6 +84,14 @@ class HassioSystem extends LitElement {
 | 
				
			|||||||
    `;
 | 
					    `;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private _handleAction(ev: CustomEvent<ActionDetail>) {
 | 
				
			||||||
 | 
					    switch (ev.detail.index) {
 | 
				
			||||||
 | 
					      case 0:
 | 
				
			||||||
 | 
					        showSystemChecksDialog(this, { supervisor: this.supervisor });
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static get styles(): CSSResult[] {
 | 
					  static get styles(): CSSResult[] {
 | 
				
			||||||
    return [
 | 
					    return [
 | 
				
			||||||
      haStyle,
 | 
					      haStyle,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@ export interface HassioResolution {
 | 
				
			|||||||
  unhealthy: string[];
 | 
					  unhealthy: string[];
 | 
				
			||||||
  issues: string[];
 | 
					  issues: string[];
 | 
				
			||||||
  suggestions: string[];
 | 
					  suggestions: string[];
 | 
				
			||||||
 | 
					  checks: { slug: string; enabled: boolean }[];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const fetchHassioResolution = async (
 | 
					export const fetchHassioResolution = async (
 | 
				
			||||||
@@ -27,3 +28,25 @@ export const fetchHassioResolution = async (
 | 
				
			|||||||
    )
 | 
					    )
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const setCheckOptions = async (
 | 
				
			||||||
 | 
					  hass: HomeAssistant,
 | 
				
			||||||
 | 
					  check: string,
 | 
				
			||||||
 | 
					  data: Record<string, any>
 | 
				
			||||||
 | 
					): Promise<void> => {
 | 
				
			||||||
 | 
					  if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
 | 
				
			||||||
 | 
					    await hass.callWS({
 | 
				
			||||||
 | 
					      type: "supervisor/api",
 | 
				
			||||||
 | 
					      endpoint: `/resolution/check/${check}`,
 | 
				
			||||||
 | 
					      data,
 | 
				
			||||||
 | 
					      method: "post",
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  await hass.callApi<HassioResponse<HassioResolution>>(
 | 
				
			||||||
 | 
					    "POST",
 | 
				
			||||||
 | 
					    `hassio/resolution/check/${check}`,
 | 
				
			||||||
 | 
					    data
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3667,6 +3667,7 @@
 | 
				
			|||||||
      "error_addon_not_found": "Add-on not found"
 | 
					      "error_addon_not_found": "Add-on not found"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "system": {
 | 
					    "system": {
 | 
				
			||||||
 | 
					      "system_checks": "System checks",
 | 
				
			||||||
      "log": {
 | 
					      "log": {
 | 
				
			||||||
        "log_provider": "Log Provider",
 | 
					        "log_provider": "Log Provider",
 | 
				
			||||||
        "get_logs": "Failed to get {provider} logs, {error}"
 | 
					        "get_logs": "Failed to get {provider} logs, {error}"
 | 
				
			||||||
@@ -3818,6 +3819,20 @@
 | 
				
			|||||||
        "create_snapshot": "Create a snapshot of {name} before updating",
 | 
					        "create_snapshot": "Create a snapshot of {name} before updating",
 | 
				
			||||||
        "updating": "Updating {name} to version {version}",
 | 
					        "updating": "Updating {name} to version {version}",
 | 
				
			||||||
        "snapshotting": "Creating snapshot of {name}"
 | 
					        "snapshotting": "Creating snapshot of {name}"
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      "system_check": {
 | 
				
			||||||
 | 
					        "title": "Manage system checks",
 | 
				
			||||||
 | 
					        "failed_to_set_option": "Failed to set check options",
 | 
				
			||||||
 | 
					        "check": {
 | 
				
			||||||
 | 
					          "addon_pwned": {
 | 
				
			||||||
 | 
					            "title": "PWNED Add-ons",
 | 
				
			||||||
 | 
					            "description": "Monitor secrets and passwords used in add-on configuration against HIBP"
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          "free_space": {
 | 
				
			||||||
 | 
					            "title": "Free space",
 | 
				
			||||||
 | 
					            "description": "Monitor free space left on the device"
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user