Skip to content

Conversation

@jakubcermak
Copy link
Contributor

Proposed change

Fixes #159188

PR #155812 removed state class from accumulating rain sensor (weekly, hourly, last 24h, ....) because they are moving windows. However the truth is that not all rain sensor are moving windows - "last 24h" is, but not others - daily, hourly, yearly, etc.
This causes the error described in the issue.
This PR extends the list of sensor keys that are considered as "TOTAL_INCREASING", as they are not moving windows.

Type of change

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

Additional information

  • This PR fixes or closes issue: Fixes #159188

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

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

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings December 29, 2025 23:12
@jakubcermak jakubcermak requested a review from pvizeli as a code owner December 29, 2025 23:12
@home-assistant
Copy link

Hey there @pvizeli, mind taking a look at this pull request as it has been labeled with an integration (ecowitt) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of ecowitt can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign ecowitt Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@frenck
Copy link
Member

frenck commented Dec 29, 2025

How does this PR differ / be a better option / compare to the existing open PR?

../Frenck

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a regression where rain sensors lost their state_class attribute, which is needed for long-term statistics in Home Assistant. The previous change (PR #155812) removed state_class from all accumulating rain sensors because moving-window sensors (like "last 24h") should not have this attribute. However, this over-corrected by also removing it from non-moving-window sensors like daily, weekly, monthly, and yearly totals that reset at specific time boundaries.

Key changes:

  • Adds a new constant RAIN_TOTAL_INCREASING_SENSOR_KEYS containing 14 rain sensor keys (both imperial and metric units)
  • Replaces hardcoded tuple check with the new constant to determine which sensors get TOTAL_INCREASING state class
  • Expands the list from 2 sensors (totalrainin, totalrainmm) to 14 sensors including event, hourly, daily, weekly, monthly, and yearly variants
Comments suppressed due to low confidence (1)

homeassistant/components/ecowitt/sensor.py:310

  • This integration lacks test coverage for sensor functionality. Consider adding tests to verify that the correct state_class is applied to rain sensors, especially given the recent changes to distinguish between moving-window and non-moving-window sensors. Tests should verify that sensors in RAIN_TOTAL_INCREASING_SENSOR_KEYS receive TOTAL_INCREASING state class while other rain sensors do not.
        if sensor.key in RAIN_TOTAL_INCREASING_SENSOR_KEYS:
            description = dataclasses.replace(
                description,
                state_class=SensorStateClass.TOTAL_INCREASING,
            )

@jakubcermak
Copy link
Contributor Author

How does this PR differ / be a better option / compare to the existing open PR?

../Frenck

as the other pr is not linked to the issue, I have to admit that I simply missed the other PR.
Anyway, this PR is meant as a simple bugfix extending existing functionality and code to resolve the issue, that's bugging me after the recent HA update because complete refactor is a longer work and this IMHO should be separated - first mitigate the issue by creating a simple fix, then larger refactor can follow.
Also it's forward compatible

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.

Entity has no longer state class / Ecowitt Weather station

3 participants