diff --git a/homeassistant/components/knx/__init__.py b/homeassistant/components/knx/__init__.py index 5caa284cc48..a8a923dc00a 100644 --- a/homeassistant/components/knx/__init__.py +++ b/homeassistant/components/knx/__init__.py @@ -15,7 +15,8 @@ from xknx.io import ( ConnectionConfig, ConnectionType, ) -from xknx.telegram import AddressFilter, GroupAddress, Telegram +from xknx.telegram import AddressFilter, Telegram +from xknx.telegram.address import parse_device_group_address from xknx.telegram.apci import GroupValueRead, GroupValueResponse, GroupValueWrite from homeassistant.const import ( @@ -412,7 +413,7 @@ class KNXModule: async def service_event_register_modify(self, call: ServiceCall) -> None: """Service for adding or removing a GroupAddress to the knx_event filter.""" attr_address = call.data[KNX_ADDRESS] - group_addresses = map(GroupAddress, attr_address) + group_addresses = map(parse_device_group_address, attr_address) if call.data.get(SERVICE_KNX_ATTR_REMOVE): for group_address in group_addresses: @@ -483,7 +484,7 @@ class KNXModule: for address in attr_address: telegram = Telegram( - destination_address=GroupAddress(address), + destination_address=parse_device_group_address(address), payload=GroupValueWrite(payload), ) await self.xknx.telegrams.put(telegram) @@ -492,7 +493,7 @@ class KNXModule: """Service for sending a GroupValueRead telegram to the KNX bus.""" for address in call.data[KNX_ADDRESS]: telegram = Telegram( - destination_address=GroupAddress(address), + destination_address=parse_device_group_address(address), payload=GroupValueRead(), ) await self.xknx.telegrams.put(telegram) diff --git a/homeassistant/components/knx/manifest.json b/homeassistant/components/knx/manifest.json index 5f8711141e3..bcca5855bf1 100644 --- a/homeassistant/components/knx/manifest.json +++ b/homeassistant/components/knx/manifest.json @@ -2,7 +2,7 @@ "domain": "knx", "name": "KNX", "documentation": "https://www.home-assistant.io/integrations/knx", - "requirements": ["xknx==0.18.0"], + "requirements": ["xknx==0.18.1"], "codeowners": ["@Julius2342", "@farmio", "@marvin-w"], "quality_scale": "silver", "iot_class": "local_push" diff --git a/homeassistant/components/knx/schema.py b/homeassistant/components/knx/schema.py index fb4b29fbd70..dc5a09534ec 100644 --- a/homeassistant/components/knx/schema.py +++ b/homeassistant/components/knx/schema.py @@ -1,8 +1,13 @@ """Voluptuous schemas for the KNX integration.""" +from __future__ import annotations + +from typing import Any + import voluptuous as vol from xknx.devices.climate import SetpointShiftMode +from xknx.exceptions import CouldNotParseAddress from xknx.io import DEFAULT_MCAST_PORT -from xknx.telegram.address import GroupAddress, IndividualAddress +from xknx.telegram.address import IndividualAddress, parse_device_group_address from homeassistant.const import ( CONF_DEVICE_CLASS, @@ -29,11 +34,20 @@ from .const import ( # KNX VALIDATORS ################## -ga_validator = vol.Any( - cv.matches_regex(GroupAddress.ADDRESS_RE.pattern), - vol.All(vol.Coerce(int), vol.Range(min=1, max=65535)), - msg="value does not match pattern for KNX group address '
//', '
/' or '' (eg.'1/2/3', '9/234', '123')", -) + +def ga_validator(value: Any) -> str | int: + """Validate that value is parsable as GroupAddress or InternalGroupAddress.""" + if isinstance(value, (str, int)): + try: + parse_device_group_address(value) + return value + except CouldNotParseAddress: + pass + raise vol.Invalid( + f"value '{value}' is not a valid KNX group address '
//', '
/' or '' (eg.'1/2/3', '9/234', '123'), nor xknx internal address 'i-'." + ) + + ga_list_validator = vol.All(cv.ensure_list, [ga_validator]) ia_validator = vol.Any( diff --git a/requirements_all.txt b/requirements_all.txt index bfb926195ac..81af5e09aa3 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2353,7 +2353,7 @@ xbox-webapi==2.0.8 xboxapi==2.0.1 # homeassistant.components.knx -xknx==0.18.0 +xknx==0.18.1 # homeassistant.components.bluesound # homeassistant.components.rest diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 50f0d3b70ca..e74d0517ccb 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1244,7 +1244,7 @@ wolf_smartset==0.1.8 xbox-webapi==2.0.8 # homeassistant.components.knx -xknx==0.18.0 +xknx==0.18.1 # homeassistant.components.bluesound # homeassistant.components.rest