Skip to content

Conversation

@JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Nov 7, 2025

migrate bus api client to ovos-bus-client package

Summary by CodeRabbit

  • Deprecations

    • Event scheduler interface marked deprecated; instantiation now emits a deprecation warning.
  • Bug Fixes

    • Improved timezone handling for scheduling; naive datetimes are assigned a configured timezone.
    • Scheduling calculations now rely on local time for more accurate initial delays.
    • UTC time retrieval updated to use a timezone-aware method.
  • Tests

    • Unit tests adjusted to reflect the updated timezone behavior.
  • Chores

    • Continuous integration updated to newer Python versions and actions.

migrate bus api client to ovos-bus-client package
@github-actions github-actions bot added the fix label Nov 7, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 7, 2025

Walkthrough

Adds deprecation for EventSchedulerInterface.init, replaces naive datetime usage with timezone-aware helpers (now_local, get_config_tz) in scheduling, updates now_utc construction, shifts scheduler update event name, adjusts unit test expectations, and updates CI workflow Python matrix and actions versions.

Changes

Cohort / File(s) Summary
Event scheduling logic & deprecation
ovos_utils/events.py
Added imports (warnings, deprecated, now_local, get_config_tz); applied @deprecated to EventSchedulerInterface.__init__ and emit DeprecationWarning at init; use now_local() in initial and repeating scheduling calculations; assign timezone to naive when via get_config_tz(); changed emitted update event name from mycroft.schedule.update_event to mycroft.scheduler.update_event; minor emission formatting tweaks.
UTC time helper change
ovos_utils/time.py
now_utc() now returns datetime.now(tz=gettz("UTC")) instead of datetime.utcnow().replace(tzinfo=gettz("UTC")) (tz-aware construction adjusted).
Tests updated
test/unittests/test_events.py
Removed/disabled TZ-naive scheduling assertions and reduced expected scheduled messages from 3 to 2; TODO comments added around the changed portion.
CI workflow updates
.github/workflows/unit_tests.yml
Python matrix updated to ["3.10","3.11","3.12"]; actions/checkout bumped to v4; actions/setup-python bumped to v5; removed codecov upload step and Python 3.9 matrix entry; minor formatting/step adjustments.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant Scheduler as EventSchedulerInterface
    participant Config as get_config_tz()
    participant Broker as MessageBus

    rect rgb(230,240,255)
    Note right of Scheduler: Initialization (deprecated)
    Caller->>Scheduler: instantiate()
    Scheduler->>Caller: DeprecationWarning (emitted)
    end

    rect rgb(240,255,230)
    Note right of Scheduler: Scheduling flow (new)
    Caller->>Scheduler: schedule_event(when)
    Scheduler->>Scheduler: now = now_local()
    alt when is naive
        Scheduler->>Config: get_config_tz()
        Config-->>Scheduler: tz
        Scheduler->>Scheduler: assign tz to when
    end
    Scheduler->>Broker: emit "mycroft.scheduler.update_event" / "mycroft.scheduler.scheduled_event"
    Broker-->>Caller: event published
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Multiple files touched with related but distinct concerns (runtime deprecation, timezone behavior, CI, tests).
  • Areas to inspect closely:
    • Deprecation decorator/message correctness and side effects during instantiation (events.py).
    • Correctness of timezone assignment for naive datetimes and potential edge cases (events.py).
    • Behavior change from mycroft.schedule.update_eventmycroft.scheduler.update_event and consumers relying on old topic.
    • now_utc() semantics vs previous implementation (time.py).
    • Test adjustments in test/unittests/test_events.py to ensure coverage still meaningful.

Poem

A rabbit nudges clocks awake, 🐰
Local times now mend what was opaque,
Warnings whisper, old paths fade,
Events hop timely, gently made,
CI hops newer, tests adjust their pace.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The PR title accurately reflects the main changes: timezone-aware datetime functions and scheduler event names are updated across multiple files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fiz/tz

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
ovos_utils/events.py (1)

211-217: Consider removing redundant deprecation warnings.

Both the @deprecated decorator (line 211) and the manual warnings.warn (lines 213-217) emit deprecation notices. The decorator already logs the deprecation via log_deprecation, making the manual warning redundant.

Choose one approach:

Option 1: Keep only the decorator

-    @deprecated("EventSchedulerInterface moved to ovos_bus_client. 'from ovos_bus_client.apis.events import EventSchedulerInterface'", "1.0.0")
     def __init__(self, bus=None, skill_id=None):
-        warnings.warn(
-            "EventSchedulerInterface moved to ovos_bus_client. 'from ovos_bus_client.apis.events import EventSchedulerInterface'",
-            DeprecationWarning,
-            stacklevel=2,
-        )

Option 2: Keep only the manual warning

-    @deprecated("EventSchedulerInterface moved to ovos_bus_client. 'from ovos_bus_client.apis.events import EventSchedulerInterface'", "1.0.0")
     def __init__(self, bus=None, skill_id=None):
         warnings.warn(
             "EventSchedulerInterface moved to ovos_bus_client. 'from ovos_bus_client.apis.events import EventSchedulerInterface'",
             DeprecationWarning,
             stacklevel=2,
         )
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d932312 and 826b6d5.

