Skip to content

Investigate configurable week-start-day support for weekly meter cycles - #166

Draft
cabberley with Copilot wants to merge 1 commit into
mainfrom
copilot/feature-make-week-start-day-configurable
Draft

Investigate configurable week-start-day support for weekly meter cycles#166
cabberley with Copilot wants to merge 1 commit into
mainfrom
copilot/feature-make-week-start-day-configurable

Conversation

Copilot AI commented Aug 5, 2026

Copy link
Copy Markdown

Problem

Weekly meter cycles always reset on Sunday, regardless of Home Assistant's configured locale (hass.config.country/language) or user expectation. Most European/other locales expect Monday as the first day of the week, so weekly meter resets are misaligned with user expectations and with statistics elsewhere in Home Assistant.

Status

This session focused on investigation and did not land a code change yet:

  • Traced how weekly cron patterns are built: PERIOD2CRON[WEEKLY] in custom_components/utility_meter_next_gen/const.py produces "{minute} {hour} * * {day}", populated from CONF_METER_OFFSET["days"] in sensor.py (__init__, around line 657) — the day field here is currently just a plain integer offset, not tied to any weekday-of-reset concept.
  • Confirmed Home Assistant core does not expose a built-in "week start day" helper on hass.config — only country and language are available (homeassistant/core_config.py). Locale-based week start would need to be derived via babel.Locale(...).first_week_day, which is available since babel is already a transitive HA dependency.
  • Reviewed the config/options flow (config_flow.py, schemas.py) to identify where an explicit override selector (Sunday/Monday) would need to be added to BASE_PREDEFINED_CONFIG_SCHEMA and the corresponding options schema, alongside the existing CONF_METER_OFFSET duration selector.

Next steps

  • Add a CONF_WEEK_START config option (e.g. default, sunday, monday) to const.py/schemas.py, exposed via selector.SelectSelector in both the config and options flows.
  • When default, derive week start from hass.config.country/language via babel.Locale.first_week_day; otherwise use the explicit override.
  • Adjust the weekly cron pattern generation in sensor.py so the {day} cron field reflects the resolved week-start weekday plus the existing offset, rather than treating offset days as an absolute weekday.
  • Add/update tests in tests/components/utility_meter_evolved/test_sensor.py covering weekly reset on both Sunday- and Monday-start configurations.

Copilot AI linked an issue Aug 5, 2026 that may be closed by this pull request
3 tasks
@cabberley
cabberley marked this pull request as ready for review August 5, 2026 21:02
@cabberley
cabberley marked this pull request as draft August 5, 2026 21:05
@cabberley
cabberley requested a lite review from Copilot August 5, 2026 21:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI changed the title [WIP] Add configurable week start day to align with locale settings Investigate configurable week-start-day support for weekly meter cycles Aug 5, 2026
Copilot AI requested a review from cabberley August 5, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: Make Week Start Day Configurable (Respect Home Assistant Locale Settings)

3 participants