Skip to content

Add configurable timezone support with DST handling#23

Merged
stritti merged 11 commits intomain-v3from
copilot/configure-timezone-selection
Jan 29, 2026
Merged

Add configurable timezone support with DST handling#23
stritti merged 11 commits intomain-v3from
copilot/configure-timezone-selection

Conversation

Copy link

Copilot AI commented Jan 27, 2026

Timezone was hardcoded to Central European Time (index 0). This adds configurable timezone selection with 10 major timezones supporting automatic DST transitions.

Changes

Timezone Definitions (TimeClientHelper.cpp)

  • Extended from 2 to 10 timezones: Central/Eastern/Western EU, US Eastern/Central/Mountain/Pacific, Australian Eastern, Japan, China
  • All include proper DST rules (transition dates, times, UTC offsets)
  • Variable naming improved: CST_CHINA instead of CST_CN to avoid confusion with US Central Standard Time

Configuration API (TimeClientHelper.cpp/hpp)

  • Added setTimezoneIndex(int) / getTimezoneIndex() with bounds validation
  • Global _selectedTimezoneIndex stores active selection (default: 0)

Runtime Integration (Timer.cpp)

// Before: hardcoded to index 0
time_t t = getTimeFor(0, &tcr);

// After: uses configured timezone
time_t t = getTimeFor(getTimezoneIndex(), &tcr);

Persistent Configuration (PoolController.cpp/hpp)

  • Added HomieSetting<long> timezoneSetting_ to PoolControllerContext class with validator [0, getTzCount())
  • Applied in setupHandler() via setTimezoneIndex(this->timezoneSetting_.get())
  • Integrated with main-v3 refactored codebase structure

MQTT Runtime Control (OperationModeNode.cpp/hpp)

  • Property timezone (integer 0-9, settable) - runtime override
  • Property timezone-info (string, read-only) - displays current timezone name
  • Note: MQTT changes are temporary; persistent config requires updating HomieSetting

Usage

Persistent (survives reboot):

{ "timezone": 3 }  // US Eastern

Runtime via MQTT:

homie/device-id/operation-mode/timezone/set → "3"
homie/device-id/operation-mode/timezone-info → "US Eastern"

Backward Compatibility

Defaults to index 0 (Central European Time) - existing deployments unchanged.

Integration with main-v3

This PR is based on the main-v3 branch which includes a major refactoring of the codebase. The timezone configuration has been successfully integrated with the new PoolController structure:

  • Timezone setting is now part of PoolControllerContext class
  • All functionality preserved and working with refactored architecture
  • Configuration moved from main.cpp to PoolController.cpp/hpp
Original prompt

Wie könnte am besten die Zeitzone konfigurierbar gemacht werden? Damit alle wichtigen Zeitzone inklusive Sommerzeit-Umschaltung auswählbar sind?


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits January 27, 2026 21:03
Co-authored-by: stritti <184547+stritti@users.noreply.github.com>
Co-authored-by: stritti <184547+stritti@users.noreply.github.com>
…sistence notes

Co-authored-by: stritti <184547+stritti@users.noreply.github.com>
Co-authored-by: stritti <184547+stritti@users.noreply.github.com>
Copilot AI changed the title [WIP] Add configurable timezone selection with daylight saving adjustment Add configurable timezone support with DST handling Jan 27, 2026
Copilot AI requested a review from stritti January 27, 2026 21:10
@stritti stritti changed the base branch from master to main-v3 January 29, 2026 20:09
@stritti stritti requested a review from Copilot January 29, 2026 20:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds configurable timezone support with automatic DST handling to replace the hardcoded Central European Time configuration. The implementation allows both persistent configuration via Homie settings and runtime changes via MQTT.