📒 Files selected for processing (1)
  • ovos_utils/events.py (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
ovos_utils/events.py (2)
ovos_utils/log.py (1)
  • deprecated (306-324)
ovos_utils/time.py (2)
  • now_local (33-43)
  • get_config_tz (11-21)
🪛 Ruff (0.14.3)
ovos_utils/events.py

279-279: Avoid specifying long messages outside the exception class

(TRY003)

🔇 Additional comments (3)
ovos_utils/events.py (3)

2-2: LGTM! Imports support timezone-aware datetime handling.

The new imports are properly used for deprecation warnings and timezone-aware datetime operations.

Also applies to: 9-10


273-284: Excellent timezone handling fixes!

The changes correctly address timezone issues:

  • Line 277: now_local() ensures timezone-aware datetime using the configured timezone
  • Lines 280-284: Properly handles naive datetime by assigning the configured timezone using replace(tzinfo=...), which is correct - it treats the naive datetime as already being in the target timezone rather than converting it

The implementation and comments are clear and accurate.


351-351: LGTM! Consistent timezone-aware datetime usage.

The change from datetime.now() to now_local() ensures the initial scheduling time for repeating events uses the configured timezone, consistent with the fix at line 277.

caught by coderabbit, been broken since mycroft times...
why do we test if we are just testing the bad behaviour...
@github-actions github-actions bot added fix and removed fix labels Nov 7, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/unittests/test_events.py (1)

266-272: TODO: Rewrite the timezone-naive test case.

The commented-out test for scheduling TZ-naive events should be updated to reflect the new behavior where naive datetimes are assigned the configured timezone from mycroft.conf.

Would you like me to help generate an updated test case that validates the new timezone handling behavior?

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 826b6d5 and 1286496.

📒 Files selected for processing (4)
  • .github/workflows/unit_tests.yml (2 hunks)
  • ovos_utils/events.py (6 hunks)
  • ovos_utils/time.py (1 hunks)
  • test/unittests/test_events.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
test/unittests/test_events.py (1)
ovos_utils/events.py (1)
  • _schedule_event (255-308)
ovos_utils/events.py (3)
ovos_utils/fakebus.py (4)
  • FakeMessage (179-329)
  • Message (332-343)
  • dig_for_message (9-15)
  • forward (242-257)
ovos_utils/log.py (1)
  • deprecated (306-324)
ovos_utils/time.py (2)
  • now_local (33-43)
  • get_config_tz (11-21)
🪛 Ruff (0.14.3)
ovos_utils/events.py

279-279: Avoid specifying long messages outside the exception class

(TRY003)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: unit_tests (3.12)
🔇 Additional comments (7)
.github/workflows/unit_tests.yml (1)

40-64: LGTM! CI updates are appropriate.

The Python version matrix update (dropping 3.9, adding 3.11-3.12) and GitHub Actions version upgrades (checkout@v4, setup-python@v5) are solid maintenance improvements.

ovos_utils/time.py (1)

30-30: LGTM! Modern timezone-aware datetime construction.

Replacing datetime.utcnow().replace(tzinfo=...) with datetime.now(tz=gettz("UTC")) is the recommended approach for creating timezone-aware UTC datetimes, especially with Python 3.12+ where utcnow() is deprecated.

test/unittests/test_events.py (1)

279-279: Verify the expected message count aligns with test execution.

The assertion has been updated from 3 to 2 messages, reflecting the removal of the TZ-naive test path. Confirm this matches the actual number of scheduled events in the test.

ovos_utils/events.py (4)

277-277: LGTM! Consistent timezone-aware time handling.

Using now_local() instead of datetime.now() ensures the calculated event time is timezone-aware and consistent with the configured timezone.


280-284: LGTM! Proper timezone handling for naive datetimes.

Assigning get_config_tz() to naive datetime objects before timestamp conversion ensures consistency with mycroft.conf timezone settings, avoiding platform-specific C mktime() behavior.


351-351: LGTM! Consistent timezone-aware scheduling.

Using now_local() ensures the initial repeating event trigger time is timezone-aware.


370-370: No issues found. The event name change is correct and consistent.

The verification confirms:

  • The new event name mycroft.scheduler.update_event is in place (line 370)
  • The old event name mycroft.schedule.update_event does not exist in the codebase—no internal code needs updating
  • The naming is consistent with related scheduler events: mycroft.scheduler.schedule_event and mycroft.scheduler.remove_event

The change is an intentional fix for naming consistency and does not break any internal consumers.

@JarbasAl JarbasAl changed the title fix: timezone woes fix: use timezone-aware datetime functions and update scheduler event names Nov 7, 2025
@JarbasAl JarbasAl merged commit 651af94 into dev Nov 7, 2025
8 of 9 checks passed
@JarbasAl JarbasAl deleted the fiz/tz branch November 7, 2025 02:59
@github-actions github-actions bot added fix and removed fix labels Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants