Skip to content

Fix: Enable WebSocket updates for custom Modbus register devices#215

Open
JakubRanosz wants to merge 1 commit intoUnipiTechnology:mainfrom
JakubRanosz:fix-register-websocket-updates
Open

Fix: Enable WebSocket updates for custom Modbus register devices#215
JakubRanosz wants to merge 1 commit intoUnipiTechnology:mainfrom
JakubRanosz:fix-register-websocket-updates

Conversation

@JakubRanosz
Copy link

@JakubRanosz JakubRanosz commented Dec 17, 2025

Fix: Enable WebSocket updates for custom Modbus register devices

Closes #214

Problem

Modbus register devices (e.g., temperature sensors connected via RS485) were not sending value updates via WebSocket, even though:

  • Values could be successfully read via REST API
  • Communication with the device was working correctly
  • Other device types (AI, DI, RO, etc.) were sending updates as expected

This was a regression from Evok v2, where Modbus register updates were transmitted correctly.

Root Cause

The Register class was missing the necessary infrastructure to participate in the event notification system:

  1. No check_new_data() method to detect value changes
  2. Not registered as an "eventable device" during initialization
  3. No cached value tracking for change detection

As a result, the periodic scan loop would read register values but never detect changes or notify WebSocket clients.

Solution

This PR adds the missing event notification infrastructure to the Register class:

Changes Made

  1. Added value caching (_cached_value)

    • Stores the last read value for comparison
  2. Implemented check_new_data() method

    • Compares current value with cached value
    • Returns True when a change is detected
    • Updates the cached value for next comparison
  3. Registered Register devices as eventable

    • Added self.__register_eventable_device(_reg) in parse_feature_register()
    • Ensures Register devices are included in the scan loop's change detection
  4. Updated value property

    • Now uses cached value when available for consistency
    • Falls back to reading from hardware if cache is empty

Technical Details

The fix follows the same pattern used by other eventable devices (DigitalInput, DataPoint, etc.):

  • Store previous value
  • Compare on each scan cycle
  • Notify via WebSocket when changes occur

@cleveHEX cleveHEX removed their assignment Jan 7, 2026
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.

[Bug]: Modbus register updates not sent via WebSocket on Unipi Patron M207

3 participants