Add next_watering timestamp sensor per device#414
Conversation
| # Add per-zone sensors (next watering, etc.) | ||
| for base_description in SENSOR_TYPES_ZONE: | ||
| sensors.append( # noqa: PERF401 | ||
| BHyveZoneSensor( | ||
| coordinator, | ||
| device, | ||
| zone, | ||
| zone_name, | ||
| base_description, | ||
| ) | ||
| ) |
There was a problem hiding this comment.
@DAB-LABS for devices with multiple zones, then each zone will receive a next watering sensor with the same data, as status.next_start_time is a property on the device, not the zone.
Therefore, a 6-zone timer creates 6 sensors that all return the identical timestamp. For a user, it is both confusing: "Front Lawn next watering" and "Back Lawn next watering" will show the same value, but also potentially incorrect, as the next_start_programs value may not actually run on all the zones.
Let's move this into SENSOR_TYPES_SPRINKLER instead
| data.get("status", {}).get("next_start_time") | ||
| ), | ||
| attributes_fn=lambda data: { | ||
| ATTR_NEXT_START_PROGRAMS: data.get("status", {}).get("next_start_programs"), |
There was a problem hiding this comment.
The programs attribute should only be included if it exists.
|
|
||
| entity_description: BHyveSensorEntityDescription | ||
| _attr_has_entity_name = True | ||
| _attr_entity_registry_enabled_default = False |
There was a problem hiding this comment.
I think it should be enabled by default
|
Thanks for the thorough review @sebr! Here's what we addressed:Moved Bonus bug fix:While wiring Thanks for having us take another look. 🙂 Tested on:HA Test (core-2026.3.4, fresh install). Sensor appears in Sensors section, renders "in 2 days", enabled by default. ruff clean, pytest passing. ~DAB |
Promotes the existing next_start_time valve attribute to a first-class per-zone SensorDeviceClass.TIMESTAMP sensor. Non-breaking, additive. - Adds BHyveZoneSensor class and SENSOR_TYPES_ZONE descriptor - Exposes next_start_programs as a 'programs' extra state attribute - Preserves existing valve attribute for backward compatibility - Disabled by default to avoid cluttering UI on install - Adds translation strings and README documentation - Adds unit tests covering populated, null, and missing cases Closes sebr#410
Per review feedback: - Move next_watering from per-zone (BHyveZoneSensor) to device-level (SENSOR_TYPES_SPRINKLER), using the existing BHyveSensor class - Remove SENSOR_TYPES_ZONE tuple and BHyveZoneSensor class - Make programs attribute conditional: only set when next_start_programs is present in device status - Enable by default (drop entity_registry_enabled_default=False) - Fix missing device_class passthrough in sprinkler sensor description copy (pre-existing bug, exposed by TIMESTAMP rendering requirement) - Update tests and README to reflect device-level scope
47e920e to
a510303
Compare
| name=base_description.name, | ||
| icon=base_description.icon, | ||
| unique_id_suffix=base_description.unique_id_suffix, | ||
| device_class=base_description.device_class, |
There was a problem hiding this comment.
That was human ~ Claude wanted to give you a string. Kept telling me it was correct... 🤦♂️😂
~DAB
|
Thanks for the contribution, @DAB-LABS 👍 |
Closes #410
Promotes the existing
next_start_timevalve attribute to a first-class per-zoneSensorDeviceClass.TIMESTAMPsensor, as discussed in #410.What this adds
A
sensor.{zone_name}_next_wateringentity is created for each zone on asprinkler_timerdevice. It reports the next scheduled watering time as a proper timestamp, enabling relative-time rendering ("in 14 hours"), long-term statistics, history graphs, and direct use in automations and dashboard cards without a template wrapper.The existing
next_start_timevalve attribute is preserved for backward compatibility.Design decisions
next_start_timeis already keyed in the data modelprogramsextra state attribute exposesnext_start_programsfor visibility into which schedule is responsibleentity_registry_enabled_default=False) to avoid cluttering the UI on install — users opt in per zone. Happy to discuss if you prefer enabled by default.orbit_time_to_local_timehelper — no new API callsTesting
next_start_timecasesruff checkclean