|
10 | 10 | from pylint.lint import PyLinter
|
11 | 11 |
|
12 | 12 | from homeassistant.const import Platform
|
| 13 | +from homeassistant.helpers.typing import UNDEFINED |
13 | 14 |
|
14 | 15 |
|
15 | 16 | @dataclass
|
@@ -39,9 +40,9 @@ class TypeHintMatch:
|
39 | 40 | f"^homeassistant\\.components\\.\\w+\\.({'|'.join([platform.value for platform in Platform])})$"
|
40 | 41 | ),
|
41 | 42 | # device_tracker matches only in the package root (device_tracker.py)
|
42 |
| - "device_tracker": re.compile( |
43 |
| - f"^homeassistant\\.components\\.\\w+\\.({Platform.DEVICE_TRACKER.value})$" |
44 |
| - ), |
| 43 | + "device_tracker": re.compile(r"^homeassistant\.components\.\w+\.(device_tracker)$"), |
| 44 | + # diagnostics matches only in the package root (diagnostics.py) |
| 45 | + "diagnostics": re.compile(r"^homeassistant\.components\.\w+\.(diagnostics)$"), |
45 | 46 | }
|
46 | 47 |
|
47 | 48 | _METHOD_MATCH: list[TypeHintMatch] = [
|
@@ -171,11 +172,33 @@ class TypeHintMatch:
|
171 | 172 | },
|
172 | 173 | return_type=["DeviceScanner", "DeviceScanner | None"],
|
173 | 174 | ),
|
| 175 | + TypeHintMatch( |
| 176 | + module_filter=_MODULE_FILTERS["diagnostics"], |
| 177 | + function_name="async_get_config_entry_diagnostics", |
| 178 | + arg_types={ |
| 179 | + 0: "HomeAssistant", |
| 180 | + 1: "ConfigEntry", |
| 181 | + }, |
| 182 | + return_type=UNDEFINED, |
| 183 | + ), |
| 184 | + TypeHintMatch( |
| 185 | + module_filter=_MODULE_FILTERS["diagnostics"], |
| 186 | + function_name="async_get_device_diagnostics", |
| 187 | + arg_types={ |
| 188 | + 0: "HomeAssistant", |
| 189 | + 1: "ConfigEntry", |
| 190 | + 2: "DeviceEntry", |
| 191 | + }, |
| 192 | + return_type=UNDEFINED, |
| 193 | + ), |
174 | 194 | ]
|
175 | 195 |
|
176 | 196 |
|
177 | 197 | def _is_valid_type(expected_type: list[str] | str | None, node: astroid.NodeNG) -> bool:
|
178 | 198 | """Check the argument node against the expected type."""
|
| 199 | + if expected_type is UNDEFINED: |
| 200 | + return True |
| 201 | + |
179 | 202 | if isinstance(expected_type, list):
|
180 | 203 | for expected_type_item in expected_type:
|
181 | 204 | if _is_valid_type(expected_type_item, node):
|
|
0 commit comments