mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Update xknx to 4.0.0 (#186650)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
271ec84bcb
commit
148d431c21
@@ -177,7 +177,7 @@ class KnxUiBinarySensor(_KnxBinarySensor, KnxUiEntity):
|
||||
knx_conf = config.knx
|
||||
self._device = XknxBinarySensor(
|
||||
xknx=knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
group_address_state=state_and_passive(knx_conf.ga_sensor),
|
||||
sync_state=knx_conf.sync_state,
|
||||
invert=knx_conf.invert,
|
||||
|
||||
@@ -114,15 +114,16 @@ class KnxUiButton(_KnxButton, KnxUiEntity):
|
||||
self._payload = payload
|
||||
self._device = XknxRawValue(
|
||||
xknx=knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
payload_length=payload_length,
|
||||
group_address=ga_send.write,
|
||||
)
|
||||
case PayloadValue(value=value):
|
||||
self._payload = value
|
||||
assert ga_send.dpt is not None # a value requires a DPT - validated
|
||||
self._device = XknxExposeSensor(
|
||||
xknx=knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
value_type=ga_send.dpt,
|
||||
group_address=ga_send.write,
|
||||
respond_to_read=False,
|
||||
|
||||
@@ -197,7 +197,9 @@ def _create_climate_yaml(xknx: XKNX, config: ConfigType) -> XknxClimate:
|
||||
)
|
||||
|
||||
|
||||
def _create_climate_ui(xknx: XKNX, conf: ClimateKnxConfig, name: str) -> XknxClimate:
|
||||
def _create_climate_ui(
|
||||
xknx: XKNX, conf: ClimateKnxConfig, name: str | None
|
||||
) -> XknxClimate:
|
||||
"""Return a KNX Climate device to be used within XKNX from UI config."""
|
||||
op_modes: list[str | HVACOperationMode] = list(HVACOperationMode)
|
||||
if conf.ignore_auto_mode:
|
||||
@@ -205,7 +207,7 @@ def _create_climate_ui(xknx: XKNX, conf: ClimateKnxConfig, name: str) -> XknxCli
|
||||
|
||||
climate_mode = XknxClimateMode(
|
||||
xknx,
|
||||
name=f"{name} Mode",
|
||||
name=f"{name} Mode" if name else None,
|
||||
group_address_operation_mode=write_address(conf.ga_operation_mode),
|
||||
group_address_operation_mode_state=state_and_passive(conf.ga_operation_mode),
|
||||
group_address_operation_mode_comfort=write_and_passive(
|
||||
@@ -693,9 +695,7 @@ class KnxUiClimate(_KnxClimate, KnxUiEntity):
|
||||
entity_config=config.entity,
|
||||
)
|
||||
knx_conf = config.knx
|
||||
self._device = _create_climate_ui(
|
||||
knx_module.xknx, knx_conf, config.entity.xknx_name
|
||||
)
|
||||
self._device = _create_climate_ui(knx_module.xknx, knx_conf, config.entity.name)
|
||||
|
||||
default_hvac_mode = HVACMode(knx_conf.default_controller_mode)
|
||||
fan_max_step = knx_conf.fan_max_step
|
||||
|
||||
@@ -270,7 +270,7 @@ class KnxYamlCover(_KnxCover, KnxYamlEntity):
|
||||
self._attr_device_class = custom_device_class
|
||||
|
||||
|
||||
def _create_ui_cover(xknx: XKNX, conf: CoverKnxConfig, name: str) -> XknxCover:
|
||||
def _create_ui_cover(xknx: XKNX, conf: CoverKnxConfig, name: str | None) -> XknxCover:
|
||||
"""Return a KNX Cover device to be used within XKNX."""
|
||||
return XknxCover(
|
||||
xknx=xknx,
|
||||
@@ -308,7 +308,5 @@ class KnxUiCover(_KnxCover, KnxUiEntity):
|
||||
unique_id=unique_id,
|
||||
entity_config=config.entity,
|
||||
)
|
||||
self._device = _create_ui_cover(
|
||||
knx_module.xknx, config.knx, config.entity.xknx_name
|
||||
)
|
||||
self._device = _create_ui_cover(knx_module.xknx, config.knx, config.entity.name)
|
||||
self.init_base()
|
||||
|
||||
@@ -140,7 +140,7 @@ class KnxUiDate(_KNXDate, KnxUiEntity):
|
||||
knx_conf = config.knx
|
||||
self._device = XknxDateDevice(
|
||||
knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
localtime=False,
|
||||
group_address=knx_conf.ga_date.write,
|
||||
group_address_state=state_and_passive(knx_conf.ga_date),
|
||||
|
||||
@@ -145,7 +145,7 @@ class KnxUiDateTime(_KNXDateTime, KnxUiEntity):
|
||||
knx_conf = config.knx
|
||||
self._device = XknxDateTimeDevice(
|
||||
knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
localtime=False,
|
||||
group_address=knx_conf.ga_datetime.write,
|
||||
group_address_state=state_and_passive(knx_conf.ga_datetime),
|
||||
|
||||
@@ -155,6 +155,8 @@ class _KnxEntityBase(Entity):
|
||||
@override
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Store register state change callback and start device object."""
|
||||
# xknx log messages and exceptions name the device
|
||||
self._device.name = self.entity_id
|
||||
self._device.register_device_updated_cb(self.after_update_callback)
|
||||
self._device.xknx.devices.async_add(self._device)
|
||||
if uid := self.unique_id:
|
||||
@@ -172,6 +174,13 @@ class _KnxEntityBase(Entity):
|
||||
# eg. for restoring state (like _KNXSwitch)
|
||||
await super().async_added_to_hass()
|
||||
|
||||
@callback
|
||||
@override
|
||||
def async_entity_id_changed(self, old_entity_id: str) -> None:
|
||||
"""Rename the xknx device after the new entity_id."""
|
||||
super().async_entity_id_changed(old_entity_id)
|
||||
self._device.name = self.entity_id
|
||||
|
||||
@override
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
"""Disconnect device object when removed."""
|
||||
|
||||
@@ -276,7 +276,7 @@ class KnxUiFan(_KnxFan, KnxUiEntity):
|
||||
|
||||
self._device = XknxFan(
|
||||
xknx=knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
group_address_speed=write_address(speed_ga),
|
||||
group_address_speed_state=state_and_passive(speed_ga),
|
||||
group_address_oscillation=write_address(knx_conf.ga_oscillation),
|
||||
|
||||
@@ -267,12 +267,10 @@ class KNXModule:
|
||||
# Not all telegrams have serializable data.
|
||||
data: int | tuple[int, ...] | None = None
|
||||
value = None
|
||||
if (
|
||||
isinstance(telegram.payload, (GroupValueWrite, GroupValueResponse))
|
||||
and telegram.payload.value is not None
|
||||
and isinstance(
|
||||
telegram.destination_address, (GroupAddress, InternalGroupAddress)
|
||||
)
|
||||
if isinstance(
|
||||
telegram.payload, (GroupValueWrite, GroupValueResponse)
|
||||
) and isinstance(
|
||||
telegram.destination_address, (GroupAddress, InternalGroupAddress)
|
||||
):
|
||||
data = telegram.payload.value.value
|
||||
if transcoder := (
|
||||
|
||||
@@ -192,7 +192,7 @@ def _create_yaml_light(xknx: XKNX, config: ConfigType) -> XknxLight:
|
||||
)
|
||||
|
||||
|
||||
def _create_ui_light(xknx: XKNX, conf: LightKnxConfig, name: str) -> XknxLight:
|
||||
def _create_ui_light(xknx: XKNX, conf: LightKnxConfig, name: str | None) -> XknxLight:
|
||||
"""Return a KNX Light device to be used within XKNX."""
|
||||
group_address_tunable_white = None
|
||||
group_address_tunable_white_state = None
|
||||
@@ -599,9 +599,7 @@ class KnxUiLight(_KnxLight, KnxUiEntity):
|
||||
unique_id=unique_id,
|
||||
entity_config=config.entity,
|
||||
)
|
||||
self._device = _create_ui_light(
|
||||
knx_module.xknx, config.knx, config.entity.xknx_name
|
||||
)
|
||||
self._device = _create_ui_light(knx_module.xknx, config.knx, config.entity.name)
|
||||
self._attr_color_mode = next(iter(self.supported_color_modes))
|
||||
self._attr_max_color_temp_kelvin = config.knx.color_temp_max
|
||||
self._attr_min_color_temp_kelvin = config.knx.color_temp_min
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"loggers": ["xknx", "xknxproject"],
|
||||
"quality_scale": "platinum",
|
||||
"requirements": [
|
||||
"xknx==3.20.0",
|
||||
"xknx==4.0.0",
|
||||
"xknxproject==3.10.0",
|
||||
"knx-frontend==2026.10.5.160528",
|
||||
"knx-telegram-store[sqlite,postgres]==0.14.0"
|
||||
|
||||
@@ -108,9 +108,10 @@ class KnxUiNotify(_KnxNotify, KnxUiEntity):
|
||||
entity_config=config.entity,
|
||||
)
|
||||
knx_conf = config.knx
|
||||
assert knx_conf.ga_send.dpt is not None # required for notify
|
||||
self._device = XknxNotification(
|
||||
knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
group_address=knx_conf.ga_send.write,
|
||||
value_type=knx_conf.ga_send.dpt,
|
||||
)
|
||||
|
||||
@@ -185,7 +185,7 @@ class KnxUiNumber(_KnxNumber, KnxUiEntity):
|
||||
|
||||
self._device = NumericValue(
|
||||
knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
group_address=knx_conf.ga_sensor.write,
|
||||
group_address_state=state_and_passive(knx_conf.ga_sensor),
|
||||
respond_to_read=knx_conf.respond_to_read,
|
||||
|
||||
@@ -74,7 +74,8 @@ class _KnxScene(BaseScene, _KnxEntityBase):
|
||||
@override
|
||||
def after_update_callback(self, device: XknxDevice) -> None:
|
||||
"""Call after device was updated."""
|
||||
self._async_record_activation()
|
||||
if not self._device.learn_requested:
|
||||
self._async_record_activation()
|
||||
super().after_update_callback(device)
|
||||
|
||||
|
||||
@@ -120,7 +121,7 @@ class KnxUiScene(_KnxScene, KnxUiEntity):
|
||||
knx_conf = config.knx
|
||||
self._device = XknxScene(
|
||||
xknx=knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
group_address=knx_conf.ga_scene.write,
|
||||
scene_number=knx_conf.scene_number,
|
||||
)
|
||||
|
||||
@@ -234,7 +234,7 @@ class KnxUiSelect(_KNXSelect, KnxUiEntity):
|
||||
|
||||
self._device = RawValue(
|
||||
knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
payload_length=payload_length,
|
||||
group_address=group_address.write,
|
||||
group_address_state=state_and_passive(group_address),
|
||||
|
||||
@@ -264,7 +264,7 @@ class KnxUiSensor(_KnxSensor, KnxUiEntity):
|
||||
|
||||
self._device = XknxSensor(
|
||||
knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
group_address_state=state_and_passive(knx_conf.ga_sensor),
|
||||
sync_state=knx_conf.sync_state,
|
||||
always_callback=True,
|
||||
|
||||
@@ -75,11 +75,6 @@ class BaseEntityConfig:
|
||||
EntityCategory | None, probatio.Coerce(parse_entity_category)
|
||||
] = None
|
||||
|
||||
@property
|
||||
def xknx_name(self) -> str:
|
||||
"""Name of the xknx device, empty when HA names the entity after its device."""
|
||||
return self.name or ""
|
||||
|
||||
|
||||
def _name_or_device_required(config: BaseEntityConfig) -> BaseEntityConfig:
|
||||
"""Require a name, unless the entity is named after its device."""
|
||||
|
||||
@@ -143,7 +143,7 @@ class KnxUiSwitch(_KnxSwitch, KnxUiEntity):
|
||||
knx_conf = config.knx
|
||||
self._device = XknxSwitch(
|
||||
knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
group_address=knx_conf.ga_switch.write,
|
||||
group_address_state=state_and_passive(knx_conf.ga_switch),
|
||||
respond_to_read=knx_conf.respond_to_read,
|
||||
|
||||
@@ -156,9 +156,10 @@ class KnxUiText(_KnxText, KnxUiEntity):
|
||||
entity_config=config.entity,
|
||||
)
|
||||
knx_conf = config.knx
|
||||
assert knx_conf.ga_text.dpt is not None # required for text
|
||||
self._device = XknxNotification(
|
||||
knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
group_address=knx_conf.ga_text.write,
|
||||
group_address_state=state_and_passive(knx_conf.ga_text),
|
||||
respond_to_read=knx_conf.respond_to_read,
|
||||
|
||||
@@ -140,7 +140,7 @@ class KnxUiTime(_KNXTime, KnxUiEntity):
|
||||
knx_conf = config.knx
|
||||
self._device = XknxTimeDevice(
|
||||
knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
localtime=False,
|
||||
group_address=knx_conf.ga_time.write,
|
||||
group_address_state=state_and_passive(knx_conf.ga_time),
|
||||
|
||||
@@ -82,14 +82,14 @@ def async_subscribe_telegrams(
|
||||
telegram: Telegram, telegram_dict: TelegramDict
|
||||
) -> None:
|
||||
"""Filter Telegram and call the callback."""
|
||||
payload_apci = type(telegram.payload)
|
||||
if payload_apci is GroupValueWrite:
|
||||
payload = telegram.payload
|
||||
if isinstance(payload, GroupValueWrite):
|
||||
if options[CONF_KNX_GROUP_VALUE_WRITE] is False:
|
||||
return
|
||||
elif payload_apci is GroupValueResponse:
|
||||
elif isinstance(payload, GroupValueResponse):
|
||||
if options[CONF_KNX_GROUP_VALUE_RESPONSE] is False:
|
||||
return
|
||||
elif payload_apci is GroupValueRead:
|
||||
elif isinstance(payload, GroupValueRead):
|
||||
if options[CONF_KNX_GROUP_VALUE_READ] is False:
|
||||
return
|
||||
|
||||
@@ -104,11 +104,11 @@ def async_subscribe_telegrams(
|
||||
|
||||
if (
|
||||
trigger_transcoder is not None
|
||||
and payload_apci in (GroupValueWrite, GroupValueResponse)
|
||||
and isinstance(payload, (GroupValueWrite, GroupValueResponse))
|
||||
and trigger_transcoder.value_type != telegram_dict["dpt_name"]
|
||||
):
|
||||
decoded_payload = decode_telegram_payload(
|
||||
payload=telegram.payload.value, # type: ignore[union-attr] # checked via payload_apci
|
||||
payload=payload.value,
|
||||
transcoder=trigger_transcoder,
|
||||
)
|
||||
# overwrite decoded payload values in telegram_dict
|
||||
|
||||
@@ -190,7 +190,7 @@ class KnxUiWeather(_KnxWeather, KnxUiEntity):
|
||||
knx_conf = config.knx
|
||||
self._device = XknxWeather(
|
||||
knx_module.xknx,
|
||||
name=config.entity.xknx_name,
|
||||
name=config.entity.name,
|
||||
sync_state=knx_conf.sync_state,
|
||||
group_address_temperature=state_and_passive(knx_conf.ga_temperature),
|
||||
group_address_brightness_south=state_and_passive(
|
||||
|
||||
Generated
+1
-1
@@ -3500,7 +3500,7 @@ xiaomi-ble==1.16.1
|
||||
xiaomi-weather==0.1.0
|
||||
|
||||
# homeassistant.components.knx
|
||||
xknx==3.20.0
|
||||
xknx==4.0.0
|
||||
|
||||
# homeassistant.components.knx
|
||||
xknxproject==3.10.0
|
||||
|
||||
@@ -368,8 +368,8 @@ async def test_climate_preset_mode(
|
||||
knx.assert_state("climate.test", HVACMode.HEAT, preset_mode="economy")
|
||||
|
||||
assert len(knx.xknx.devices) == 2
|
||||
assert len(knx.xknx.devices[0].device_updated_cbs) == 2
|
||||
assert len(knx.xknx.devices[1].device_updated_cbs) == 2
|
||||
for device in knx.xknx.devices:
|
||||
assert len(device.device_updated_cbs) == 2
|
||||
# test removing also removes hooks
|
||||
entity_registry.async_remove("climate.test")
|
||||
# If we remove the entity the underlying devices should disappear too
|
||||
|
||||
@@ -205,6 +205,28 @@ async def test_yaml_entity_device_naming(
|
||||
assert states[0].attributes["friendly_name"] == expected_friendly_name
|
||||
|
||||
|
||||
async def test_xknx_device_named_after_entity_id(
|
||||
hass: HomeAssistant,
|
||||
knx: KNXTestKit,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""The xknx device carries the entity_id as name and follows a rename."""
|
||||
await knx.setup_integration(
|
||||
{Platform.SWITCH: {"name": "test", KNX_ADDRESS: "1/1/1"}}
|
||||
)
|
||||
(device,) = knx.xknx.devices
|
||||
assert device.name == "switch.test"
|
||||
assert device.switch.device_name == "switch.test"
|
||||
|
||||
entity_registry.async_update_entity("switch.test", new_entity_id="switch.renamed")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("switch.renamed") is not None
|
||||
(device,) = knx.xknx.devices
|
||||
assert device.name == "switch.renamed"
|
||||
assert device.switch.device_name == "switch.renamed"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("device_id", "expected_identifier"),
|
||||
[
|
||||
|
||||
@@ -231,7 +231,7 @@ async def test_number_yaml_attribute_validation(
|
||||
"device_class": "temperature", # from DPT
|
||||
"unit_of_measurement": "°C",
|
||||
"min": -273.0,
|
||||
"max": 670760.0,
|
||||
"max": 670433.28,
|
||||
"step": 0.01,
|
||||
},
|
||||
),
|
||||
|
||||
@@ -62,6 +62,12 @@ async def test_activate_knx_scene(
|
||||
# different scene number - should not be recorded
|
||||
await knx.receive_write("1/1/1", (0x00,))
|
||||
assert len(events) == 4
|
||||
# learn request for this scene number - should not be recorded
|
||||
await knx.receive_write("1/1/1", (0x97,))
|
||||
assert len(events) == 4
|
||||
# activation after a learn request is recorded again
|
||||
await knx.receive_write("1/1/1", (0x17,))
|
||||
assert len(events) == 5
|
||||
|
||||
|
||||
async def test_scene_ui_create(
|
||||
|
||||
Reference in New Issue
Block a user