diff --git a/homeassistant/components/pulseaudio_loopback/switch.py b/homeassistant/components/pulseaudio_loopback/switch.py index ec1adc7641bb2..38b90c2d348a0 100644 --- a/homeassistant/components/pulseaudio_loopback/switch.py +++ b/homeassistant/components/pulseaudio_loopback/switch.py @@ -84,6 +84,11 @@ def __init__(self, host, port, buff_sz, tcp_timeout): self._buffer_size = int(buff_sz) self._tcp_timeout = int(tcp_timeout) + @property + def available(self): + """Return true if module state was updated.""" + return len(self._current_module_state) + def _send_command(self, cmd, response_expected): """Send a command to the pa server using a socket.""" sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -147,6 +152,7 @@ def __init__(self, hass, name, pa_server, sink_name, source_name): self._name = name self._sink_name = sink_name self._source_name = source_name + self._available = False self._pa_svr = pa_server @property @@ -154,6 +160,11 @@ def name(self): """Return the name of the switch.""" return self._name + @property + def available(self): + """Return true if Pulse is available and connected.""" + return self._available + @property def is_on(self): """Return true if device is on.""" @@ -186,6 +197,11 @@ def turn_off(self, **kwargs): def update(self): """Refresh state in case an alternate process modified this data.""" self._pa_svr.update_module_state() + + if not self._pa_svr.available: + return + self._module_idx = self._pa_svr.get_module_idx( self._sink_name, self._source_name ) + self._available = True