Improve subentry type detection

This commit is contained in:
2026-02-13 19:29:11 +01:00
parent 6de191b10b
commit 8b20cf4744
4 changed files with 29 additions and 9 deletions

View File

@@ -1,5 +1,8 @@
# Changelog # Changelog
## 0.0.8 - 2026-02-13
- Improve subentry type detection for HA versions exposing different class names.
## 0.0.7 - 2026-02-13 ## 0.0.7 - 2026-02-13
- Avoid crashing config entries when subentries are unsupported. - Avoid crashing config entries when subentries are unsupported.

View File

@@ -65,6 +65,6 @@ Each group address has `invert incoming` and `invert outgoing` toggles to flip K
- Advanced DPT mapping options and inversion settings. - Advanced DPT mapping options and inversion settings.
## Versioning and Releases ## Versioning and Releases
- Current version: 0.0.7 - Current version: 0.0.8
- `CHANGELOG.md` lists versions with the newest entries at the top. - `CHANGELOG.md` lists versions with the newest entries at the top.
- Release creation is manual and only done when explicitly requested. - Release creation is manual and only done when explicitly requested.

View File

@@ -28,9 +28,6 @@ from .const import (
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
KNX_DOMAIN = "knx" KNX_DOMAIN = "knx"
_SUBENTRY_TYPE = getattr(
config_entries, "SubentryType", getattr(config_entries, "ConfigEntrySubentryType", None)
)
class HAKnxBridgeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): class HAKnxBridgeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
@@ -68,19 +65,20 @@ class HAKnxBridgeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
@staticmethod @staticmethod
@callback @callback
def async_get_supported_subentry_types(config_entry): def async_get_supported_subentry_types(config_entry):
if _SUBENTRY_TYPE is None: subentry_type = _get_subentry_type()
if subentry_type is None:
_LOGGER.warning( _LOGGER.warning(
"Config subentries are not supported in this Home Assistant version" "Config subentries are not supported in this Home Assistant version"
) )
return {} return {}
return { return {
"binary_sensor": _SUBENTRY_TYPE( "binary_sensor": subentry_type(
name="Binary Sensor Port", flow_class=BinarySensorPortSubentryFlow name="Binary Sensor Port", flow_class=BinarySensorPortSubentryFlow
), ),
"switch": _SUBENTRY_TYPE( "switch": subentry_type(
name="Switch Port", flow_class=SwitchPortSubentryFlow name="Switch Port", flow_class=SwitchPortSubentryFlow
), ),
"cover": _SUBENTRY_TYPE( "cover": subentry_type(
name="Cover Port", flow_class=CoverPortSubentryFlow name="Cover Port", flow_class=CoverPortSubentryFlow
), ),
} }
@@ -354,3 +352,22 @@ def _invert_in_key(address_key: str) -> str:
def _invert_out_key(address_key: str) -> str: def _invert_out_key(address_key: str) -> str:
return f"{address_key}_{CONF_INVERT_OUTGOING}" return f"{address_key}_{CONF_INVERT_OUTGOING}"
def _get_subentry_type():
candidates = [
"SubentryType",
"ConfigEntrySubentryType",
"ConfigSubentryType",
"SubEntryType",
]
for name in candidates:
subentry_type = getattr(config_entries, name, None)
if subentry_type is not None:
return subentry_type
_LOGGER.debug(
"Subentry type class not found on homeassistant.config_entries. "
"Available attrs: %s",
", ".join(sorted(dir(config_entries))),
)
return None

View File

@@ -1,7 +1,7 @@
{ {
"domain": "ha_knx_bridge", "domain": "ha_knx_bridge",
"name": "HA KNX Bridge", "name": "HA KNX Bridge",
"version": "0.0.7", "version": "0.0.8",
"config_flow": true, "config_flow": true,
"documentation": "https://github.com/bahmcloud/HA-KNX-Bridge", "documentation": "https://github.com/bahmcloud/HA-KNX-Bridge",
"issue_tracker": "https://github.com/bahmcloud/HA-KNX-Bridge/issues", "issue_tracker": "https://github.com/bahmcloud/HA-KNX-Bridge/issues",