Commit 47e33be
committed
feat: type Controller's mqttc by what the SDK calls on an injected client
Closes #8.
mqttc was annotated with the concrete MqttClient, which nominally admits only
that class or a subclass. It works today only because ebus-mqtt-client ships no
py.typed, so downstream type checkers resolve the import to Any. When that marker
lands the annotation starts meaning what it says, and a consumer injecting its own
client needs a cast or a type-ignore to use a feature whose purpose is supplying
one.
Adds MqttTransport, a runtime_checkable Protocol of the three members the SDK
actually calls on an injected client — publish, subscribe, unsubscribe — and
widens the parameter to it. Signatures mirror MqttClient exactly, so MqttClient
satisfies it unchanged and every existing call site keeps type-checking.
Deliberately not the full client surface. An injected client is never started or
stopped: _connect_broker returns early when mqttc is already set, so the start()
beside from_config is unreachable, and stop() is behind if self._owns_client.
is_connected, is_running and publish_and_flush are Device/Property-path members
with no injection point. Typing the parameter with those would oblige consumers to
implement methods the SDK provably never calls on their object.
Two supporting edits, both behaviour-preserving: _connect_broker binds the
SDK-built client to a local of the concrete type so start() resolves, and
Controller keeps that client in _owned_client so stop() has a typed handle.
Assignment order in _connect_broker is unchanged, so a start() that raises leaves
self.mqttc exactly as it did before.1 parent 24e1a3c commit 47e33be
4 files changed
Lines changed: 141 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
81 | 84 | | |
82 | 85 | | |
83 | 86 | | |
| |||
130 | 133 | | |
131 | 134 | | |
132 | 135 | | |
| 136 | + | |
133 | 137 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
| |||
2176 | 2178 | | |
2177 | 2179 | | |
2178 | 2180 | | |
2179 | | - | |
| 2181 | + | |
2180 | 2182 | | |
2181 | 2183 | | |
2182 | 2184 | | |
| |||
2221 | 2223 | | |
2222 | 2224 | | |
2223 | 2225 | | |
2224 | | - | |
| 2226 | + | |
2225 | 2227 | | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
2226 | 2233 | | |
2227 | 2234 | | |
2228 | 2235 | | |
| |||
2257 | 2264 | | |
2258 | 2265 | | |
2259 | 2266 | | |
2260 | | - | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
2261 | 2272 | | |
2262 | 2273 | | |
2263 | 2274 | | |
2264 | 2275 | | |
2265 | | - | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
2266 | 2279 | | |
2267 | 2280 | | |
2268 | 2281 | | |
| |||
2854 | 2867 | | |
2855 | 2868 | | |
2856 | 2869 | | |
2857 | | - | |
2858 | | - | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
2859 | 2875 | | |
| 2876 | + | |
2860 | 2877 | | |
2861 | 2878 | | |
2862 | 2879 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1303 | 1303 | | |
1304 | 1304 | | |
1305 | 1305 | | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
0 commit comments