Skip to content
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

Adds an option to fill the forecast segment with icons #715

Merged
merged 8 commits into from
Aug 5, 2024

Conversation

scinos
Copy link
Contributor

@scinos scinos commented Jul 19, 2024

(Comes from #669)

What problem does this PR solve?

Adds the option to add more than one icon per forecast span. This should improve readability, specially for wallboards.

Proposed solution

Adds a new config icon_fill with three possible values:

  • single This is the default option and keeps current functionallity: it shows one single icon per span, centered.
  • full Show one icon per forecast segment. For example, it will display 12 sun icons if the next 12h is sunny.
  • <n> (an integer). Like full, but instead of displaying an icon per forecast segment, it will displaye an icon every nth segment. (In other words, full and 1 do the same). At the very least it will display one icon per span.

This is how it looks like:

image

Alternatively, we can have this as a boolean (icon_fill:false current behaviour, icon_fill:true fill all segments with icons), and introduce a second option icon_spacing (similar to label_spacing) to be able to space out the icons

| `hide_temperatures` | bool | **Optional** | Whether to hide temperatures under the bar | `false` |
| `round_temperatures` | bool | **Optional** | Whether to round temperatures to the nearest whole number | `false` |
| `hide_bar` | bool | **Optional** | Whether to hide the bar itself | `false` |
| `icon_fill` | [string][icon_fill] | **Optional** | Whether to repeat the icon inside the bar | `'single` |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This the only real change in this file. Everything else is adding spaces to keep columns aligned.

Copy link
Owner

@decompil3d decompil3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for splitting this into a separate PR. Much easier to review. This overall looks good. Some minor comments below. Please address the comments and then add tests for the new behavior.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@@ -196,6 +196,11 @@ export class HourlyWeatherCard extends LitElement {
}
}

if (config.icon_fill && config.icon_fill !== 'single' && config.icon_fill !== 'full') {
if (!Number.isNaN(config.icon_fill) && (config.icon_fill < 1)) {
throw new Error(this.localize('errors.must_be_positive_int'));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not reuse this error string, as it won't be very helpful to users if they mistype the value. Can you make a new string in src/localize/languages/en.json under the errors section with something like this:

icon_fill must be either a positive integer or one of "single" or "full"

No need to translate to other languages. Once I merge this, I can trigger auto-translation on the new string before releasing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I also refactored the check to be more explicit about what is a valid value and what isn't.

src/weather-bar.ts Outdated Show resolved Hide resolved
@scinos
Copy link
Contributor Author

scinos commented Jul 26, 2024

@decompil3d I think I need some help with checking the config option icon_fill. I see there are config tests in two places:

Why do we need two? Which one should I use to test the validity of icon_fill option?

@decompil3d
Copy link
Owner

@decompil3d I think I need some help with checking the config option icon_fill. I see there are config tests in two places:

Why do we need two? Which one should I use to test the validity of icon_fill option?

I think checking validity in renderCore would be most consistent with the existing code. Thanks for checking.

@scinos
Copy link
Contributor Author

scinos commented Jul 29, 2024

@decompil3d added tests, this PR is ready for review now

@scinos scinos marked this pull request as ready for review July 29, 2024 05:09
Copy link
Owner

@decompil3d decompil3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I'm on my phone reviewing this right now, but I'll merge this into a branch later so that CI picks up translation and then will merge to main and publish. Thanks for your contribution!

@decompil3d decompil3d changed the base branch from main to icon-fill-loc August 5, 2024 20:02
@decompil3d decompil3d merged commit de656b5 into decompil3d:icon-fill-loc Aug 5, 2024
5 checks passed
decompil3d added a commit that referenced this pull request Aug 5, 2024
…for #715) (#726)

* Adds an option to fill the forecast segment with icons (#715)

* Adds an option to fill the forecast segment with icons

* Fix typos

* Improved error detection and error message

* undefined icon_fill behaves like icon_fill:single

* Move icon_fill config check to renderCore

* Tests for icon_fill errors

* Add tests for new behaviour

* [Auto] Adding updated localization files

Files changed:
M	src/localize/languages/cs.json
M	src/localize/languages/da.json
M	src/localize/languages/de.json
M	src/localize/languages/es.json
M	src/localize/languages/fr.json
M	src/localize/languages/hu.json
M	src/localize/languages/it.json
M	src/localize/languages/nb.json
M	src/localize/languages/nl.json
M	src/localize/languages/nn-NO.json
M	src/localize/languages/pl.json
M	src/localize/languages/pt-BR.json
M	src/localize/languages/pt.json
M	src/localize/languages/ru.json
M	src/localize/languages/sk.json
M	src/localize/languages/zh.json

* Massage the auto-translation a bit

* [Auto] Adding updated localization files

Files changed:
M	src/localize/languages/pt-BR.json

* Add note to README about hidden icons on narrow segments

* Update readme table

* Tiny edit on readme

---------

Co-authored-by: Sergio Cinos <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants