Skip to content

Commit baf95d2

Browse files
authored
Merge pull request #2223 from rosenrot00/fix/descriptor-internal-guard
Prevent refresh failure for descriptions without internal attribute
2 parents b19c039 + 65fd98c commit baf95d2

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

custom_components/solax_modbus/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def should_register_be_loaded(hass: HomeAssistant, hub: Any, descriptor: Any) ->
189189
"""
190190
Check if an entity is enabled in the entity registry, checking across multiple platforms.
191191
"""
192-
if descriptor.internal:
192+
if getattr(descriptor, "internal", False):
193193
_LOGGER.debug(f"{hub.name}: should be loaded: entity with key {descriptor.key} is internal, returning True.")
194194
return True
195195
unique_id = f"{hub._name}_{descriptor.key}"

tests/unit/test_entity_loading.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Tests for entity-description loading decisions."""
2+
3+
from types import SimpleNamespace
4+
from typing import Any
5+
6+
import pytest
7+
8+
from custom_components.solax_modbus import should_register_be_loaded
9+
from custom_components.solax_modbus.const import BaseModbusSwitchEntityDescription
10+
11+
12+
def test_descriptor_without_internal_is_loaded_by_default(
13+
monkeypatch: pytest.MonkeyPatch,
14+
) -> None:
15+
"""Control descriptions without an internal field must not stop polling."""
16+
descriptor = BaseModbusSwitchEntityDescription(key="test_switch")
17+
hub = SimpleNamespace(name="Test hub", _name="Test hub")
18+
registry = SimpleNamespace(async_get_entity_id=lambda *_args: None)
19+
fake_hass: Any = object()
20+
monkeypatch.setattr(
21+
"custom_components.solax_modbus.er.async_get",
22+
lambda _hass: registry,
23+
)
24+
25+
assert not hasattr(descriptor, "internal")
26+
assert should_register_be_loaded(fake_hass, hub, descriptor)

0 commit comments

Comments
 (0)