Add preference for /sonos endpoint

This commit is contained in:
2020-05-14 21:26:08 +02:00
parent 2bfcf1763a
commit 1130432288
4 changed files with 18 additions and 0 deletions

View File

@@ -5,5 +5,6 @@ object PreferenceKey {
const val PORT = "preference_port"
const val ENABLE_SAY_ENDPOINT = "preference_enable_say_endpoint"
const val ENABLE_WAVE_ENDPOINT = "preference_enable_wave_endpoint"
const val ENABLE_SONOS_ENDPOINT = "preference_enable_sonos_endpoint"
const val TTS = "preference_tts"
}

View File

@@ -92,6 +92,10 @@ class WebServer(port: Int, private val context: Context) : NanoHTTPD(port),
}
private fun sonos(session: IHTTPSession): Response {
if (!preferences.getBoolean(PreferenceKey.ENABLE_SONOS_ENDPOINT, true)) {
throw ResponseException(NOT_FOUND, "")
}
if (session.method != Method.POST) {
throw ResponseException(METHOD_NOT_ALLOWED, "")
}
@@ -108,6 +112,10 @@ class WebServer(port: Int, private val context: Context) : NanoHTTPD(port),
}
private fun sonosCache(session: IHTTPSession): Response {
if (!preferences.getBoolean(PreferenceKey.ENABLE_SONOS_ENDPOINT, true)) {
throw ResponseException(NOT_FOUND, "")
}
if (session.method != Method.GET) {
throw ResponseException(METHOD_NOT_ALLOWED, "")
}

View File

@@ -21,6 +21,8 @@
<string name="preference_enable_say_endpoint_title">Enable /say endpoint</string>
<string name="preference_enable_wave_endpoint_summary">Allow HTTP clients to use /wave endpoint which enables them to retrieve TTS message as wave file</string>
<string name="preference_enable_wave_endpoint_title">Enable /wave endpoint</string>
<string name="preference_enable_sonos_endpoint_summary">Allow HTTP clients to use /sonos endpoint which enables them to send TTS messages directly to Sonos devices</string>
<string name="preference_enable_sonos_endpoint_title">Enable /sonos endpoint</string>
<string name="preference_tts_summary">Go to platform\'s TTS engine settings and adjust its parameters</string>
<string name="preference_tts_title">TTS engine settings</string>
<string name="preference_category_tts">TTS engine</string>

View File

@@ -24,6 +24,13 @@
android:title="@string/preference_enable_wave_endpoint_title"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:key="preference_enable_sonos_endpoint"
android:summary="@string/preference_enable_sonos_endpoint_summary"
android:title="@string/preference_enable_sonos_endpoint_title"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/preference_category_tts" app:iconSpaceReserved="false">