Replies: 5 comments 15 replies
-
Hello, from NEMO.interlocks import interlocks, Interlock
from NEMO.exceptions import InterlockError
from NEMO.models import Interlock as Interlock_model
class MyInterlockImplementation(Interlock):
def _send_command(self, interlock: Interlock_model, command_type: Interlock_model.State) -> Interlock_model.State:
# add your implementation
pass
interlocks["my_implementation"] = MyInterlockImplementation() you can also implement the You'll also need to create the from django.apps import AppConfig
class MyPluginConfig(AppConfig):
name = "NEMO_my_plugin"
default_auto_field = "django.db.models.AutoField"
def ready(self):
from NEMO_my_plugin import interlocks # unused but required import Now, to use your app, you'll need to add it in INSTALLED_APPS (before NEMO) and go into detailed administration and add a new interlock card type with the matching key That should be all. |
Beta Was this translation helpful? Give feedback.
-
I believe you should be able to extend the Interlock model, and have your admin view include all the fields. It will automatically add it to the regular Interlock model. You can then leave them there, or override the regular interlock admin and filter to only who the regular ones and not your new model. with regards to showing related attribute, you have to use the following in admin.py (assuming your OneToOne is name "interlock"): list_display = ["get_interlock_card"]
@display(boolean=True, ordering="interlock__interlock_card__name", description="Interlock Card")
def get_interlock_card(self, obj):
return obj.interlock.interlock_card.name |
Beta Was this translation helpful? Give feedback.
-
For packaging, you'll have to extract it, fix the imports, create your setup.py, and push to pypi. Let me know if you have any other questions. |
Beta Was this translation helpful? Give feedback.
-
Congratulations on your first plugin! that was fast! |
Beta Was this translation helpful? Give feedback.
-
One more suggestion, you could consider adding a migration that creates the interlock card category automatically. def set_mqtt_interlock_category_forward(apps, schema_editor):
InterlockCardCategory = apps.get_model("NEMO", "InterlockCardCategory")
InterlockCardCategory.objects.get_or_create(name="MQTT", key="mqtt_interlock")
def set_mqtt_interlock_category_reverse(apps, schema_editor):
pass
migrations = [
migrations.RunPython(set_mqtt_interlock_category_forward, set_mqtt_interlock_category_reverse),
] |
Beta Was this translation helpful? Give feedback.
-
Hello,
I have a couple of PR I wanted to work on since long time ago, and I might finally have time to dedicate.
One question before I get started. The main one would be adding support for a different class of interlocks (and maybe sensor), which would require additional python libraries.
What would be the best approach for it?
install.py
?interlocks.py
, leaving base classes available?Thanks a lot in advance.
Beta Was this translation helpful? Give feedback.
All reactions