text: # #
  # # Bridge between the Onkyo AVR EISCP remote control protocol and MQTT.
  # # Allows to remotely control networked Onkyo AVRs and get status
  # # information.
  # #
  # # Written and (C) 2015-16 by Oliver Wagner <owagner@tellerulam.com>
  # # Provided under the terms of the MIT license
  # #
  # # Requires:
  # # - onkyo-eiscp - https://github.com/miracle2k/onkyo-eiscp
  # # - Eclipse Paho for Python - http://www.eclipse.org/paho/clients/python/
  # #
  
  # import argparse
  # import logging
  # import logging.handlers
  # import time
  # import json
  # import paho.mqtt.client as mqtt
  # import eiscp
  
  # version = "0.7"
  
  # lastSend = 0
  
  # logging.info('Starting onkyo2mqtt V%s with topic prefix "%s"' % (version, topic))
  
  
  # def sendavr(cmd):
  #     logging.getLogger("sendavr").info(cmd)
  #     global lastSend
  #     now = time.time()
  #     if now - lastSend < 0.05:
  #         time.sleep(0.05 - (now - lastSend))
  #     receiver.send(cmd)
  #     lastSend = time.time()
  #     logging.info("Sent command %s" % (cmd))
  
  # # Query some initial values
  # for icmd in ("PWR", "MVL", "SLI", "SLA", "LMD"):
  #     sendavr(icmd + "QSTN")
  
  # mqc.loop_start()
  
  
  # # def publish(suffix, val, raw):
  # #     global topic, mqc
  # #     logger = logging.getLogger("publish")
  # #     robj = {}
  # #     robj["val"] = val
  # #     logger.info(f"val: {val}")
  # #     if raw is not None:
  # #         logger.info(f"raw: {raw}")
  # #         robj["onkyo_raw"] = raw
  # #     mqc.publish(topic + "status/" + suffix, json.dumps(robj), qos=0, retain=True)
  
  
  # logger = logging.getLogger("main_looper")
  
  # while True:
  #     try:
  #         msg = receiver.get(3600)
  #     except Exception as e:
  #         logger.warning(f"got exception while get: {e}")
  #     else:
  #         logger.info(f"got msg: {msg}")
  #         if msg.startswith("MVL"):
  #             logger.info(f"Set Main Volume to {int(msg[-2:], 16)}")
  #         if msg is not None:
  #             try:
  #                 parsed = eiscp.core.iscp_to_command(msg)
  #                 # Either part of the parsed command can be a list
  #                 if isinstance(parsed[1], str) or isinstance(parsed[1], int):
  #                     val = parsed[1]
  #                 else:
  #                     val = parsed[1][0]
  #                 if isinstance(parsed[0], str):
  #                     publish(parsed[0], val, msg)
  #                 else:
  #                     for pp in parsed[0]:
  #                         publish(pp, val, msg)
  #             except:
  #                 publish(msg[:3], msg[3:], msg)
  