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

Add some weather attribute icons and units #21133

Merged
merged 1 commit into from
Jun 22, 2024

Conversation

karwosts
Copy link
Contributor

@karwosts karwosts commented Jun 22, 2024

Proposed change

Icons/units for weather card for some more of the common attributes from https://developers.home-assistant.io/docs/core/entity/weather/

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Summary by CodeRabbit

  • New Features
    • Added new weather icons for thermometer, sun, and water attributes.
    • Introduced new weather attributes: apparent temperature, cloud coverage, dew point, and UV index.
    • Enhanced weather data visualization with updated icons and attributes.

Copy link
Contributor

coderabbitai bot commented Jun 22, 2024

Walkthrough

Walkthrough

The weather.ts file has been updated to enhance its weather data representation capabilities. New weather icons and attributes related to temperature, cloud coverage, and UV index have been added. The getWeatherUnit function now handles new attributes like apparent temperature, dew point, and cloud coverage, improving the visual accuracy of weather-related components such as the weather-forecast card.

Changes

Files Change Summaries
src/data/weather.ts Added new weather icons (mdiThermometerWater, mdiSunWireless, mdiThermometer) and attributes (apparent_temperature, cloud_coverage, dew_point, temperature, uv_index) to enhance weather data representation and the getWeatherUnit function.

Sequence Diagram(s)

sequenceDiagram
    participant WeatherForecastCard
    participant WeatherAPI
    participant WeatherDataProcessor
    
    WeatherForecastCard->>WeatherAPI: Request weather data
    WeatherAPI-->>WeatherForecastCard: Send weather data
    WeatherForecastCard->>WeatherDataProcessor: Process weather data with new attributes (apparent_temperature, cloud_coverage, dew_point, temperature, uv_index)
    WeatherDataProcessor-->>WeatherForecastCard: Provide processed data with corresponding icons and units
    WeatherForecastCard->>WeatherForecastCard: Display weather data with correct icons and units
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure the weather-forecast card shows correct icons and units for all secondary_info_attributes (from #21026).

Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 5ddf72b and 41d6da6.

Files selected for processing (1)
  • src/data/weather.ts (3 hunks)
Additional context used
Biome
src/data/weather.ts

[error] 35-39: The enum declaration should not be const (lint/suspicious/noConstEnum)

Const enums are not supported by bundlers and are incompatible with the 'isolatedModules' mode. Their use can lead to import inexistent values.
See TypeScript Docs for more details.
Safe fix: Turn the const enum into a regular enum.


[error] 269-269: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 272-272: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 287-287: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 305-305: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 296-296: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

Please refactor this function to reduce its complexity score from 21 to the max allowed complexity 15.


[error] 539-539: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 553-553: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 177-177: Use Number.parseInt instead of the equivalent global. (lint/style/useNumberNamespace)

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.


[error] 178-178: isFinite is unsafe. It attempts a type coercion. Use Number.isFinite instead. (lint/suspicious/noGlobalIsFinite)

See the MDN documentation for more details.
Unsafe fix: Use Number.isFinite instead.

Additional comments not posted (3)
src/data/weather.ts (3)

4-6: New icons added for weather attributes

The addition of mdiThermometer, mdiThermometerWater, and mdiSunWireless icons aligns with the PR's goal of enhancing attribute representation. Ensure these icons are appropriately licensed for use in this project.


120-128: Addition of new weather attribute icons

The new icons and attributes (apparent_temperature, cloud_coverage, dew_point, temperature, uv_index) are correctly added to weatherAttrIcons. This change supports the visualization of these attributes on the weather card.


232-241: Update getWeatherUnit for new attributes

The function now handles units for apparent_temperature, dew_point, temperature, templow, cloud_coverage, humidity, and precipitation_probability. Ensure that these changes are reflected in the UI and that the units are correctly formatted according to user settings.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range comments (5)
src/data/weather.ts (5)

Line range hint 35-39: Replace const enum with regular enum

Const enums are incompatible with isolatedModules and certain bundlers. Change WeatherEntityFeature from a const enum to a regular enum to avoid potential issues with undefined values at runtime.

- export const enum WeatherEntityFeature {
+ export enum WeatherEntityFeature {

Line range hint 269-269: Avoid using non-null assertions

Replace non-null assertions with optional chaining or appropriate checks to prevent runtime errors if the data is unexpectedly null or undefined.

-    value = forecast[0].precipitation!;
+    value = forecast[0].precipitation ?? 0;  // Default to 0 if undefined

-    attribute = "humidity";
+    attribute = stateObj.attributes.humidity ?? "unknown";  // Default to "unknown" if undefined

-    tempHigh = fc.temperature;
+    tempHigh = fc.temperature ?? 0;  // Default to 0 if undefined

-    tempLow = fc.temperature;
+    tempLow = fc.temperature ?? 0;  // Default to 0 if undefined

Also applies to: 272-272, 287-287, 305-305


Line range hint 177-178: Use safer global functions

Replace parseInt and isFinite with Number.parseInt and Number.isFinite for consistency and to avoid type coercion issues.

-  const degreenum = typeof degree === "number" ? degree : parseInt(degree, 10);
+  const degreenum = typeof degree === "number" ? degree : Number.parseInt(degree, 10);

-  if (isFinite(degreenum)) {
+  if (Number.isFinite(degreenum)) {

Line range hint 296-296: Refactor function to reduce complexity

The function getWeatherStateSVG has a high complexity score. Consider refactoring to simplify the logic, possibly by breaking it down into smaller, more manageable functions.


Line range hint 539-539: Use optional chaining for safer access

Replace direct property access with optional chaining to prevent runtime errors when properties might not be present.

-  if (forecast && forecast?.length && forecast?.length > 2) {
+  if (forecast?.length > 2) {

-    return { forecast: forecast_event.forecast, type: forecast_event?.type };
+    return { forecast: forecast_event?.forecast, type: forecast_event?.type };

Also applies to: 553-553

@silamon silamon merged commit 362e92f into home-assistant:dev Jun 22, 2024
14 checks passed
@Jpsy
Copy link

Jpsy commented Jun 22, 2024

Thanks for taking the time to work on this! 👍

@karwosts karwosts deleted the weather-attr-icons-units branch June 22, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Weather-forecast card does not show correct icons and units for some secondary_info_attributes
3 participants