Disable USB discovery for teleinfo (#170933)

This commit is contained in:
puddly
2026-05-19 08:20:20 +00:00
committed by Franck Nijhof
parent 95cc9aed64
commit 2f35ad2a8a
4 changed files with 35 additions and 31 deletions
@@ -92,16 +92,6 @@ class TeleinfoConfigFlow(ConfigFlow, domain=DOMAIN):
usb.get_serial_by_id, discovery_info.device
)
# Validate by reading a real Teleinfo frame — silent abort on failure
errors, decoded_data = await self._validate_serial_port(dev_path)
if errors or decoded_data is None:
return self.async_abort(reason="not_teleinfo_device")
# Use ADCO (meter serial number) as unique_id — same as manual entry
adco = decoded_data["ADCO"]
await self.async_set_unique_id(adco)
self._abort_if_unique_id_configured(updates={CONF_SERIAL_PORT: dev_path})
self._discovered_device = dev_path
self.context["title_placeholders"] = {
"name": human_readable_device_name(
@@ -122,6 +112,20 @@ class TeleinfoConfigFlow(ConfigFlow, domain=DOMAIN):
if TYPE_CHECKING:
assert self._discovered_device is not None
if user_input is not None:
# Validate by reading a real Teleinfo frame — silent abort on failure
errors, decoded_data = await self._validate_serial_port(
self._discovered_device
)
if errors or decoded_data is None:
return self.async_abort(reason="not_teleinfo_device")
# Use ADCO (meter serial number) as unique_id — same as manual entry
adco = decoded_data["ADCO"]
await self.async_set_unique_id(adco)
self._abort_if_unique_id_configured(
updates={CONF_SERIAL_PORT: self._discovered_device}
)
return self.async_create_entry(
title=f"Teleinfo ({self._discovered_device})",
data={CONF_SERIAL_PORT: self._discovered_device},
@@ -8,15 +8,5 @@
"integration_type": "device",
"iot_class": "local_polling",
"quality_scale": "silver",
"requirements": ["pyteleinfo==0.4.0"],
"usb": [
{
"pid": "6015",
"vid": "0403"
},
{
"pid": "EA60",
"vid": "10C4"
}
]
"requirements": ["pyteleinfo==0.4.0"]
}
-10
View File
@@ -58,16 +58,6 @@ USB = [
"pid": "0003",
"vid": "04B4",
},
{
"domain": "teleinfo",
"pid": "6015",
"vid": "0403",
},
{
"domain": "teleinfo",
"pid": "EA60",
"vid": "10C4",
},
{
"domain": "velbus",
"pid": "0B1B",
@@ -170,6 +170,11 @@ async def test_usb_discovery_not_teleinfo(
data=USB_DISCOVERY_INFO,
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "usb_confirm"
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "not_teleinfo_device"
@@ -202,6 +207,11 @@ async def test_usb_discovery_already_configured_updates_path(
),
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "usb_confirm"
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
# Path should be updated to the new device path
@@ -225,6 +235,11 @@ async def test_usb_discovery_manual_entry_duplicate(
data=USB_DISCOVERY_INFO,
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "usb_confirm"
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
@@ -244,5 +259,10 @@ async def test_usb_discovery_decode_error_aborts(
data=USB_DISCOVERY_INFO,
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "usb_confirm"
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "not_teleinfo_device"