Skip to content

[Bug] TypeError in DC charger switch causes connection storm and sensor unavailability #276

@BaggyG-AU

Description

@BaggyG-AU

Integration version

1.1.9

Describe the bug

The DC charger switch entity (switch.sigen_inverter_dc_charger_dc_charging) throws a TypeError when checking the is_on state. This error occurs in switch.py line 116 when comparing NoneType with int, which happens when dc_charger_output_power returns None instead of a numeric value.

This TypeError triggers a cascade of effects:

  1. The integration repeatedly attempts to reconnect to recover from the error
  2. Modbus TCP connections accumulate in SYN_SENT state (observed 54+ stuck connections)
  3. The Sigenergy inverter becomes overwhelmed and stops responding
  4. All Sigenergy sensors become unavailable
  5. System requires Home Assistant restart to clear connections

Logs

Full TypeError Stack Trace:

2025-12-07 16:25:06.531 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 295, in _handle_refresh_interval
await self._async_refresh(log_failures=True, scheduled=True)
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 528, in _async_refresh
self.async_update_listeners()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 201, in async_update_listeners
update_callback()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 608, in _handle_coordinator_update
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1024, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1149, in _async_write_ha_state
self.__async_calculate_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1086, in __async_calculate_state
state = self._stringify_state(available)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1030, in _stringify_state
if (state := self.state) is None:
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1659, in state
if (is_on := self.is_on) is None:
File "/config/custom_components/sigen/switch.py", line 217, in is_on
return self.entity_description.is_on_fn(self.coordinator.data, identifier)
File "/config/custom_components/sigen/switch.py", line 116, in
is_on_fn=lambda data, identifier: data.get("dc_chargers", {}).get(identifier, {}).get("dc_charger_output_power", 0) > 0,
TypeError: '>' not supported between instances of 'NoneType' and 'int'

Connection Errors Following TypeError

2025-12-07 16:25:06.529 WARNING (MainThread) [custom_components.sigen.modbus] Modbus error reading interval at 41500 for inverter 'Sigen Inverter': Connection error: Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.50.177:502]
2025-12-07 16:25:36.028 WARNING (MainThread) [custom_components.sigen.modbus] ConnectionException/Timeout during read for 192.168.50.177:502@247 (address 30000): Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.50.177:502]. Marking connection as closed.
2025-12-07 16:25:38.207 WARNING (MainThread) [custom_components.sigen.modbus] ConnectionException/Timeout during read for 192.168.50.177:502@247 (address 30083): Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.50.177:502]. Marking connection as closed.
2025-12-07 16:25:38.327 WARNING (MainThread) [custom_components.sigen.modbus] ConnectionException/Timeout during read for 192.168.50.177:502@247 (address 30204): Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.50.177:502]. Marking connection as closed.
2025-12-07 16:25:38.446 WARNING (MainThread) [custom_components.sigen.modbus] ConnectionException/Timeout during read for 192.168.50.177:502@247 (address 40001): Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.50.177:502]. Marking connection as closed.

Diagnostics file

config_entry-sigen-01K9ZZHPHWAQ0XF4PVJWC6AGRE.json

Checklist

  • I searched existing issues and discussions.
  • I attached logs and/or diagnostics.
  • This is not a support request; it describes a reproducible bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions