From 0bae2eed8a64edd97a5a3dbdecd1fbc6d7efc723 Mon Sep 17 00:00:00 2001 From: Alex Barcelo Date: Wed, 4 Apr 2018 09:12:12 +0200 Subject: [PATCH] Update async_ usage (for Home Assistant 0.66+) This should workd for Home Assistant 0.66+ onwards, but keeping backwards compatibility. Note that there is an extra workaround to avoid `async` completely, as it will give syntax error under Python 3.7. This should future-proof the import. --- zigate/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zigate/__init__.py b/zigate/__init__.py index 8b1922c..340d0ce 100644 --- a/zigate/__init__.py +++ b/zigate/__init__.py @@ -4,7 +4,14 @@ import asyncio import logging -from homeassistant.util import async as hasync +try: + # Valid since HomeAssistant 0.66+ + from homeassistant.util import async_ as hasync +except ImportError: + # backwards compatibility, with workaround to avoid reserved word "async" + # from homeassistant.util import async as hasync # <- invalid syntax in Python 3.7 + import importlib + hasync = importlib.import_module("homeassistant.util.async") import homeassistant.helpers.config_validation as cv from homeassistant.const import (CONF_NAME, CONF_HOST, CONF_PORT)