mirror of
				https://github.com/home-assistant/frontend.git
				synced 2025-10-30 22:19:55 +00:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			20231026.0
			...
			Move-parti
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | a0b11eb357 | 
| @@ -29,10 +29,6 @@ import { | |||||||
|   HassioAddonDetails, |   HassioAddonDetails, | ||||||
|   updateHassioAddon, |   updateHassioAddon, | ||||||
| } from "../../../src/data/hassio/addon"; | } from "../../../src/data/hassio/addon"; | ||||||
| import { |  | ||||||
|   createHassioPartialBackup, |  | ||||||
|   HassioPartialBackupCreateParams, |  | ||||||
| } from "../../../src/data/hassio/backup"; |  | ||||||
| import { | import { | ||||||
|   extractApiErrorMessage, |   extractApiErrorMessage, | ||||||
|   ignoreSupervisorError, |   ignoreSupervisorError, | ||||||
| @@ -103,7 +99,7 @@ class UpdateAvailableCard extends LitElement { | |||||||
|  |  | ||||||
|   @state() private _addonInfo?: HassioAddonDetails; |   @state() private _addonInfo?: HassioAddonDetails; | ||||||
|  |  | ||||||
|   @state() private _action: "backup" | "update" | null = null; |   @state() private _updating = false; | ||||||
|  |  | ||||||
|   @state() private _error?: string; |   @state() private _error?: string; | ||||||
|  |  | ||||||
| @@ -138,7 +134,7 @@ class UpdateAvailableCard extends LitElement { | |||||||
|                   name: this._name, |                   name: this._name, | ||||||
|                 })} |                 })} | ||||||
|               </p>` |               </p>` | ||||||
|             : this._action === null |             : !this._updating | ||||||
|             ? html` |             ? html` | ||||||
|                 ${this._changelogContent |                 ${this._changelogContent | ||||||
|                   ? html` |                   ? html` | ||||||
| @@ -172,18 +168,13 @@ class UpdateAvailableCard extends LitElement { | |||||||
|             : html`<ha-circular-progress alt="Updating" size="large" active> |             : html`<ha-circular-progress alt="Updating" size="large" active> | ||||||
|                 </ha-circular-progress> |                 </ha-circular-progress> | ||||||
|                 <p class="progress-text"> |                 <p class="progress-text"> | ||||||
|                   ${this._action === "update" |                   ${this.supervisor.localize("update_available.updating", { | ||||||
|                     ? this.supervisor.localize("update_available.updating", { |                     name: this._name, | ||||||
|                         name: this._name, |                     version: this._version_latest, | ||||||
|                         version: this._version_latest, |                   })} | ||||||
|                       }) |  | ||||||
|                     : this.supervisor.localize( |  | ||||||
|                         "update_available.creating_backup", |  | ||||||
|                         { name: this._name } |  | ||||||
|                       )} |  | ||||||
|                 </p>`} |                 </p>`} | ||||||
|         </div> |         </div> | ||||||
|         ${this._version !== this._version_latest && this._action === null |         ${this._version !== this._version_latest && !this._updating | ||||||
|           ? html` |           ? html` | ||||||
|               <div class="card-actions"> |               <div class="card-actions"> | ||||||
|                 ${changelog |                 ${changelog | ||||||
| @@ -319,37 +310,16 @@ class UpdateAvailableCard extends LitElement { | |||||||
|  |  | ||||||
|   private async _update() { |   private async _update() { | ||||||
|     this._error = undefined; |     this._error = undefined; | ||||||
|     if (this._shouldCreateBackup) { |     this._updating = true; | ||||||
|       let backupArgs: HassioPartialBackupCreateParams; |  | ||||||
|       if (this._updateType === "addon") { |  | ||||||
|         backupArgs = { |  | ||||||
|           name: `addon_${this.addonSlug}_${this._version}`, |  | ||||||
|           addons: [this.addonSlug!], |  | ||||||
|           homeassistant: false, |  | ||||||
|         }; |  | ||||||
|       } else { |  | ||||||
|         backupArgs = { |  | ||||||
|           name: `${this._updateType}_${this._version}`, |  | ||||||
|           folders: ["homeassistant"], |  | ||||||
|           homeassistant: true, |  | ||||||
|         }; |  | ||||||
|       } |  | ||||||
|       this._action = "backup"; |  | ||||||
|       try { |  | ||||||
|         await createHassioPartialBackup(this.hass, backupArgs); |  | ||||||
|       } catch (err: any) { |  | ||||||
|         this._error = extractApiErrorMessage(err); |  | ||||||
|         this._action = null; |  | ||||||
|         return; |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     this._action = "update"; |  | ||||||
|     try { |     try { | ||||||
|       if (this._updateType === "addon") { |       if (this._updateType === "addon") { | ||||||
|         await updateHassioAddon(this.hass, this.addonSlug!); |         await updateHassioAddon( | ||||||
|  |           this.hass, | ||||||
|  |           this.addonSlug!, | ||||||
|  |           this._shouldCreateBackup | ||||||
|  |         ); | ||||||
|       } else if (this._updateType === "core") { |       } else if (this._updateType === "core") { | ||||||
|         await updateCore(this.hass); |         await updateCore(this.hass, this._shouldCreateBackup); | ||||||
|       } else if (this._updateType === "os") { |       } else if (this._updateType === "os") { | ||||||
|         await updateOS(this.hass); |         await updateOS(this.hass); | ||||||
|       } else if (this._updateType === "supervisor") { |       } else if (this._updateType === "supervisor") { | ||||||
| @@ -358,7 +328,7 @@ class UpdateAvailableCard extends LitElement { | |||||||
|     } catch (err: any) { |     } catch (err: any) { | ||||||
|       if (this.hass.connection.connected && !ignoreSupervisorError(err)) { |       if (this.hass.connection.connected && !ignoreSupervisorError(err)) { | ||||||
|         this._error = extractApiErrorMessage(err); |         this._error = extractApiErrorMessage(err); | ||||||
|         this._action = null; |         this._updating = false; | ||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -302,7 +302,8 @@ export const installHassioAddon = async ( | |||||||
|  |  | ||||||
| export const updateHassioAddon = async ( | export const updateHassioAddon = async ( | ||||||
|   hass: HomeAssistant, |   hass: HomeAssistant, | ||||||
|   slug: string |   slug: string, | ||||||
|  |   backup: boolean | ||||||
| ): Promise<void> => { | ): Promise<void> => { | ||||||
|   if (atLeastVersion(hass.config.version, 2021, 2, 4)) { |   if (atLeastVersion(hass.config.version, 2021, 2, 4)) { | ||||||
|     await hass.callWS({ |     await hass.callWS({ | ||||||
| @@ -310,11 +311,13 @@ export const updateHassioAddon = async ( | |||||||
|       endpoint: `/store/addons/${slug}/update`, |       endpoint: `/store/addons/${slug}/update`, | ||||||
|       method: "post", |       method: "post", | ||||||
|       timeout: null, |       timeout: null, | ||||||
|  |       data: { backup: backup }, | ||||||
|     }); |     }); | ||||||
|   } else { |   } else { | ||||||
|     await hass.callApi<HassioResponse<void>>( |     await hass.callApi<HassioResponse<void>>( | ||||||
|       "POST", |       "POST", | ||||||
|       `hassio/addons/${slug}/update` |       `hassio/addons/${slug}/update`, | ||||||
|  |       { backup: backup } | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -6,15 +6,18 @@ export const restartCore = async (hass: HomeAssistant) => { | |||||||
|   await hass.callService("homeassistant", "restart"); |   await hass.callService("homeassistant", "restart"); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| export const updateCore = async (hass: HomeAssistant) => { | export const updateCore = async (hass: HomeAssistant, backup: boolean) => { | ||||||
|   if (atLeastVersion(hass.config.version, 2021, 2, 4)) { |   if (atLeastVersion(hass.config.version, 2021, 2, 4)) { | ||||||
|     await hass.callWS({ |     await hass.callWS({ | ||||||
|       type: "supervisor/api", |       type: "supervisor/api", | ||||||
|       endpoint: "/core/update", |       endpoint: "/core/update", | ||||||
|       method: "post", |       method: "post", | ||||||
|       timeout: null, |       timeout: null, | ||||||
|  |       data: { backup: backup }, | ||||||
|     }); |     }); | ||||||
|   } else { |   } else { | ||||||
|     await hass.callApi<HassioResponse<void>>("POST", `hassio/core/update`); |     await hass.callApi<HassioResponse<void>>("POST", `hassio/core/update`, { | ||||||
|  |       backup: backup, | ||||||
|  |     }); | ||||||
|   } |   } | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user