Skip to content

rebaseline #46

Merged
cabberley merged 22 commits into
dev_baselinefrom
main
Jul 14, 2025
Merged

rebaseline #46
cabberley merged 22 commits into
dev_baselinefrom
main

Conversation

@cabberley

@cabberley cabberley commented Jul 14, 2025

Copy link
Copy Markdown
Owner

Proposed Changes

(Describe the changes and rationale behind them)

Related Issues

(Github link to related issues or pull requests)

Summary by Sourcery

Extend the Utility Meter Next Gen integration to support a new “multi” configuration type for creating multiple period meters (with optional tariffs and calculation sensors) in one flow, add per-cycle calibration application options, enhance sensor state tracking and attributes, and update config schemas and flows accordingly.

New Features:

  • Add a ‘multi’ config type to define multiple predefined reset cycles and generate individual utility meter and calculation sensors from a single source entry
  • Introduce per-cycle calibration application options (calibrate_apply and calibrate_calc_apply) to target calibration values to specific meter cycles

Enhancements:

  • Extend sensor model to track and persist calculated current and last values with new ATTR_LINKED_METER and ATTR_PREDEFINED_CYCLE attributes
  • Add clean_string_display helper and map meter type constants to human-readable names (METER_NAME_TYPES)
  • Revise config_flow and schemas to include multi-step forms and selectors for multi configurations
  • Improve CRON and predefined schemas, and update OptionsFlowHandler to handle the new multi config

Build:

  • Bump manifest version to 2025.7.12

Documentation:

  • Expand README with a guide on using the multi-predefined reset cycle feature and update HACS installation instructions

cabberley and others added 22 commits July 6, 2025 05:58
	modified:   README.md
	modified:   custom_components/utility_meter_next_gen/__init__.py
	modified:   custom_components/utility_meter_next_gen/config_flow.py
	modified:   custom_components/utility_meter_next_gen/const.py
	modified:   custom_components/utility_meter_next_gen/manifest.json
	modified:   custom_components/utility_meter_next_gen/schemas.py
	modified:   custom_components/utility_meter_next_gen/sensor.py
	modified:   custom_components/utility_meter_next_gen/strings.json
	modified:   custom_components/utility_meter_next_gen/translations/en.json
	modified:   custom_components/utility_meter_next_gen/config_flow.py
	modified:   custom_components/utility_meter_next_gen/schemas.py
	modified:   custom_components/utility_meter_next_gen/sensor.py
	modified:   custom_components/utility_meter_next_gen/strings.json
	modified:   custom_components/utility_meter_next_gen/translations/en.json
Multi Predefined recycle Meters Feature Code
	modified:   custom_components/utility_meter_next_gen/config_flow.py
	modified:   custom_components/utility_meter_next_gen/manifest.json
	modified:   custom_components/utility_meter_next_gen/schemas.py
	modified:   custom_components/utility_meter_next_gen/sensor.py
	modified:   custom_components/utility_meter_next_gen/manifest.json
 Changes to be committed:
	modified:   custom_components/utility_meter_next_gen/manifest.json
	modified:   custom_components/utility_meter_next_gen/sensor.py
Multi period calculation bug fix
	modified:   custom_components/utility_meter_next_gen/manifest.json
	modified:   custom_components/utility_meter_next_gen/sensor.py
