Skip to content

Add flag to suppress time updates by client#1733

Open
clydebarrow wants to merge 21 commits into
esphome:mainfrom
clydebarrow:provide-time
Open

Add flag to suppress time updates by client#1733
clydebarrow wants to merge 21 commits into
esphome:mainfrom
clydebarrow:provide-time

Conversation

@clydebarrow
Copy link
Copy Markdown

What does this implement/fix?

Related to:

home-assistant/core#171846
esphome/esphome#14658
esphome/esphome#16583

Adds a flag to APIClient that will cause the connection to ignore time sync requests. The default value maintains the existing behaviour so is non-breaking.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable):

Pull request in esphome (if applicable):

  • esphome/esphome#

Checklist:

  • The code change is tested and works locally.
  • If api.proto was modified, a linked pull request has been made to esphome with the same changes.
  • Tests have been added to verify that the new code works (under tests/ folder).

@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4e72197) to head (8a071fd).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1733   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        26           
  Lines         4231      4233    +2     
=========================================
+ Hits          4231      4233    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@clydebarrow clydebarrow marked this pull request as ready for review May 23, 2026 03:29
Copilot AI review requested due to automatic review settings May 23, 2026 03:29
@clydebarrow clydebarrow requested a review from bdraco May 23, 2026 03:29
Copy link
Copy Markdown
Contributor

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 an opt-out flag to prevent the client-side connection from responding to ESPHome GetTimeRequest messages, allowing callers (e.g., log runners) to avoid modifying a device’s time/timezone via API time sync while keeping the default behavior unchanged.

Changes:

  • Add provide_time: bool = True to ConnectionParams and plumb it from APIClientBase.__init__.
  • Conditionally register the internal GetTimeRequest handler based on provide_time.
  • Add a dedicated test module validating default behavior, flag propagation, handler registration, and time response shape.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
aioesphomeapi/client_base.py Adds provide_time argument and forwards it into ConnectionParams.
aioesphomeapi/connection.py Adds provide_time to params and gates GetTimeRequest handler registration.
aioesphomeapi/connection.pxd Adds provide_time field to the Cython ConnectionParams declaration.
tests/test_provide_time.py Adds tests covering the new flag behavior and handler registration.
Comments suppressed due to low confidence (1)

aioesphomeapi/client_base.py:337

  • The APIClientBase.init docstring lists parameters through timezone but does not document the newly added provide_time argument. Please add a :param provide_time: entry explaining that setting it to False disables handling of GetTimeRequest/time sync responses (default True).
        """Create a client, this object is shared across sessions.

        :param address: The address to connect to; for example an IP address
          or .local name for mDNS lookup.
        :param port: The port to connect to
        :param password: Optional password to send to the device for authentication
        :param client_info: User Agent string to send.
        :param keepalive: The keepalive time in seconds (ping interval) for detecting stale connections.
            Every keepalive seconds a ping is sent, if no pong is received the connection is closed.
        :param zeroconf_instance: Pass a zeroconf instance to use if an mDNS lookup is necessary.
        :param noise_psk: Encryption preshared key for noise transport encrypted sessions.
        :param expected_name: Require the devices name to match the given expected name.
            Can be used to prevent accidentally connecting to a different device if
            IP passed as address but DHCP reassigned IP.
        :param addresses: Optional list of IP addresses to connect to which takes
            precedence over the address parameter. This is most commonly used when
            the device has dual stack IPv4 and IPv6 addresses and you do not know
            which one to connect to.
        :param expected_mac: Optional MAC address to check against the device.
            The format should be lower case without : or - separators.
            Example: 00:aa:22:33:44:55 -> 00aa22334455
        :param timezone: Optional IANA timezone name to send to ESPHome devices.
            If not provided, the system timezone will be detected automatically.
            Example: 'America/Chicago' or 'Europe/London'
        """

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 23, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds a provide_time: bool = True option to API client and ConnectionParams, threads it into Cython declarations, conditions GetTimeRequest handler registration on that flag, and adds tests verifying default/explicit values and transport-level responses.

Changes

Optional Time Provision Flag

Layer / File(s) Summary
Parameter contract and storage
aioesphomeapi/client_base.py, aioesphomeapi/connection.pxd, aioesphomeapi/connection.py
APIClientBase.__init__ gains keyword provide_time: bool = True; value is passed into ConnectionParams and declared as a public Cython bint provide_time.
Conditional GetTimeRequest handler registration
aioesphomeapi/connection.py
Registration of the internal GetTimeRequest handler is executed only when self._params.provide_time is truthy.
Test coverage for provide_time behavior
tests/test_provide_time.py, tests/common.py
New tests assert default is True, that False is preserved, and that a plaintext GetTimeRequest produces an outbound GetTimeResponse only when provide_time=True. get_mock_connection_params() now sets provide_time=True for mocks.

