Skip to content

Commit

Permalink
Update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Dec 7, 2020
1 parent 6c8a6de commit c6139ff
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/hassfest.yml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 24 additions & 25 deletions bin/update_requirements
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
4 changes: 1 addition & 3 deletions custom_components/jq300/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions custom_components/jq300/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
"documentation": "https://github.com/Limych/ha-jq300",
"domain": "jq300",
"name": "JQ-300/200/100 Indoor Air Quality Meter",
"requirements": []
}
"requirements": [
"paho-mqtt~=1.5"
]
}

0 comments on commit c6139ff

Please sign in to comment.