From c6139ff7fba656dcb222662b731bfff989caf0c2 Mon Sep 17 00:00:00 2001 From: Andrey Khrolenok Date: Mon, 7 Dec 2020 05:33:02 +0300 Subject: [PATCH] Update workflow --- .github/workflows/hassfest.yml | 14 ++++++++ bin/update_requirements | 49 +++++++++++++-------------- custom_components/jq300/__init__.py | 4 +-- custom_components/jq300/manifest.json | 6 ++-- 4 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/hassfest.yml diff --git a/.github/workflows/hassfest.yml b/.github/workflows/hassfest.yml new file mode 100644 index 0000000..18c7d19 --- /dev/null +++ b/.github/workflows/hassfest.yml @@ -0,0 +1,14 @@ +name: Validate with hassfest + +on: + push: + pull_request: + schedule: + - cron: "0 0 * * *" + +jobs: + validate: + runs-on: "ubuntu-latest" + steps: + - uses: "actions/checkout@v2" + - uses: home-assistant/actions/hassfest@master diff --git a/bin/update_requirements b/bin/update_requirements index 67f3b81..2a25433 100755 --- a/bin/update_requirements +++ b/bin/update_requirements @@ -8,13 +8,15 @@ import requests ROOT = os.path.dirname(os.path.abspath(f"{__file__}/..")) PKG_PATH = PACKAGE = None -for current_path, dirs, _ in os.walk(f"{ROOT}/custom_components"): - if current_path.find("__pycache__") != -1: - continue - for dname in dirs: - if dname != "__pycache__": - PACKAGE = dname -PKG_PATH = f"{ROOT}/custom_components/{PACKAGE}" +for dname in [ + d + for d in os.listdir(f"{ROOT}/custom_components") + if os.path.isdir(f"{ROOT}/custom_components/{d}") +]: + if dname != "__pycache__": + PACKAGE = dname + PKG_PATH = f"{ROOT}/custom_components/{PACKAGE}" + break def get_package(requre: str) -> str: @@ -35,25 +37,22 @@ print(harequire) with open(f"{PKG_PATH}/manifest.json") as manifest: manifest = json.load(manifest) - requirements = [] + requirements = {} for req in manifest["requirements"]: - requirements.append(get_package(req)) - manifest["requirements"] = requirements -with open(f"{ROOT}/requirements.txt") as requirements: - tmp = requirements.readlines() - requirements = [] - for req in tmp: - requirements.append(req.replace("\n", "")) -for req in requirements: - pkg = get_package(req) - if pkg in manifest["requirements"]: - manifest["requirements"].remove(pkg) - manifest["requirements"].append(req) - -for req in manifest["requirements"]: - pkg = get_package(req) - if pkg in harequire: - print(f"{pkg} in HA requirements, no need here.") + requirements[get_package(req)] = req +with open(f"{ROOT}/requirements.txt") as reqs: + for req in reqs.readlines(): + req = req.replace("\n", "") + pkg = get_package(req) + if pkg in requirements: + if pkg in harequire or pkg == "homeassistant": + print(f"{pkg} in HA requirements, no need in manifest.") + requirements.pop(pkg, None) + else: + requirements[pkg] = req +manifest["requirements"] = list(requirements.values()) + print(json.dumps(manifest["requirements"], indent=4, sort_keys=True)) + with open(f"{PKG_PATH}/manifest.json", "w") as manifestfile: manifestfile.write(json.dumps(manifest, indent=4, sort_keys=True)) diff --git a/custom_components/jq300/__init__.py b/custom_components/jq300/__init__.py index a3ca120..bb0f9ca 100644 --- a/custom_components/jq300/__init__.py +++ b/custom_components/jq300/__init__.py @@ -354,9 +354,7 @@ def _mqtt_connect(self): def on_connect_callback(client, userdata, flags, res): _LOGGER.debug("Connected to MQTT") try: - sub = self._get_devices_mqtt_topics(self.active_devices) - if sub: - self._mqtt_subscribe(sub) + self._mqtt_subscribe(self._get_devices_mqtt_topics(self.active_devices)) except Exception as exc: # pylint: disable=broad-except logging.exception(exc) diff --git a/custom_components/jq300/manifest.json b/custom_components/jq300/manifest.json index 577b505..5d5c75d 100644 --- a/custom_components/jq300/manifest.json +++ b/custom_components/jq300/manifest.json @@ -7,5 +7,7 @@ "documentation": "https://github.com/Limych/ha-jq300", "domain": "jq300", "name": "JQ-300/200/100 Indoor Air Quality Meter", - "requirements": [] -} \ No newline at end of file + "requirements": [ + "paho-mqtt~=1.5" + ] +}