Handle receiving a message by checking whether it is in response
        to a command or unsolicited, and dispatching it to the appropriate
        object method.

def received_message(self, msg):
        """
        Handle receiving a message by checking whether it is in response
        to a command or unsolicited, and dispatching it to the appropriate
        object method.
        """
        logger.debug("Received message: %s", msg)
        if msg.is_binary:
            raise ValueError("Binary messages not supported")
        resps = json.loads(msg.data)

        cmd_group = _get_cmds_id(*resps)
        if cmd_group:
            (cmds, promise) = self._cmd_groups[cmd_group]
            promise.fulfill((cmds, resps))
        else:
            try:
                self.received_unsolicited(resps)
            except:
                logger.exception("Error in unsolicited msg handler")
                raise