-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Logbook: Localize Message & Style updates #6978
Conversation
Previous Conversationzsarnett 2 hours ago •
@bdraco Worked with you recently to help us with the More info logbook. Would you be able to help me with these changes in the backend to better support this card and the logbook as a whole? @bdraco Can you provide a bit more detail on the multi entity use case? @zsarnett Use case would be this card. Being able to see a log book for all Motion Sensor entities and building a security dashboard of sorts with the card. All Windows. We would be allowing the users to choose which entities to query for instead of just one or all of them bdraco (J. Nick Koston) @bdraco I think that will only work if there is a custom icon set. To calculate the default icon on the frontend, I think you need the 'state' as well?
I think that will only work if there is a custom icon set. To calculate the default icon on the frontend, I think you need the 'state' as well? I adjusted the PR to provide state and icon We have this giant block to create the message home-assistant/core@aa07171/homeassistant/components/logbook/init.py#L551. Ideally we send state from the backend and no message and the frontend will generate the message (localized) instead. This would get us a smaller response. I'd also like to drop "domain" as it appears to be unused by the frontend and means we end up sending the string again since its already in "entity_id" @bdraco I can drop icon but I think its needed to fully match what the frontend does: Actually, Icon would be helpful actually. Re reading the code We don't need domain. We currently use domain but we don't need to What do you think about doing this part on the frontend? Edit: even if the first step is just porting the code and it isn't localized, it would be an improvement as the backend wouldn't have to send those text blobs for each state. I much prefer us to do that in the Frontend as we can run translations (I actually don't know if that done in the backend or not) @bramkragten (who is probably in bed) would be a better fit to say whether we should or not. I personally think it should be in the frontend though |
I have pulled out the changes for the logbook into here. Original Discussion was here: #6976 |
I have started the logbook message in the frontend but it still needs localized |
|
@bdraco This should be fixed in the latest commit |
Looks good. We did loose the exact time on the more info pop up. Was that one purpose? |
Yes that was on purpose |
src/panels/logbook/ha-logbook.ts
Outdated
.entityId=${item.entity_id} | ||
@click=${this._entityClicked} | ||
> | ||
${!this.narrow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${!this.narrow | |
${!this.narrow && !this.relativeTime |
It's redundant to show 2 types of time for the same element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I disagree. I was thinking about adding it to the narrow version as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Narrow being: Relative_Time - Absolute_Time
Reason being that some people want to know when but I don't want to calculate how many hours/mins ago that was
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the absolute time in a tooltip?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that could also work, but the logbook lines can be long, and they wrap now, you don't want a secondary line then I guess...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From that statement of no secondary then you don't want the relative time in the secondary with the tooltip either? You are saying keep it to the left?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally the time to the left makes it look disconnected but idk. I like having both times. Tooltip would be okay. But sometime I want to know the absolute and sometimes I want to know the relative time without having to calculate it
src/common/entity/domain_icon.ts
Outdated
case "cover": { | ||
const open = compareState !== "closed"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you move all domain-specific icon code in here instead of importing the function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to default after wards. If the conditions aren't met we run the last lines of the domain icon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldnt this on top be enough? If the domain has a specific icon function let that handle it...
if (domain in domainIcons) {
return domainIcons[domain](state);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some domains have a specific icon but also non specific. Those are a fallback
src/data/logbook.ts
Outdated
stateObj: HassEntity, | ||
domain: string | ||
): string => { | ||
const localizePath = "ui.components.logbook.messages"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move it out of the function.
src/data/logbook.ts
Outdated
case "opening": | ||
case "window": | ||
if (isOn) { | ||
return hass.localize(`${localizePath}.was_opened`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make the localize names:
ui.components.logbook.messages.${domain}.${device_class || "_"}.${state}
That's what we also use for the state translations, and requires a lot less code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The state translations are built by core for all the states. Is it even possible to do that here? like in the code there are a lot of if this state do this otherwise this. Doing it your way would require me to do this for all states? no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would move the logic to the translations instead of the code, not more complicated I guess?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I do the logic in Json?
The link styles just look weird. Especially with two on the same line. I can put the time on the right. Just made sense to me to have them as the secondary information. |
But in your proposal, you would have a click target (automation) in a click target (entity)? And it would not be clear what a click would do? I think since they perform the same action, open the more info dialog, they should look the same? |
Well in my mind and the reasoning was the main action of the row click was the Entity that was changed. The more info for the most important entity of the row. The Auatomation/script that changed it is supporting information and is displayed as such. Clicking the link more info to the supporting and clicking the row more info to the main entity. Is there no better solution than Anchor links 🤮 ... I guess not |
… logbook-style-and-rework
Once this is good to go, I can start working on making the triggers localizable. |
Does this need a backend change or is this a bug? Am getting an error:
|
Still think the icons should be vertically centered |
Works for me on the latest core dev |
Does this still happen with home-assistant/core#40387 ? |
@bramkragten Fixed here home-assistant/core#40565. |
Proposed change
Type of change
Checklist
Core PR is reliant on the frontend PR merging before it can be merged as it is a breaking change: home-assistant/core#40070