Sequence Diagram(s)

sequenceDiagram
  participant APIClient
  participant Connection
  participant Device
  APIClient->>Connection: construct ConnectionParams(provide_time)
  Connection->>Connection: if provide_time register GetTimeRequest handler
  Device->>Connection: GetTimeRequest
  Connection->>Device: GetTimeResponse (epoch_seconds[, timezone])
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

minor

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add flag to suppress time updates by client' clearly and concisely summarizes the main change: adding a provide_time flag to control whether time sync requests are processed.
Description check ✅ Passed The description relates to the changeset by explaining what the flag does, linking to relevant issues, and confirming non-breaking behavior with backward compatibility.
Linked Issues check ✅ Passed All code changes meet the requirements: the provide_time flag has been plumbed through APIClientBase, ConnectionParams (both Python and Cython), the GetTimeRequest handler registration is now conditional, and tests verify the flag's behavior.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the provide_time flag feature: API signature updates, parameter declarations, handler registration logic, tests, and test helper updates are all in scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Copy Markdown
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.

🧹 Nitpick comments (2)
aioesphomeapi/client_base.py (1)

311-337: ⚡ Quick win

Document the new provide_time kwarg in APIClientBase.__init__ docstring.

The constructor now accepts provide_time, but the parameter block does not describe it. Please add a short :param provide_time: entry for caller-facing clarity.

Suggested diff
         :param timezone: Optional IANA timezone name to send to ESPHome devices.
             If not provided, the system timezone will be detected automatically.
             Example: 'America/Chicago' or 'Europe/London'
