Fix water/gas badge when rate is 0
If there is only one flow rate sensor, and it has a value <=0, the badge would be displayed without a unit because the sensor gets skipped.
Instead of skipping <=0 values, continue to process sensor, but clamp the value to a minimum of 0. This ensures for single sensors we have a unit, and for multiple sensors the chosen unit is consistent even if the first sensor value drops to zero.
* Use isExternalStatistic helper for consistency
* Remove redundant if condition
We have `band = drawBands && ...`, so there is no point checking if `drawBands` is true inside `if (band && ...)`.
* Skip plotting state value on statistic graph if units mismatch
For example plotting a *F sensor on a *C chart - statistic data will be converted to *C, but the state value will still be in *F so the displayed point is wrong. Similarly if plotting a kW sensor on a W chart, the same is true - statistics get converted to W by recorder, but the state value would still be in kW. In other words the plotted state point is complete nonsense.
If the units of the statistic state don't match the units of the graph, we should not be displaying the value on the graph.
* Remove redundant this.unit check
Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>
---------
Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>
* Preserve entity unit_of_measurement in gas and water flow rate badges
The gas and water total badges on the energy dashboard Now tab previously
converted all flow rate values to L/min and then formatted them as either
L/min or gal/min based on the unit system. This meant entities reporting
in m³/h or other units always displayed incorrectly.
Now the badges preserve the unit_of_measurement from the entities. If all
entities share the same unit, the raw values are summed directly. If they
differ, values are converted through L/min as an intermediate and displayed
in the first entity's unit.
* Extract shared computeTotalFlowRate to energy.ts
* Use same now() time for all entity state values
Otherwise if there is a slight time lag while each statistic is processed, some of the points go missing from the tooltip. There end up being to very closely spaced time points for each different entity.
* Fix initial statistics graph card metadata loading
When using energy collection mode, the metadata for statistic entities was not always being loaded when the charts were first created. This could be seen in the graph units when they had differing unit (e.g. kW and W mixed).
* Re-create form editor when schema changes in hui-form-element-editor
When a parent component passes a new schema to hui-form-element-editor
(e.g. with updated disabled flags after an entity change), the internal
hui-form-editor was not rebuilt because loadConfigElement() short-circuits
once the config element exists. This meant dynamic schema changes were
silently ignored.
Override updated() to detect schema changes after initial load, tear down
the stale config element via unloadConfigElement(), and re-set the value
so the normal load path recreates the form with the current schema.
Fixes#29776
* Fix prettier formatting in hui-map-card.ts
Pre-existing formatting issue on dev branch.
* Propagate schema changes to existing form editor element
When the schema property on hui-form-element-editor changes (e.g. because
the selected entity changed and disabled flags need updating), directly
update the schema on the already-created hui-form-editor config element.
Previously, unloadConfigElement() was tried but caused a visible flash
(editor going blank then reappearing), and re-setting value with a spread
object was tried but deepEqual considers it unchanged, short-circuiting
the reload.
The fix is minimal: make _configElement protected in HuiElementEditor so
the subclass can reach it, then in the updated() hook push the new schema
directly onto the existing element — no teardown, no re-creation.
* Convert energy panel to use a dashboard strategy
Move the view-selection logic from ha-panel-energy into a dedicated
energy dashboard strategy, consistent with how home/areas/map dashboards
work. The strategy decides which view strategies (electricity, gas,
water, power, overview) to show based on energy preferences.
Extract shared constants into a separate module to avoid circular
dependencies between the panel and view strategies.
* Remove unused energy collection constants from ha-panel-energy
* date-range-picker with cally
* fix timePicker
* Review: backdrop transition
* fix comments
* Add formatCallyDateRange
* Refactor date formatting in date range picker and remove unused styles
* time-input without label
* review
* Use isExternalStatistic helper for consistency
* Remove redundant if condition
We have `band = drawBands && ...`, so there is no point checking if `drawBands` is true inside `if (band && ...)`.
* Skip plotting state value on statistic graph if units mismatch
For example plotting a *F sensor on a *C chart - statistic data will be converted to *C, but the state value will still be in *F so the displayed point is wrong. Similarly if plotting a kW sensor on a W chart, the same is true - statistics get converted to W by recorder, but the state value would still be in kW. In other words the plotted state point is complete nonsense.
If the units of the statistic state don't match the units of the graph, we should not be displaying the value on the graph.
* Remove redundant this.unit check
Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>
---------
Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>