-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Compute the icon based on the logbook state and not the current state #12725
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 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2984a8b
Compute the icon based on the logbook state and not the current state
bdraco 07933ab
Instead of overriding the icon, override the state
bdraco 0e38820
too much branching, lets try a different approach
bdraco 08dec3b
revert
bdraco 77f4852
rebuild the state instead
bdraco 690376c
cleanup diff
bdraco 4e61d11
cleanup diff
bdraco 353a349
Update src/panels/logbook/ha-logbook-renderer.ts
bdraco 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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { | |
| PropertyValues, | ||
| TemplateResult, | ||
| } from "lit"; | ||
| import type { HassEntity } from "home-assistant-js-websocket"; | ||
| import { customElement, eventOptions, property } from "lit/decorators"; | ||
| import { classMap } from "lit/directives/class-map"; | ||
| import { DOMAINS_WITH_DYNAMIC_PICTURE } from "../../common/const"; | ||
|
|
@@ -15,7 +16,6 @@ import { formatTimeWithSeconds } from "../../common/datetime/format_time"; | |
| import { restoreScroll } from "../../common/decorators/restore-scroll"; | ||
| import { fireEvent } from "../../common/dom/fire_event"; | ||
| import { computeDomain } from "../../common/entity/compute_domain"; | ||
| import { domainIconWithoutDefault } from "../../common/entity/domain_icon"; | ||
| import { isComponentLoaded } from "../../common/config/is_component_loaded"; | ||
| import { computeRTL, emitRTLDirection } from "../../common/util/compute_rtl"; | ||
| import "../../components/entity/state-badge"; | ||
|
|
@@ -131,7 +131,7 @@ class HaLogbookRenderer extends LitElement { | |
|
|
||
| const seenEntityIds: string[] = []; | ||
| const previous = this.entries[index - 1]; | ||
| const stateObj = item.entity_id | ||
| const currentStateObj = item.entity_id | ||
| ? this.hass.states[item.entity_id] | ||
| : undefined; | ||
| const item_username = | ||
|
|
@@ -140,26 +140,37 @@ class HaLogbookRenderer extends LitElement { | |
| ? computeDomain(item.entity_id) | ||
| : // Domain is there if there is no entity ID. | ||
| item.domain!; | ||
| const overrideIcon = | ||
| item.icon || | ||
| (item.domain && !stateObj | ||
| ? domainIconWithoutDefault(item.domain!) | ||
| : undefined); | ||
| const overrideImage = !DOMAINS_WITH_DYNAMIC_PICTURE.has(domain) | ||
| ? stateObj?.attributes.entity_picture_local || | ||
| stateObj?.attributes.entity_picture || | ||
| (!stateObj && | ||
| !overrideIcon && | ||
| item.domain && | ||
| isComponentLoaded(this.hass, item.domain) | ||
| ? brandsUrl({ | ||
| domain: item.domain!, | ||
| type: "icon", | ||
| useFallback: true, | ||
| darkOptimized: this.hass.themes?.darkMode, | ||
| }) | ||
| : undefined) | ||
| : undefined; | ||
| const historicStateObj = item.entity_id ? <HassEntity>(<unknown>{ | ||
| entity_id: item.entity_id, | ||
| state: item.state, | ||
| attributes: { | ||
| // Rebuild the historical state by copying static attributes only | ||
| device_class: currentStateObj?.attributes.device_class, | ||
| source_type: currentStateObj?.attributes.source_type, | ||
| has_date: currentStateObj?.attributes.has_date, | ||
| has_time: currentStateObj?.attributes.has_time, | ||
| // We do not want to use dynamic entity pictures (e.g., from media player) for the log book rendering, | ||
| // as they would present a false state in the log (played media right now vs actual historic data). | ||
| entity_picture_local: DOMAINS_WITH_DYNAMIC_PICTURE.has(domain) | ||
| ? undefined | ||
| : currentStateObj?.attributes.entity_picture_local, | ||
| entity_picture: DOMAINS_WITH_DYNAMIC_PICTURE.has(domain) | ||
| ? undefined | ||
| : currentStateObj?.attributes.entity_picture, | ||
| }, | ||
| }) : currentStateObj; | ||
| const overrideImage = | ||
| !historicStateObj && | ||
| !item.icon && | ||
| domain && | ||
| isComponentLoaded(this.hass, domain) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we care if it is loaded?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ? brandsUrl({ | ||
| domain: domain!, | ||
| type: "icon", | ||
| useFallback: true, | ||
| darkOptimized: this.hass.themes?.darkMode, | ||
| }) | ||
| : undefined; | ||
|
|
||
| return html` | ||
| <div class="entry-container"> | ||
|
|
@@ -178,14 +189,12 @@ class HaLogbookRenderer extends LitElement { | |
| <div class="entry ${classMap({ "no-entity": !item.entity_id })}"> | ||
| <div class="icon-message"> | ||
| ${!this.noIcon | ||
| ? // We do not want to use dynamic entity pictures (e.g., from media player) for the log book rendering, | ||
| // as they would present a false state in the log (played media right now vs actual historic data). | ||
| html` | ||
| ? html` | ||
| <state-badge | ||
| .hass=${this.hass} | ||
| .overrideIcon=${overrideIcon} | ||
| .overrideIcon=${item.icon} | ||
| .overrideImage=${overrideImage} | ||
| .stateObj=${stateObj} | ||
| .stateObj=${item.icon ? undefined : historicStateObj} | ||
| .stateColor=${false} | ||
| ></state-badge> | ||
| ` | ||
|
|
||
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.