Skip to content

Commit

Permalink
Add ZGP basis to quirk gen
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJulianJES committed Jun 26, 2023
1 parent d9bedd1 commit 97f64f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions quirk_generator/generate_quirk.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections import defaultdict

from jinja2 import Environment, PackageLoader
from zigpy.profiles import zha, zll
from zigpy.profiles import zgp, zha, zll
from zigpy.zcl import clusters

_LOGGER = logging.getLogger(__name__)
Expand All @@ -17,10 +17,11 @@ def process_profiles(data: dict) -> dict:
"""Process the profiles in the device signature."""
profiles = set()
for endpoint in data["signature"]["endpoints"].values():
profiles.add(endpoint["profile_id"])
profiles.add(int(endpoint["profile_id"], 16))
data["present_profiles"] = profiles
data["zha_profile"] = zha.PROFILE_ID
data["zll_profile"] = zll.PROFILE_ID
data["zgp_profile"] = zgp.PROFILE_ID
return data


Expand All @@ -43,6 +44,8 @@ def process_profile_id(profile_id: str) -> str | int:
return "zha.PROFILE_ID"
elif profile_id == zll.PROFILE_ID:
return "zll.PROFILE_ID"
elif profile_id == zgp.PROFILE_ID:
return "zgp.PROFILE_ID"
else:
return profile_id

Expand All @@ -62,6 +65,11 @@ def process_device_type(profile_id: str, device_type: str) -> str | int:
return f"zll.DeviceType.{zll.DeviceType(device_type).name}"
except ValueError:
return device_type
elif profile_id == zgp.PROFILE_ID:
try:
return f"zgp.DeviceType.{zgp.DeviceType(device_type).name}"
except ValueError:
return device_type
else:
return device_type

Expand Down
2 changes: 1 addition & 1 deletion quirk_generator/templates/imports_template.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from zigpy.profiles import {% if zha_profile in present_profiles -%}zha{% if present_profiles |length > 1 -%},{% endif %} {% endif %}{% if zll_profile in present_profiles -%}zll{% endif %}
from zigpy.profiles import {% if zha_profile in present_profiles -%}zha{% if present_profiles |length > 1 -%},{% endif %} {% endif %}{% if zll_profile in present_profiles -%}zll{% if present_profiles |length > 2 -%},{% endif %}{% endif %}{% if zgp_profile in present_profiles -%}zgp{% endif %}
from zigpy.quirks import CustomDevice
{% for module, classes in grouped_clusters.items() %}from {{module}} import (
{% for class in classes %} {{class}},{% if not loop.last %}
Expand Down

0 comments on commit 97f64f4

Please sign in to comment.