async_upnp_client library

Steven December 27, 2018 13:06

This year I started working on a Python library called async_upnp_client. The source for this library are found on Github. This library provides a means to interface with UPnP enabled devices, such as Smart TVs, your home router, and maybe even your printer.

The library was mostly created as a base for the Home Assistant DLNA DMR platform. When I started experimenting with Home Assistant I wanted to control my TV and get playing/paused/… events from it to, for example, turn off/on the lights automatically. In the end UPnP/DLNA was not the best route, as my TV only provides these events when playing from a DLNA DMS source. However, others were able to use this in their set-ups, as they reported this when I released this as a custom component. This caused me to try to get this into Home Assistant itself, as a platform, which happened eventually. In the end, async_upnp_client is also used by the UPnP component, which allows you to monitor your router from within Home Assistant.

It turns out there was no Python asyncio UPnP client, so I wrote my own. The asyncio part is important, as Home Assistant works better when its components/platforms are using asyncio. There is at least on other asyncio UPnP client called SoCo, but it is specific to Sonos players.

So why would you write your own library? There are multiple reasons for this, such as:

  • You learn a lot about the standard;
  • You keep up with a programming language/part of programming language;
  • Perhaps most importantly, you help others by saving them the work of writing their own implementation and understanding the specifics of the standard.

These were the reasons for me to start working on this library. Python is not the programming language I use professionally any more, but still want to keep up with. And not just the language itself, but also the ecosystem around it with all of its tools such as PyTest and MyPy.

Comments are closed.