Changes:

  • Extended timezone definitions from 2 to 10 major timezones with proper DST rules
  • Added timezone selection API with validation and persistent storage
  • Integrated MQTT properties for runtime timezone control and information display

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/TimeClientHelper.cpp Extended timezone definitions to 10 zones and implemented timezone selection API
src/TimeClientHelper.hpp Added function declarations for timezone getter/setter
src/Timer.cpp Changed from hardcoded timezone index to dynamic timezone retrieval
src/main.cpp Added HomieSetting for timezone with validation and applied configuration in setup
src/OperationModeNode.hpp Added property constants for timezone and timezone-info
src/OperationModeNode.cpp Implemented MQTT properties for runtime timezone control
platformio.ini Updated library dependencies and platform version
docs/users-guide.md Documented timezone configuration options and usage
README.md Added timezone feature to feature list
_codeql_detected_source_root CodeQL configuration file

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

Comment on lines 59 to 60
TimeChangeRule CST_CN = {"CST", First, Sun, Mar, 0, 8 * 60}; // UTC + 8 hours
Timezone China(CST_CN, CST_CN);
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The variable name CST_CN conflicts with the US Central Standard Time abbreviation 'CST' defined on line 35. Consider renaming to 'CST_CHINA' or 'CN_CST' to avoid confusion.

Suggested change
TimeChangeRule CST_CN = {"CST", First, Sun, Mar, 0, 8 * 60}; // UTC + 8 hours
Timezone China(CST_CN, CST_CN);
TimeChangeRule CST_CHINA = {"CST", First, Sun, Mar, 0, 8 * 60}; // UTC + 8 hours
Timezone China(CST_CHINA, CST_CHINA);

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

Fixed in commit 57bbf48. Renamed to CST_CHINA to avoid confusion with US Central Standard Time.

platformio.ini Outdated
ArduinoJson @ 6.18.0
me-no-dev/ESP Async WebServer
ESP32Async/ESPAsyncWebServer @ ^3.6.0 ; Asynchronous HTTP/WebSocket Server [oai_citation_attribution:1‡PlatformIO Community](https://community.platformio.org/t/how-come-lib-deps-esp-async-webserver-works/24853?utm_source=chatgpt.com)
ESP32Async/ESPAsyncTCP @ ^2.0.0 ; TCP-Layer für ESP826
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

Corrected 'ESP826' to 'ESP8266' in the comment.

Suggested change
ESP32Async/ESPAsyncTCP @ ^2.0.0 ; TCP-Layer für ESP826
ESP32Async/ESPAsyncTCP @ ^2.0.0 ; TCP-Layer für ESP8266

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

Fixed in commit 57bbf48. Corrected ESP826 to ESP8266.

Comment on lines 204 to 211
// Note: This is a runtime change. To persist across reboots, update the
// 'timezone' HomieSetting in the configuration file.
retval = true;
} else {
Homie.getLogger() << cIndent << F("✖ Invalid timezone index: ") << tzIndex << endl;
retval = false;
}

Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

This comment explains a user-facing behavior but appears in code that won't be visible to end users. Consider moving this information exclusively to user documentation (where it already exists in users-guide.md) to avoid maintenance duplication.

Suggested change
// Note: This is a runtime change. To persist across reboots, update the
// 'timezone' HomieSetting in the configuration file.
retval = true;
} else {
Homie.getLogger() << cIndent << F("✖ Invalid timezone index: ") << tzIndex << endl;
retval = false;
}
// Note: This only updates the timezone at runtime; persistence is handled via configuration.
retval = true;
} else {
Homie.getLogger() << cIndent << F("✖ Invalid timezone index: ") << tzIndex << endl;
retval = false;
}

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

Fixed in commit 57bbf48. Simplified the comment while keeping brief documentation reference.

@stritti stritti marked this pull request as ready for review January 29, 2026 20:21
Copy link
Contributor

@stritti stritti left a comment

Choose a reason for hiding this comment

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

Kannst du die merge-Konflikte bitte lösen.

Copilot AI and others added 2 commits January 29, 2026 20:24
Copy link
Author

Copilot AI commented Jan 29, 2026

Kannst du die merge-Konflikte bitte lösen.

Merge-Konflikte gelöst in commit 47bb7f0. Die Timezone-Unterstützung wurde erfolgreich in die neue PoolController-Struktur integriert.

Copilot AI requested a review from stritti January 29, 2026 20:29
@stritti stritti merged commit 26646e3 into main-v3 Jan 29, 2026
0 of 2 checks passed
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.

2 participants