+        :param provide_time: Whether to reply to GetTimeRequest messages.
+            Set to False to avoid client-driven time/timezone updates on the device.
         """

As per coding guidelines, "Docstrings should be terse and default to single-line format ("""Summary.""") describing what the function does and what the caller can pass."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@aioesphomeapi/client_base.py` around lines 311 - 337, The __init__ docstring
for APIClientBase is missing documentation for the new provide_time parameter;
update the APIClientBase.__init__ docstring to add a concise ":param
provide_time: bool" entry describing that it controls whether the client
advertises/sends the current time to the device (default True) so callers
understand its purpose and default behavior and ensure the summary remains terse
and follows the file's single-line docstring style.
tests/test_provide_time.py (1)

1-10: ⚡ Quick win

Trim module prose and separator comments to match repository style rules.

The module docstring is overly explanatory, and section-divider comments are unnecessary here. Keep a terse summary and rely on test names for structure.

Suggested diff
-"""Tests for the provide_time flag on APIClient / ConnectionParams.
-
-When provide_time=True (the default) the connection registers a handler
-for GetTimeRequest and responds with the current epoch time, keeping the
-device's clock in sync with the client.
-
-When provide_time=False the handler is not registered, leaving the
-device's clock untouched — useful for ESPHome's own log runner which
-should not override timezone settings managed by Home Assistant.
-"""
+"""Test provide_time behavior on APIClient and APIConnection."""
@@
-# ---------------------------------------------------------------------------
-# Tests: APIClient stores the flag correctly on _params
-# ---------------------------------------------------------------------------
@@
-# ---------------------------------------------------------------------------
-# Tests: _register_internal_message_handlers respects the flag
-# ---------------------------------------------------------------------------
@@
-# ---------------------------------------------------------------------------
-# Tests: the time response handler sends a plausible epoch value
-# ---------------------------------------------------------------------------

As per coding guidelines, "Docstrings should be terse and default to single-line format ("""Summary.""")..." and "Add comments only when the why is non-obvious... Default to writing no comments."

Also applies to: 25-27, 44-47, 85-87

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_provide_time.py` around lines 1 - 10, The module docstring and
several section-divider comments are too verbose; replace the multi-line
docstring at the top with a terse single-line summary (e.g., "Tests for the
provide_time flag on APIClient/ConnectionParams.") and remove the unnecessary
separator or explanatory comments around the provide_time-related tests (the
long explanatory blocks referenced in the review). Keep test function names and
assertions intact so behavior is unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@aioesphomeapi/client_base.py`:
- Around line 311-337: The __init__ docstring for APIClientBase is missing
documentation for the new provide_time parameter; update the
APIClientBase.__init__ docstring to add a concise ":param provide_time: bool"
entry describing that it controls whether the client advertises/sends the
current time to the device (default True) so callers understand its purpose and
default behavior and ensure the summary remains terse and follows the file's
single-line docstring style.

In `@tests/test_provide_time.py`:
- Around line 1-10: The module docstring and several section-divider comments
are too verbose; replace the multi-line docstring at the top with a terse
single-line summary (e.g., "Tests for the provide_time flag on
APIClient/ConnectionParams.") and remove the unnecessary separator or
explanatory comments around the provide_time-related tests (the long explanatory
blocks referenced in the review). Keep test function names and assertions intact
so behavior is unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f3b92d65-3287-4f61-95b8-fb1c9814c8a3

📥 Commits

Reviewing files that changed from the base of the PR and between 32a514b and cd6bda6.

📒 Files selected for processing (4)
  • aioesphomeapi/client_base.py
  • aioesphomeapi/connection.pxd
  • aioesphomeapi/connection.py
  • tests/test_provide_time.py

@bdraco
Copy link
Copy Markdown
Member

bdraco commented May 23, 2026

Tests are failing. Looks like an update is needed

@bluetoothbot
Copy link
Copy Markdown
Contributor

bluetoothbot commented May 23, 2026

PR Review — Add flag to suppress time updates by client

The production change is correct and minimal: provide_time is plumbed APIClientBase.__init__ -> ConnectionParams -> gated handler registration in _register_internal_message_handlers, defaults to True (non-breaking), and the .pxd adds cdef public bint provide_time matching the established timezone dataclass pattern. Since GetTimeResponse is only ever sent reactively from the gated handler (no proactive time push exists), suppressing registration fully achieves the goal, and APIClient inherits the constructor so the flag is exposed publicly. I reconstructed the exact diff locally: the full suite passes (1184 passed, 1 skipped) in pure-Python and the Cython transpile succeeds, so I could not reproduce bdraco's 'tests are failing' on current main with this revision (I could not link the compiled extension here due to missing Python dev headers, so a Cython build-time failure can't be 100% excluded). The remaining work is in the test file: the provide_time=True test asserts only that some write occurred, not that a GetTimeResponse was sent — tightening it to decode the frame (as test_get_time_request_timezone_handling already does) is the substantive fix and directly addresses bdraco's 'test end to end' request. The __import__ idiom and duplicated connection setup are minor cleanups. Minor (non-blocking) note: _do_finish_connect still computes _cached_timezone = await get_timezone(...) even when provide_time=False, which is now dead work on that path.


🟡 Important

1. Assertion doesn't verify a GetTimeResponse was actually sent (`tests/test_provide_time.py`, L91-93)

assert transport.write.called or transport.writelines.called is too loose to prove the behavior under test. Two problems:

  1. The frame helper sends frames exclusively via writelinestransport.write is never called by this path, so the transport.write.called half of the OR is dead and the failure message ("Expected transport.write to be called") is misleading.
  2. The assertion only proves some write happened after reset_mock(); it does not prove the bytes are a GetTimeResponse. This is exactly the gap bdraco flagged — to be a meaningful end-to-end test (especially against the shipped Cython build), it should decode the frame and confirm it's a GetTimeResponse.

The existing test_get_time_request_timezone_handling in tests/test_connection.py shows the pattern:

assert transport.writelines.call_count == 1
raw = b"".join(transport.writelines.call_args[0][0])
resp = GetTimeResponse()
resp.ParseFromString(raw[3:])  # skip 0x00, length varuint, type varuint

Mirror that here. For the provide_time=False case the current assert_not_called() checks are fine.

assert transport.write.called or transport.writelines.called, (
    "Expected transport.write to be called with a GetTimeResponse"
)

🟢 Suggestions

1. Use a normal top-level `patch` import instead of dynamic `__import__` (`tests/test_provide_time.py`, L66-71)

__import__("unittest.mock", fromlist=["patch"]).patch.object(...) is an obfuscated way to reach patch. Add patch to the existing from unittest.mock import MagicMock line and inline the patch.object(...) directly in the with block — that is how every other test module here (e.g. test_connection.py) does it. The dedicated patch_create_connection helper then disappears entirely, removing a layer of indirection for no benefit.

def patch_create_connection(loop, transport, connected):
    return __import__("unittest.mock", fromlist=["patch"]).patch.object(

Checklist

  • Production logic correct; flag fully suppresses client time provision
  • Non-breaking (default preserves existing behaviour)
  • Cython .pxd kept in sync with new dataclass field
  • Public APIClient surface exposes the new param
  • Tests assert observable behaviour meaningfully — warning #1
  • Tests follow project idioms / avoid duplication — suggestion #2, #3

Summary

The production change is correct and minimal: provide_time is plumbed APIClientBase.__init__ -> ConnectionParams -> gated handler registration in _register_internal_message_handlers, defaults to True (non-breaking), and the .pxd adds cdef public bint provide_time matching the established timezone dataclass pattern. Since GetTimeResponse is only ever sent reactively from the gated handler (no proactive time push exists), suppressing registration fully achieves the goal, and APIClient inherits the constructor so the flag is exposed publicly. I reconstructed the exact diff locally: the full suite passes (1184 passed, 1 skipped) in pure-Python and the Cython transpile succeeds, so I could not reproduce bdraco's 'tests are failing' on current main with this revision (I could not link the compiled extension here due to missing Python dev headers, so a Cython build-time failure can't be 100% excluded). The remaining work is in the test file: the provide_time=True test asserts only that some write occurred, not that a GetTimeResponse was sent — tightening it to decode the frame (as test_get_time_request_timezone_handling already does) is the substantive fix and directly addresses bdraco's 'test end to end' request. The __import__ idiom and duplicated connection setup are minor cleanups. Minor (non-blocking) note: _do_finish_connect still computes _cached_timezone = await get_timezone(...) even when provide_time=False, which is now dead work on that path.


To rebase specific severity levels, mention me: @bluetoothbot rebase critical (fixes 🔴 only), @bluetoothbot rebase important (fixes 🔴 + 🟡), or just @bluetoothbot rebase for all.


Automated review by Kōan2307017
63556d1
5e07577
a795a46
e9d438d
61c9814
cd6bda6
0de112a
99d4963
729a0b3
96ee82f
afe41eb
61c7e78
baf7351
6c279e4
a86ee13
022eb3e
f7c3170
801ae48
3276d49
8a071fd

Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
tests/test_provide_time.py (1)

1-5: ⚡ Quick win

Condense the module docstring to a single line.

The multi-line module docstring should be simplified to match project conventions. As per coding guidelines, docstrings should be terse and default to single-line format.

♻️ Proposed simplification
-"""Tests for the provide_time flag on APIClient / ConnectionParams.
-
-When provide_time=True (the default) the connection registers a handler
-device's clock in sync with the client, otherwise ignores time requests.
-"""
+"""Tests for the provide_time flag on APIClient / ConnectionParams."""

As per coding guidelines: "Docstrings should be terse and default to single-line format ("""Summary.""") describing what the function does and what the caller can pass. Multi-line docstrings are the exception, only justified when there is non-obvious caller-visible behaviour that the type signature and parameter names don't already convey."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_provide_time.py` around lines 1 - 5, Replace the multi-line module
docstring at the top of the tests/test_provide_time.py file with a single-line
terse docstring summarizing the module purpose (e.g., "Tests for the
provide_time flag on APIClient/ConnectionParams."); update the existing
triple-quoted block so it is one line only and preserves the same summary
wording to follow project docstring conventions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/test_provide_time.py`:
- Around line 1-5: Replace the multi-line module docstring at the top of the
tests/test_provide_time.py file with a single-line terse docstring summarizing
the module purpose (e.g., "Tests for the provide_time flag on
APIClient/ConnectionParams."); update the existing triple-quoted block so it is
one line only and preserves the same summary wording to follow project docstring
conventions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c80c04e6-b939-49ed-97cd-b73e8c94862a

📥 Commits

Reviewing files that changed from the base of the PR and between 0de112a and afe41eb.

📒 Files selected for processing (1)
  • tests/test_provide_time.py

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 23, 2026

Merging this PR will not alter performance

✅ 47 untouched benchmarks


Comparing clydebarrow:provide-time (8a071fd) with main (4e72197)

Open in CodSpeed

Comment thread tests/test_provide_time.py Outdated
Copy link
Copy Markdown
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 (2)
tests/test_provide_time.py (2)

58-58: ⚡ Quick win

Make the connection-patch helper private and keep helpers at the bottom.

patch_create_connection is test-internal but publicly named. Rename it to _patch_create_connection; also keep private helpers grouped below public tests for consistency.

🧹 Suggested rename
-    with patch_create_connection(loop, transport, connected):
+    with _patch_create_connection(loop, transport, connected):
         connect_task = asyncio.create_task(connect(conn, login=False))
         await connected.wait()
         send_plaintext_hello(conn._frame_helper)
         await connect_task
         return conn, transport, conn._frame_helper

-def patch_create_connection(loop, transport, connected):
+def _patch_create_connection(loop, transport, connected):
     return __import__("unittest.mock", fromlist=["patch"]).patch.object(
         loop,
         "create_connection",
         side_effect=partial(_create_mock_transport_protocol, transport, connected),
     )

As per coding guidelines, **/*.py: "Organize methods with public API at the top and private helpers (_underscore_prefixed) at the bottom."

Also applies to: 66-71

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_provide_time.py` at line 58, The helper function
patch_create_connection is test-internal but named and positioned like a public
API; rename the function to _patch_create_connection and update all its call
sites (e.g., the with patch_create_connection(loop, transport, connected):
usages) to use the new name, and move the helper definition to the bottom of the
file beneath the public tests so private helpers are grouped together per
project guidelines.

1-5: ⚡ Quick win

Use a terse single-line module docstring.

This docstring is multi-line and more verbose than needed for this test module.

✂️ Suggested simplification
-"""Tests for the provide_time flag on APIClient / ConnectionParams.
-
-When provide_time=True (the default) the connection registers a handler
-for GetTimeRequest and responds to it, otherwise ignores the request.
-"""
+"""Tests provide_time behavior for GetTimeRequest handling."""

As per coding guidelines, **/*.py: "Docstrings should be terse and default to single-line format ("""Summary.""")."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_provide_time.py` around lines 1 - 5, Replace the multi-line module
docstring at the top of tests/test_provide_time.py with a terse single-line
docstring summarizing the test (e.g., a one-line description of the provide_time
flag behavior); locate the module docstring that currently mentions
provide_time, APIClient / ConnectionParams and GetTimeRequest and condense it to
a single-line summary per project docstring guidelines.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_provide_time.py`:
- Around line 46-50: The return type annotation of _make_connected_conn is
wrong: it declares tuple[APIConnection, asyncio.Transport,
APIPlaintextFrameHelper, asyncio.Task] but the function actually returns (conn,
transport, conn._frame_helper); update the annotation on _make_connected_conn to
tuple[APIConnection, asyncio.Transport, APIPlaintextFrameHelper] (or
alternatively adjust the function to also return the asyncio.Task if intended),
ensuring the types match the actual returned variables conn, transport, and
conn._frame_helper.

---

Nitpick comments:
In `@tests/test_provide_time.py`:
- Line 58: The helper function patch_create_connection is test-internal but
named and positioned like a public API; rename the function to
_patch_create_connection and update all its call sites (e.g., the with
patch_create_connection(loop, transport, connected): usages) to use the new
name, and move the helper definition to the bottom of the file beneath the
public tests so private helpers are grouped together per project guidelines.
- Around line 1-5: Replace the multi-line module docstring at the top of
tests/test_provide_time.py with a terse single-line docstring summarizing the
test (e.g., a one-line description of the provide_time flag behavior); locate
the module docstring that currently mentions provide_time, APIClient /
ConnectionParams and GetTimeRequest and condense it to a single-line summary per
project docstring guidelines.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 64ed59dd-9f02-4fd0-875d-9a12a92d8b4f

📥 Commits

Reviewing files that changed from the base of the PR and between baf7351 and 022eb3e.

📒 Files selected for processing (1)
  • tests/test_provide_time.py

Comment thread tests/test_provide_time.py Outdated
@clydebarrow clydebarrow requested a review from bdraco May 23, 2026 07:19
@bdraco
Copy link
Copy Markdown
Member

bdraco commented May 23, 2026

@bluetoothbot review

Copy link
Copy Markdown
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

LGTM assuming the bot doesn't find something I missed

@bluetoothbot
Copy link
Copy Markdown
Contributor

@bdraco: Tests are failing. Looks like an update is needed

I reconstructed this exact diff on top of current main and ran it: all 4 tests in test_provide_time.py pass and the full suite is green (1184 passed, 1 skipped) in pure-Python mode, and the Cython transpile (setup.py build_ext) of the cythonized modules succeeds. So I couldn't reproduce a failure on the current revision — the failure may have been on the pre-rewrite version (before this was switched to the end-to-end approach). One caveat: I couldn't link the compiled extension in my environment (missing Python.h), so I can't fully rule out a Cython build/run-time failure. Could you point at which CI job is red (Python version / use_cython) and the failing assertion? Note the branch is based on an older main (4e72197); rebasing onto current main before re-running CI may also be worth a try.



def patch_create_connection(loop, transport, connected):
return __import__("unittest.mock", fromlist=["patch"]).patch.object(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This could be a bit cleaner and is inconsistant with the rest of the tests. Bot caught it above and had a suggestion.

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.

Displaying logs uses the same api as Home Assistant and sends the time zone which changes the time zone of the device

4 participants