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

Support for icon_map #753

Merged
merged 3 commits into from
Oct 14, 2024
Merged

Support for icon_map #753

merged 3 commits into from
Oct 14, 2024

Conversation

scinos
Copy link
Contributor

@scinos scinos commented Oct 13, 2024

What problem does this PR solve?

Adds support for use custom icons for the weather conditions. This will help the use case where the original icons are too small (or too similar) to be read from a distance, or just be able to use a different icon set for aesthetic reasons.

Proposed solution

Adds a config option icon_map. This YAML dictionary will allow to map each weather condition to an icon to use. If an icon is not present in the map, the default (i.e. the mdi:* icon) will be used.

For example, this config will produce this result:

icon_map:
  "sunny": "mdi:emoticon-cool-outline"

image

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 this contribution. It's looking great so far. I've added a few comments and suggestions. Can you please apply them and let me know when this is ready for another review? Thanks again!

src/hourly-weather.ts Outdated Show resolved Hide resolved
src/types.ts Outdated
Comment on lines 13 to 14
export type Conditions = 'clear-night' | 'cloudy' | 'fog' | 'hail' | 'lightning' | 'lightning-rainy' | 'partlycloudy' | 'pouring' | 'rainy' | 'snowy' | 'snowy-rainy' | 'sunny' | 'windy' | 'windy-variant' | 'exceptional'
export type IconMap = Partial<Record<Conditions, string>>
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
export type Conditions = 'clear-night' | 'cloudy' | 'fog' | 'hail' | 'lightning' | 'lightning-rainy' | 'partlycloudy' | 'pouring' | 'rainy' | 'snowy' | 'snowy-rainy' | 'sunny' | 'windy' | 'windy-variant' | 'exceptional'
export type IconMap = Partial<Record<Conditions, string>>
export type Condition = 'clear-night' | 'cloudy' | 'fog' | 'hail' | 'lightning' | 'lightning-rainy' | 'partlycloudy' | 'pouring' | 'rainy' | 'snowy' | 'snowy-rainy' | 'sunny' | 'windy' | 'windy-variant' | 'exceptional';
type PerConditionConfig<TValue> = Partial<Record<Condition, TValue>>;
export type IconMap = PerRecordConfig<string>;

Copy link
Owner

Choose a reason for hiding this comment

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

And then replace the ColorConfig interface below with:

export type ColorConfig extends PerConditionConfig<ColorDefinition>;

Copy link
Owner

Choose a reason for hiding this comment

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

And edit the type of condition in ConditionSpan and ForecastSegment to Condition instead of string.

Copy link
Contributor Author

@scinos scinos Oct 14, 2024

Choose a reason for hiding this comment

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

I couldn't make it work with export type ColorConfig extends PerConditionConfig<ColorDefinition>;. I tried export interface ColorConfig extends PerConditionConfig<ColorDefinition> {}; but then I got a bunch of type errors every time it iterates over ColorConfig key/value because it thinks value is unknown.

Example:
image
I guess I can fix it with a bunch of as ColorDefinition, but the forced cast feels wrong to me.

I'm not sure if what I did is equivalent tbh. Let me know what you think.

Copy link
Owner

Choose a reason for hiding this comment

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

Oh, my bad - I originally had that comment suggesting an interface, but changed to a type and forgot to adjust the syntax. You got it right.

src/weather-bar.ts Outdated Show resolved Hide resolved
src/weather-bar.ts Outdated Show resolved Hide resolved
@scinos scinos requested a review from decompil3d October 14, 2024 18:06
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 adjusting. Looks great.

@decompil3d decompil3d merged commit bcad269 into decompil3d:main Oct 14, 2024
3 checks passed
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