Skip to content

Fix device info timeout in TOU schedule example#22

Merged
eman merged 2 commits intomainfrom
fix-tou-device-info-timeout
Oct 17, 2025
Merged

Fix device info timeout in TOU schedule example#22
eman merged 2 commits intomainfrom
fix-tou-device-info-timeout

Conversation

@eman
Copy link
Copy Markdown
Owner

@eman eman commented Oct 17, 2025

Problem

The tou_schedule_example.py was consistently timing out when trying to get the controller serial number, showing this error:

Requesting controller serial number via device info...
Timed out waiting for device features

Root Cause

The _wait_for_controller_serial function was using the event emitter to wait for feature_received events without first subscribing to device feature messages:

# ❌ Problematic code
mqtt_client.once("feature_received", capture_feature)
await mqtt_client.request_device_info(device)

The feature_received event is only emitted when a device feature message is received and parsed by a subscribed handler. Without the subscription, the MQTT client never receives the response messages.

Solution

Fixed the function to properly subscribe to device feature messages before making the request:

# ✅ Fixed code
await mqtt_client.subscribe_device_feature(device, capture_feature)
await mqtt_client.request_device_info(device)

This ensures:

  1. MQTT subscription is established for device feature messages
  2. The response messages are received and parsed
  3. The feature_received event is properly emitted
  4. The timeout is avoided

Verification

  • Pattern now matches successful examples like device_feature_callback.py
  • Other event emitter usage (like event_emitter_demo.py) is correctly implemented
  • Code passes linting and formatting checks

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change
  • Documentation update

Impact

This fix ensures the TOU schedule example works correctly and can successfully retrieve the controller serial number needed for TOU operations.

eman added 2 commits October 17, 2025 13:37
…s example

The availableEnergyCapacity field represents energy in Watt-hours (Wh),
not a percentage. Updated the display format from '{value}%' to '{value} Wh'.

This prevents confusing output like 'Available Energy: 709.0%' which
doesn't make sense for a percentage value.
…example

The _wait_for_controller_serial function was using the event emitter to
wait for 'feature_received' events without first subscribing to device
feature messages. This caused timeouts because the feature_received event
is only emitted when a feature message is received and parsed.

Changes:
- Call subscribe_device_feature() before request_device_info()
- This ensures the MQTT subscription is established before the request
- Resolves 'Timed out waiting for device features' errors

The pattern now matches other examples like device_feature_callback.py
that successfully retrieve device features.
@eman eman merged commit c7bdb34 into main Oct 17, 2025
10 checks passed
@eman eman deleted the fix-tou-device-info-timeout branch October 17, 2025 21:03
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.

1 participant