Update COMMUNITY_INTEGRATIONS.md _update_settings examples

Simplify the reconnect example to show a common pattern (reconnect on any change) and improve the _warn_unhandled_updated_settings example to show selective handling of specific fields.
This commit is contained in:
Paul Kompfner
2026-02-23 15:45:00 -05:00
parent 30db5fea7c
commit e804060e17

View File

@@ -266,17 +266,18 @@ class MySTTService(STTService):
self._sync_model_name_to_metrics()
```
To react to runtime setting changes, override `_update_settings`. The base implementation applies the delta to `self._settings` and returns a `dict` mapping each changed field name to its **pre-update** value. Your override should call `super()` first, then act on the changed fields:
To react to runtime setting changes, override `_update_settings`. The base implementation applies the delta to `self._settings` and returns a `dict` mapping each changed field name to its **pre-update** value. Your override should call `super()` first, then act on the changed fields. A common implementation might look like:
```python
async def _update_settings(self, update: STTSettings) -> dict[str, Any]:
"""Apply a settings update, reconfiguring the recognizer if needed."""
changed = await super()._update_settings(update)
if "language" in changed:
# Restart the recognizer with the new language.
await self._disconnect()
await self._connect()
if not changed:
return changed
await self._disconnect()
await self._connect()
return changed
```
@@ -285,7 +286,7 @@ The dict keys work like a set for membership tests (`"language" in changed`) and
Note that, in this example, the service requires a reconnect to apply the new language. Consider, for each setting, whether your service requires reconnection or can apply changes in-place.
If your service can't yet apply certain settings at runtime, call `self._warn_unhandled_updated_settings(changed)` with the unhandled field names so users get a clear log message:
If your service can't yet apply certain settings at runtime, call `self._warn_unhandled_updated_settings(changed)` with any unhandled field names so users get a clear log message:
```python
async def _update_settings(self, update: STTSettings) -> dict[str, Any]:
@@ -294,8 +295,11 @@ async def _update_settings(self, update: STTSettings) -> dict[str, Any]:
if not changed:
return changed
# TODO: someday we could reconnect here to apply updated settings.
self._warn_unhandled_updated_settings(changed)
if "language" in changed:
await self._update_language()
else:
# TODO: handle changes to other settings soon!
self._warn_unhandled_updated_settings(changed.keys() - {"language"})
return changed
```