-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add support for update entities #12059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
53ebc90
Add support for update entities
ludeeus 59ca456
Apply suggestions from code review
ludeeus 638a019
Add to gallery
ludeeus 9b6cfc7
implement xx%
ludeeus 8ce7010
Adjustments for skipped
ludeeus ae0f1c2
Add progress bar
ludeeus 9c35340
Add UPDATE_SUPPORT_INSTALL
ludeeus 73a6c49
Allow skipping without install support
ludeeus de8adb8
Add version to service call if supported
ludeeus e339585
Adjust changelog link
ludeeus 79bf803
Use Installing
ludeeus 21d0882
adjustments
ludeeus 9ba6583
Use unavailable
ludeeus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| --- | ||
| title: Update | ||
| --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import { html, LitElement, PropertyValues, TemplateResult } from "lit"; | ||
| import { customElement, property, query } from "lit/decorators"; | ||
| import "../../../../src/components/ha-card"; | ||
| import { | ||
| UPDATE_SUPPORT_BACKUP, | ||
| UPDATE_SUPPORT_PROGRESS, | ||
| UPDATE_SUPPORT_INSTALL, | ||
| } from "../../../../src/data/update"; | ||
| import "../../../../src/dialogs/more-info/more-info-content"; | ||
| import { getEntity } from "../../../../src/fake_data/entity"; | ||
| import { | ||
| MockHomeAssistant, | ||
| provideHass, | ||
| } from "../../../../src/fake_data/provide_hass"; | ||
| import "../../components/demo-more-infos"; | ||
|
|
||
| const base_attributes = { | ||
| title: "Awesome", | ||
| current_version: "1.2.2", | ||
| latest_version: "1.2.3", | ||
| release_url: "https://home-assistant.io", | ||
| supported_features: UPDATE_SUPPORT_INSTALL, | ||
| skipped_version: null, | ||
| in_progress: false, | ||
| release_summary: | ||
| "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In nec metus aliquet, porta mi ut, ultrices odio. Etiam egestas orci tellus, non semper metus blandit tincidunt. Praesent elementum turpis vel tempor pharetra. Sed quis cursus diam. Proin sem justo.", | ||
| }; | ||
|
|
||
| const ENTITIES = [ | ||
| getEntity("update", "update1", "on", { | ||
| ...base_attributes, | ||
| friendly_name: "Update", | ||
| }), | ||
| getEntity("update", "update2", "on", { | ||
| ...base_attributes, | ||
| title: null, | ||
| friendly_name: "Update without title", | ||
| }), | ||
| getEntity("update", "update3", "on", { | ||
| ...base_attributes, | ||
| release_url: null, | ||
| friendly_name: "Update without release_url", | ||
| }), | ||
| getEntity("update", "update4", "on", { | ||
| ...base_attributes, | ||
| release_summary: null, | ||
| friendly_name: "Update without release_summary", | ||
| }), | ||
| getEntity("update", "update5", "off", { | ||
| ...base_attributes, | ||
| current_version: "1.2.3", | ||
| friendly_name: "No update", | ||
| }), | ||
| getEntity("update", "update6", "off", { | ||
| ...base_attributes, | ||
| skipped_version: "1.2.3", | ||
| friendly_name: "Skipped version", | ||
| }), | ||
| getEntity("update", "update7", "on", { | ||
| ...base_attributes, | ||
| supported_features: | ||
| base_attributes.supported_features + UPDATE_SUPPORT_BACKUP, | ||
| friendly_name: "With backup support", | ||
| }), | ||
| getEntity("update", "update8", "on", { | ||
| ...base_attributes, | ||
| in_progress: true, | ||
| friendly_name: "With true in_progress", | ||
| }), | ||
| getEntity("update", "update9", "on", { | ||
| ...base_attributes, | ||
| in_progress: 25, | ||
| supported_features: | ||
| base_attributes.supported_features + UPDATE_SUPPORT_PROGRESS, | ||
| friendly_name: "With 25 in_progress", | ||
| }), | ||
| getEntity("update", "update10", "on", { | ||
| ...base_attributes, | ||
| in_progress: 50, | ||
| supported_features: | ||
| base_attributes.supported_features + UPDATE_SUPPORT_PROGRESS, | ||
| friendly_name: "With 50 in_progress", | ||
| }), | ||
| getEntity("update", "update11", "on", { | ||
| ...base_attributes, | ||
| in_progress: 75, | ||
| supported_features: | ||
| base_attributes.supported_features + UPDATE_SUPPORT_PROGRESS, | ||
| friendly_name: "With 75 in_progress", | ||
| }), | ||
| getEntity("update", "update12", "unavailable", { | ||
| ...base_attributes, | ||
| in_progress: 50, | ||
| friendly_name: "Unavailable", | ||
| }), | ||
| getEntity("update", "update13", "on", { | ||
| ...base_attributes, | ||
| supported_features: 0, | ||
| friendly_name: "No install support", | ||
| }), | ||
| getEntity("update", "update14", "off", { | ||
| ...base_attributes, | ||
| current_version: null, | ||
| friendly_name: "Update without current_version", | ||
| }), | ||
| getEntity("update", "update15", "off", { | ||
| ...base_attributes, | ||
| latest_version: null, | ||
| friendly_name: "Update without latest_version", | ||
| }), | ||
| ]; | ||
|
|
||
| @customElement("demo-more-info-update") | ||
| class DemoMoreInfoUpdate extends LitElement { | ||
| @property() public hass!: MockHomeAssistant; | ||
|
|
||
| @query("demo-more-infos") private _demoRoot!: HTMLElement; | ||
|
|
||
| protected render(): TemplateResult { | ||
| return html` | ||
| <demo-more-infos | ||
| .hass=${this.hass} | ||
| .entities=${ENTITIES.map((ent) => ent.entityId)} | ||
| ></demo-more-infos> | ||
| `; | ||
| } | ||
|
|
||
| protected firstUpdated(changedProperties: PropertyValues) { | ||
| super.firstUpdated(changedProperties); | ||
| const hass = provideHass(this._demoRoot); | ||
| hass.updateTranslations(null, "en"); | ||
| hass.addEntities(ENTITIES); | ||
| } | ||
| } | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| "demo-more-info-update": DemoMoreInfoUpdate; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import type { | ||
| HassEntityAttributeBase, | ||
| HassEntityBase, | ||
| } from "home-assistant-js-websocket"; | ||
| import { supportsFeature } from "../common/entity/supports-feature"; | ||
|
|
||
| export const UPDATE_SUPPORT_INSTALL = 1; | ||
| export const UPDATE_SUPPORT_SPECIFIC_VERSION = 2; | ||
| export const UPDATE_SUPPORT_PROGRESS = 4; | ||
| export const UPDATE_SUPPORT_BACKUP = 8; | ||
|
|
||
| interface UpdateEntityAttributes extends HassEntityAttributeBase { | ||
| current_version: string | null; | ||
| in_progress: boolean | number; | ||
| latest_version: string | null; | ||
| release_summary: string | null; | ||
| release_url: string | null; | ||
| skipped_version: string | null; | ||
| title: string | null; | ||
| } | ||
|
|
||
| export interface UpdateEntity extends HassEntityBase { | ||
| attributes: UpdateEntityAttributes; | ||
| } | ||
|
|
||
| export const updateUsesProgress = (entity: UpdateEntity): boolean => | ||
| supportsFeature(entity, UPDATE_SUPPORT_PROGRESS) && | ||
| typeof entity.attributes.in_progress === "number"; | ||
|
|
||
| export const updateCanInstall = (entity: UpdateEntity): boolean => | ||
| supportsFeature(entity, UPDATE_SUPPORT_INSTALL) && | ||
| entity.attributes.latest_version !== entity.attributes.current_version && | ||
| entity.attributes.latest_version !== entity.attributes.skipped_version; | ||
|
|
||
| export const updateIsInstalling = (entity: UpdateEntity): boolean => | ||
| updateUsesProgress(entity) || !!entity.attributes.in_progress; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.