-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Fix rain count sensors' state class of Ecowitt #158204
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
Changes from 6 commits
4943275
ed20026
0bb5c1d
5f3040a
000c9ff
c5755e7
620e29c
5d8a17c
a825a5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,19 @@ | |
| ) | ||
|
|
||
|
|
||
| # Hourly and 24h rain count sensors are rolling window sensors | ||
| _ROLLING_WINDOW_RAIN_COUNT_SENSORS = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I stiln think this should be a positive list, not a negative list.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I strongly disagree. There are 30 rain count sensors in total, in which 8 are rolling window and 22 are accumulating. If we want to really be comprehensive, then I'd go with something like _RAIN_COUNT_SENSORS_STATE_CLASS_MAPPING: Final = {
"eventrainin": SensorStateClass.TOTAL_INCREASING,
"hourlyrainin": None,
"totalrainin": SensorStateClass.TOTAL_INCREASING,
"dailyrainin": SensorStateClass.TOTAL_INCREASING,
"weeklyrainin": SensorStateClass.TOTAL_INCREASING,
"monthlyrainin": SensorStateClass.TOTAL_INCREASING,
"yearlyrainin": SensorStateClass.TOTAL_INCREASING,
"last24hrainin": None,
"eventrainmm": SensorStateClass.TOTAL_INCREASING,
"hourlyrainmm": None,
"totalrainmm": SensorStateClass.TOTAL_INCREASING,
"dailyrainmm": SensorStateClass.TOTAL_INCREASING,
"weeklyrainmm": SensorStateClass.TOTAL_INCREASING,
"monthlyrainmm": SensorStateClass.TOTAL_INCREASING,
"yearlyrainmm": SensorStateClass.TOTAL_INCREASING,
"last24hrainmm": None,
"erain_piezo": SensorStateClass.TOTAL_INCREASING,
"hrain_piezo": None,
"drain_piezo": SensorStateClass.TOTAL_INCREASING,
"wrain_piezo": SensorStateClass.TOTAL_INCREASING,
"mrain_piezo": SensorStateClass.TOTAL_INCREASING,
"yrain_piezo": SensorStateClass.TOTAL_INCREASING,
"last24hrain_piezo": None,
"erain_piezomm": SensorStateClass.TOTAL_INCREASING,
"hrain_piezomm": None,
"drain_piezomm": SensorStateClass.TOTAL_INCREASING,
"wrain_piezomm": SensorStateClass.TOTAL_INCREASING,
"mrain_piezomm": SensorStateClass.TOTAL_INCREASING,
"yrain_piezomm": SensorStateClass.TOTAL_INCREASING,
"last24hrain_piezomm": None,
}but then we need to introduce another warning for a sensor not in this list, which just makes this change increasing more complicated. Given that
I'd suggest we don't add complexity here and keep the fix as simple and minimal as possible to avoid introducing even more issues. We can always evaluate any improvement separately in the future if needed.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't see it, which one are you talking about?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not saying you need to set a full list, but I think all sensors should default to Then only the "valid" sensors should get the _TOTAL_INCREASING_RAIN_COUNT_SENSORS: Final = {
# Lifetime
"totalrainin": SensorStateClass.TOTAL_INCREASING,
"totalrainmm": SensorStateClass.TOTAL_INCREASING,
# Yearly, resets 1st day of the year
"yearlyrainin": SensorStateClass.TOTAL_INCREASING,
"yearlyrainmm": SensorStateClass.TOTAL_INCREASING,
"yrain_piezo": SensorStateClass.TOTAL_INCREASING,
"yrain_piezomm": SensorStateClass.TOTAL_INCREASING,
# Monthly, resets 1st day of the month
"monthlyrainin": SensorStateClass.TOTAL_INCREASING,
"monthlyrainmm": SensorStateClass.TOTAL_INCREASING,
"mrain_piezo": SensorStateClass.TOTAL_INCREASING,
"mrain_piezomm": SensorStateClass.TOTAL_INCREASING,
# Weekly, resets 1st day of the week
"weeklyrainin": SensorStateClass.TOTAL_INCREASING,
"weeklyrainmm": SensorStateClass.TOTAL_INCREASING,
"wrain_piezo": SensorStateClass.TOTAL_INCREASING,
"wrain_piezomm": SensorStateClass.TOTAL_INCREASING,
}I'm not sure about the long-term value for "daily" or for "event" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
As a user of the integration:
That's the near-term need for irrigation automation, but the long-term need is for adjusting the amount of irrigation (duration of cycle).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And again, this discrimination shouldn't live in Home Assistant code, so this list should be rather short-lived before necessary arrangement is done on aioecowitt library.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's as short-lived as you say it will be, then no harm in making the default
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is. The short-live can still be a while, and it also puts more code in Home Assistant unnecessarily. I don't want to continue this unproductive discussion. I have been trying to address your arguments but you ignore mine. And it seems both of us are rather determined on this. If you strongly believe it shouldn't be this way, feel free to raise a different PR and leave it to someone else's judgement on which one should be merged. I'm not going to change mine without seeing a convincing argument.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I do, because your way can introduce actual bugs:
As you wish - I have opened alternative #158528
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unresolving this conversation. I thin it isn't finished.
Honestly, I think that solution is the best approach. EXPLICIT ALWAYS WINS. I suggest define them all fully explicitly as full integration descriptions. Hacks like: if sensor.key in _ROLLING_WINDOW_RAIN_COUNT_SENSORS is the source of all weirdness to begin with. We need to start extensively defining every sensor. I'm going to put my feet down on this one. ../Frenck |
||
| "hourlyrainin", | ||
| "hourlyrainmm", | ||
| "hrain_piezo", | ||
| "hrain_piezomm", | ||
| "last24hrainin", | ||
| "last24hrainmm", | ||
| "last24hrain_piezo", | ||
| "last24hrain_piezomm", | ||
| } | ||
|
|
||
|
|
||
| ECOWITT_SENSORS_MAPPING: Final = { | ||
| EcoWittSensorTypes.HUMIDITY: SensorEntityDescription( | ||
| key="HUMIDITY", | ||
|
|
@@ -151,12 +164,14 @@ | |
| key="RAIN_COUNT_MM", | ||
| native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS, | ||
| device_class=SensorDeviceClass.PRECIPITATION, | ||
| state_class=SensorStateClass.TOTAL_INCREASING, | ||
|
upsuper marked this conversation as resolved.
Outdated
|
||
| suggested_display_precision=1, | ||
| ), | ||
| EcoWittSensorTypes.RAIN_COUNT_INCHES: SensorEntityDescription( | ||
| key="RAIN_COUNT_INCHES", | ||
| native_unit_of_measurement=UnitOfPrecipitationDepth.INCHES, | ||
| device_class=SensorDeviceClass.PRECIPITATION, | ||
| state_class=SensorStateClass.TOTAL_INCREASING, | ||
|
upsuper marked this conversation as resolved.
Outdated
|
||
| suggested_display_precision=2, | ||
| ), | ||
| EcoWittSensorTypes.RAIN_RATE_MM: SensorEntityDescription( | ||
|
|
@@ -285,15 +300,8 @@ def _new_sensor(sensor: EcoWittSensor) -> None: | |
| name=sensor.name, | ||
| ) | ||
|
|
||
| # Only total rain needs state class for long-term statistics | ||
| if sensor.key in ( | ||
| "totalrainin", | ||
| "totalrainmm", | ||
| ): | ||
| description = dataclasses.replace( | ||
| description, | ||
| state_class=SensorStateClass.TOTAL_INCREASING, | ||
| ) | ||
| if sensor.key in _ROLLING_WINDOW_RAIN_COUNT_SENSORS: | ||
| description = dataclasses.replace(description, state_class=None) | ||
|
upsuper marked this conversation as resolved.
Outdated
|
||
|
|
||
| async_add_entities([EcowittSensorEntity(sensor, description)]) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.