def _on_client_connect(self, data): """Handle client connect.""" client = None if data.get('id') in self._clients: client = self._clients[data.get('id')] client.update_connected(True) else: client = Snapclient(self, data.get('client')) self._clients[data.get('id')] = client if self._new_client_callback_func and callable(self._new_client_callback_func): self._new_client_callback_func(client) _LOGGER.info('client %s connected', client.friendly_name)
def synchronize(self, status): """Synchronize snapserver.""" self._version = status.get('server').get('version') self._groups = {} self._clients = {} self._streams = {} for stream in status.get('server').get('streams'): self._streams[stream.get('id')] = Snapstream(stream) _LOGGER.debug('stream found: %s', self._streams[stream.get('id')]) for group in status.get('server').get('groups'): self._groups[group.get('id')] = Snapgroup(self, group) _LOGGER.debug('group found: %s', self._groups[group.get('id')]) for client in group.get('clients'): self._clients[client.get('id')] = Snapclient(self, client) _LOGGER.debug('client found: %s', self._clients[client.get('id')])
def setUp(self): data = { 'id': 'test', 'host': { 'ip': '0.0.0.0', 'name': 'localhost' }, 'config': { 'name': '', 'latency': 0, 'volume': { 'muted': False, 'percent': 90 } }, 'snapclient': { 'version': '0.0' }, 'connected': True } server = MagicMock() self.client = Snapclient(server, data)