Bug Fixes for Calculation sensor value not surviving HA restarts
Bumps [ruff](https://github.com/astral-sh/ruff) from 0.12.2 to 0.12.3.
- [Release notes](https://github.com/astral-sh/ruff/releases)
- [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md)
- [Commits](astral-sh/ruff@0.12.2...0.12.3)

---
updated-dependencies:
- dependency-name: ruff
  dependency-version: 0.12.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
	modified:   custom_components/utility_meter_next_gen/manifest.json
	modified:   custom_components/utility_meter_next_gen/sensor.py
	modified:   custom_components/utility_meter_next_gen/sensor.py
Tariff Total - miscalculating
	modified:   README.md
Update dependency ruff to v0.12.3
@sourcery-ai

sourcery-ai Bot commented Jul 14, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR rebases and extends the utility_meter_next_gen integration by introducing multi-meter (multi-predefined cycle) support, refactoring sensor setup to loop over selected meter types with per-cycle calibration application, persisting and exposing calculated values in both primary and calculated sensors, and updating configuration flows, schemas, constants, and documentation to expose the new multi-meter feature.

ER diagram for multi-meter type configuration and calibration application

erDiagram
    CONFIG_ENTRY {
        string CONF_METER_TYPE
        string CONF_TARIFFS
        decimal CONF_CONFIG_CALIBRATE_VALUE
        decimal CONF_CONFIG_CALIBRATE_CALC_VALUE
        string CONF_CONFIG_CALIBRATE_APPLY
        string CONF_CONFIG_CALIBRATE_CALC_APPLY
    }
    UTILITY_METER_SENSOR {
        string meter_type
        string tariff
        decimal calibrate_value
        decimal calibrate_calc_value
    }
    CONFIG_ENTRY ||--o{ UTILITY_METER_SENSOR : "creates sensors for each meter_type/tariff"
    CONFIG_ENTRY ||--|| UTILITY_METER_SENSOR : "applies calibration per selected cycle via *_APPLY fields"
Loading

Class diagram for updated Utility Meter sensor types and calibration logic

classDiagram
    class UtilityMeterSensor {
        - Decimal _calibrate_value
        - Decimal _calibrate_calc_value
        - Decimal _attr_calculated_current_value
        - Decimal _attr_calculated_last_value
        + __init__(...)
        + start(...)
        + async_reading(...)
        + async_reset_meter(...)
        + async_added_to_hass(...)
        + extra_state_attributes()
        + extra_restore_state_data()
        + async_get_last_sensor_data()
    }
    class UtilityMeterCalculatedSensor {
        - Decimal _calibrate_calc_value
        + __init__(...)
        + start(...)
        + async_added_to_hass(...)
        + extra_state_attributes()
    }
    class UtilitySensorExtraStoredData {
        + Decimal|None calculated_current_value
        + Decimal|None calculated_last_value
        + as_dict()
        + from_dict(...)
    }
    UtilityMeterSensor --|> RestoreSensor
    UtilityMeterCalculatedSensor --|> RestoreSensor
    UtilityMeterSensor --> UtilitySensorExtraStoredData : uses for state restore
    UtilityMeterCalculatedSensor --> UtilityMeterSensor : links via ATTR_LINKED_METER
Loading

Class diagram for configuration flow and schema changes (multi-meter support)

classDiagram
    class UtilityMeterEvolvedCustomConfigFlow {
        + async_step_user(...)
        + async_step_cron(...)
        + async_step_predefined(...)
        + async_step_multi_step_1(...)
        + async_step_multi_step_2(...)
    }
    class OptionsFlowHandler {
        + async_step_init(...)
        + async_multi_option_step_2(...)
    }
    class Schemas {
        + create_multi_config_schema_step_1(...)
        + create_multi_config_schema_step_2(...)
        + create_multi_option_schema_step_1(...)
        + create_multi_option_schema_step_2(...)
    }
    UtilityMeterEvolvedCustomConfigFlow --> Schemas : uses
    OptionsFlowHandler --> Schemas : uses
Loading

File-Level Changes

Change Details Files
Add multi-configuration support in config flow and options flow
  • Introduce CONF_CONFIG_MULTI and multi-step flow methods in config_flow.py
  • Add create_multi_config_schema_* and create_multi_option_schema_* helpers in schemas.py
  • Extend OptionsFlowHandler to render multi config and options steps
custom_components/utility_meter_next_gen/config_flow.py
custom_components/utility_meter_next_gen/schemas.py
Refactor async_setup_entry to instantiate multiple meters per selected types
  • Extract calibrate_apply and calibrate_calc_apply options
  • Loop over meter_type list and create UtilityMeterSensor/UtilityMeterCalculatedSensor per type
  • Use METER_NAME_TYPES for naming and unique_id formatting
custom_components/utility_meter_next_gen/sensor.py
Persist and expose calculated values on sensors
  • Extend UtilitySensorExtraStoredData with calculated_current_value/last_value
  • Update as_dict/from_dict to include new calculated fields
  • Expose and round calculated attributes in extra_state_attributes and restore logic
custom_components/utility_meter_next_gen/sensor.py
Enhance sensor classes for calculated metrics and logging
  • Add clean_string_display utility for formatted names
  • Insert debug logging in cron validation and reading flows
  • Refine UtilityMeterCalculatedSensor to include linked meter attribute and display precision
custom_components/utility_meter_next_gen/sensor.py
Expand schemas for multi and common configuration
  • Refactor BASE_COMMON_CONFIG_SCHEMA and BASE_MULTI_CONFIG_SCHEMA_STEP_1
  • Create step-by-step option schemas for multi config flows
  • Adjust existing create_calc_extras_schema and create_common_option_schema
custom_components/utility_meter_next_gen/schemas.py
Update constants with meter name mappings and calibration keys
  • Define METER_NAME_TYPES and MULTI_METER_TYPES lists
  • Add CONF_CONFIG_CALIBRATE_APPLY and CONF_CONFIG_CALIBRATE_CALC_APPLY constants
  • Adjust PERIOD2CRON mapping to include new intervals
custom_components/utility_meter_next_gen/const.py
Bump version, update manifest, requirements, and documentation
  • Increment manifest.json version to 2025.7.12
  • Fix README badges and add multi-predefined usage section
  • Remove trailing newline in requirements.txt
manifest.json
requirements.txt
README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@cabberley
cabberley merged commit 1561a3d into dev_baseline Jul 14, 2025
4 of 6 checks passed
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.

1 participant