Updated handling to resolve TextReadEntityType passed as unit_of_measurement causing recorder statistics failure#419
Open
kcoffau wants to merge 4 commits intosfstar:mainfrom
Open
Updated handling to resolve TextReadEntityType passed as unit_of_measurement causing recorder statistics failure#419kcoffau wants to merge 4 commits intosfstar:mainfrom
kcoffau wants to merge 4 commits intosfstar:mainfrom
Conversation
Added extended entity handling to cater for Venus 3.7.0
Handle TextReadEntityType in Victron sensor description
|
Much anticipated <3 |
|
I would be quite happy to have this fix, because now the integration is breaking all HA's statistics… Is there anything I can do to help? |
Contributor
Author
|
If you haven’t already, include your logs and what stat is causing it. Your plugin, HomeAssistant and victron Venus os version Sent from my iPhoneOn 15 Mar 2026, at 04:58, Geert Folkertsma ***@***.***> wrote:GeertFolkertsma left a comment (sfstar/hass-victron#419)
I would be quite happy to have this fix, because now the integration is breaking all HA's statistics… Is there anything I can do to help?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
|
Actually, this is not what caused (or at least) solved the bug in my case; I had to apply #424 to make it work. I can imagine that this fix addresses other, rarer problems—the microgrid error seems to have had a different cause. |
Enhanced VictronHub to support TCP keepalive and configurable Modbus retries after transport errors. Updated configuration flow and translations to include new options. Improved error handling for transport-related exceptions during Modbus operations.
Contributor
Author
|
Added extra configuration for Modbus TCP resilience. Keep Alive and retries. |
Contributor
Author
|
@sfstar for your review. |
Contributor
Author
Added advanced Modbus TCP settings section with details on TCP Keep Alive and Modbus TCP Retries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Breaking change
Proposed change
Type of change
Additional information
When Home Assistant's recorder attempts to compile statistics for Victron text/enum sensor entities (e.g. sensor.victronvebus_microgrid_error), it crashes with:
sqlalchemy.exc.ProgrammingError: (sqlite3.ProgrammingError) Error binding parameter 3:
type 'TextReadEntityType' is not supported
[SQL: INSERT INTO statistics_meta (statistic_id, source, unit_of_measurement, ...) VALUES ...]
[parameters: ('sensor.victronvebus_microgrid_error227', 'recorder',
<custom_components.victron.const.TextReadEntityType object at 0x...>, ...)]
This occurs because registerInfo.unit for TextReadEntityType registers holds a TextReadEntityType object rather than a plain string or None. The HA recorder passes this directly to SQLite as a bind parameter, which SQLite cannot handle, causing the statistics task to fail on every cycle. The result is that all history recording stops for the entire HA instance, not just the affected entity.
Root Cause
In async_setup_entry within sensor.py, the VictronEntityDescription is constructed without guarding against non-string unit values for text entities:
python# Before — passes TextReadEntityType object directly
description = VictronEntityDescription(
native_unit_of_measurement=registerInfo.unit, # ← object, not string
state_class=registerInfo.determine_stateclass(), # ← meaningless for text entities
device_class=determine_victron_device_class(...) # ← unit is not a string here
...
)
Fix
Guard all three unit-dependent properties against TextReadEntityType instances, returning None for text entities which have no meaningful numeric unit, state class, or device class:
python# After — safely returns None for text entities
is_text_entity = isinstance(registerInfo.entityType, TextReadEntityType)
description = VictronEntityDescription(
native_unit_of_measurement=registerInfo.unit if not is_text_entity else None,
state_class=registerInfo.determine_stateclass() if not is_text_entity else None,
device_class=determine_victron_device_class(register_name, registerInfo.unit) if not is_text_entity else None,
...
)
Impact
Fixes recorder statistics failure for all users with any text/enum Victron entities present
Restores full HA history recording which is blocked by this error
No functional change to how text entity values are decoded or displayed — only the metadata passed to the recorder changes
Affects any unit ID that exposes text registers (e.g. unit 227 microgrid_error, mode registers, alarm state registers)
Testing
Verified by checking HA logs after applying the patch — Unhandled database error while processing StatisticsTask errors no longer appear and history recording resumes for all entities.
HA Version Confirmed Affected
Home Assistant OS 17.1 / Core 2026.2.3
Checklist
ruff format custom_components/victron)