diff --git a/vortex.py b/vortex.py index 849fc3c..1b351b4 100644 --- a/vortex.py +++ b/vortex.py @@ -44,7 +44,12 @@ class VortexConnection(object): data = True while data: - data = self.socket.recv(4096).decode('utf-8') + try: + data = self.socket.recv(512).decode() + except: + time.sleep(0.1) + self.logger.warning('Recv failed') + continue buf += data while buf.find('\r') != -1: diff --git a/vortexiot.py b/vortexiot.py index 14d4f70..f2c2d5e 100644 --- a/vortexiot.py +++ b/vortexiot.py @@ -22,7 +22,8 @@ class VortexSpejsIOTClient(mqtt.Client): def on_connect(self, client, userdata, flags, rc): self.subscribe(self.topic_prefix + '+/+/set') self.logger.info('Connected') - self.device_id = self.vortex.discover().keys()[0] + self.device_id = list(self.vortex.discover().keys())[0] + self.vortex[self.device_id].call_single('BLAUTO0') def run(self): self.loop_start() @@ -53,12 +54,15 @@ class VortexSpejsIOTClient(mqtt.Client): self.logger.info('mqtt -> %r %r', topic, msg.payload) node, attrib, _ = topic.split('/') + msg.payload = msg.payload.decode('utf-8') if node in config.INPUTS: if attrib == 'gain': self.multi_call('GAINI', config.INPUTS[node], msg.payload) elif attrib == 'mute': self.multi_call('MUTEI', config.INPUTS[node], '1' if msg.payload == 'true' else '0') + elif attrib == 'mode': + self.multi_call('MIC', config.INPUTS[node], '1' if msg.payload == 'mic' else '0') elif node in config.OUTPUTS: if attrib == 'gain': self.multi_call('GAINO', config.OUTPUTS[node], msg.payload)