1 """Base class for Wyoming providers."""
3 from __future__
import annotations
7 from wyoming.client
import AsyncTcpClient
8 from wyoming.info
import Describe, Info
12 from .error
import WyomingError
20 """Hold info for Wyoming service."""
22 def __init__(self, host: str, port: int, info: Info) ->
None:
23 """Initialize Wyoming service."""
29 if (self.
infoinfo.satellite
is not None)
and self.
infoinfo.satellite.installed:
34 if any(asr.installed
for asr
in info.asr):
35 self.
platformsplatforms.append(Platform.STT)
36 if any(tts.installed
for tts
in info.tts):
37 self.
platformsplatforms.append(Platform.TTS)
38 if any(wake.installed
for wake
in info.wake):
39 self.
platformsplatforms.append(Platform.WAKE_WORD)
40 if any(intent.installed
for intent
in info.intent)
or any(
41 handle.installed
for handle
in info.handle
43 self.
platformsplatforms.append(Platform.CONVERSATION)
46 """Return True if services are installed that Home Assistant can use."""
48 any(asr
for asr
in self.
infoinfo.asr
if asr.installed)
49 or any(tts
for tts
in self.
infoinfo.tts
if tts.installed)
50 or any(wake
for wake
in self.
infoinfo.wake
if wake.installed)
51 or any(intent
for intent
in self.
infoinfo.intent
if intent.installed)
52 or any(handle
for handle
in self.
infoinfo.handle
if handle.installed)
53 or ((self.
infoinfo.satellite
is not None)
and self.
infoinfo.satellite.installed)
57 """Return name of first installed usable service."""
61 if (self.
infoinfo.satellite
is not None)
and self.
infoinfo.satellite.installed:
62 return self.
infoinfo.satellite.name
65 asr_installed = [asr
for asr
in self.
infoinfo.asr
if asr.installed]
67 return asr_installed[0].name
70 tts_installed = [tts
for tts
in self.
infoinfo.tts
if tts.installed]
72 return tts_installed[0].name
75 wake_installed = [wake
for wake
in self.
infoinfo.wake
if wake.installed]
77 return wake_installed[0].name
80 intent_installed = [intent
for intent
in self.
infoinfo.intent
if intent.installed]
82 return intent_installed[0].name
85 handle_installed = [handle
for handle
in self.
infoinfo.handle
if handle.installed]
87 return handle_installed[0].name
92 async
def create(cls, host: str, port: int) -> WyomingService |
None:
93 """Create a Wyoming service."""
98 return cls(host, port, info)
104 retries: int = _INFO_RETRIES,
105 retry_wait: float = _INFO_RETRY_WAIT,
106 timeout: float = _INFO_TIMEOUT,
108 """Load info from Wyoming server."""
109 wyoming_info: Info |
None =
None
111 for _
in range(retries + 1):
113 async
with AsyncTcpClient(host, port)
as client, asyncio.timeout(timeout):
115 await client.write_event(Describe().event())
117 event = await client.read_event()
120 "Connection closed unexpectedly",
123 if Info.is_type(event.type):
124 wyoming_info = Info.from_event(event)
127 if wyoming_info
is not None:
129 except (TimeoutError, OSError, WyomingError):
131 await asyncio.sleep(retry_wait)
WyomingService|None create(cls, str host, int port)
None __init__(self, str host, int port, Info info)
Info|None load_wyoming_info(str host, int port, int retries=_INFO_RETRIES, float retry_wait=_INFO_RETRY_WAIT, float timeout=_INFO_TIMEOUT)