Skip to content

Instantly share code, notes, and snippets.

@dzerrenner
Created December 28, 2020 00:11
Show Gist options
  • Save dzerrenner/09c51de36f8d549eeba15d4bdb7232b9 to your computer and use it in GitHub Desktop.
Save dzerrenner/09c51de36f8d549eeba15d4bdb7232b9 to your computer and use it in GitHub Desktop.
Simple python aiohttp server to switch input channels on Denon-AVRs
import logging
import denonavr
from aiohttp import web
from rich.logging import RichHandler
DEBUG = False
IP_RECEIVER = '192.168.2.187'
async def channel(request):
logger = request.app.logger.getChild("denon")
chname = request.match_info['chname']
logger.debug(f"trying to switch input to: {chname}")
res = request.app['denon'].input_func = chname
return web.json_response({"status": res}, headers = {'Access-Control-Allow-Origin':'*'})
def app():
FORMAT = "%(name)s %(message)s"
level = logging.DEBUG if DEBUG else logging.INFO
logging.basicConfig(
level=level, format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
)
app = web.Application(logger=logging.getLogger(__name__), debug=DEBUG)
d = denonavr.DenonAVR(IP_RECEIVER, "Denon Receiver")
app['denon'] = d
app.logger.info(f"Started... Receiver-Info: {d.receiver_type}, S/N {d.serial_number}")
app.logger.debug(f"channels: {d.input_func_list}")
app.router.add_get("/denon/channel/{chname}", channel)
return app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment