Home Information - Your home, your data, organized.
Python
Working on cleaning up integration factoring. WIP
Anthony Cassandra9ea90f23f79e
diff --git a/src/hi/apps/config/templates/config/panes/home.html b/src/hi/apps/config/templates/config/panes/home.htmlindex 84d6e5f6..54e3ae30 100644--- a/src/hi/apps/config/templates/config/panes/home.html+++ b/src/hi/apps/config/templates/config/panes/home.html@@ -24,7 +24,7 @@<div class="tab-pane fade" id="hi-integrations" role="tabpanel"aria-labelledby="hi-integrations-tab"><div id="{{ DIVID.INTEGRATION_TAB }}">- {% include "core/panes/config_tab.html" with integration_list=integration_list %}+ {% include "core/panes/integration_config_tab.html" with integration_list=integration_list %}</div></div>diff --git a/src/hi/integrations/core/integration_gateway.py b/src/hi/integrations/core/integration_gateway.pyindex 0a382be4..0a49fe7d 100644--- a/src/hi/integrations/core/integration_gateway.py+++ b/src/hi/integrations/core/integration_gateway.py@@ -9,15 +9,15 @@ class IntegrationGateway:Each integration needs to provide an Integration Manager that implements these methods."""- def enable( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:+ def enable_modal_view( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:# Should return a modal via antinode.modal_from_template() (called async)raise NotImplementedError('Subclasses must override this method')- def disable( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:+ def disable_modal_view( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:# Should return a modal via antinode.modal_from_template() (called async)raise NotImplementedError('Subclasses must override this method')- def manage( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:+ def manage_pane_view( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:# Should return HTML fragment for the management pane of the integration.raise NotImplementedError('Subclasses must override this method')diff --git a/src/hi/integrations/core/models.py b/src/hi/integrations/core/models.pyindex cbd11a34..fcd393a0 100644--- a/src/hi/integrations/core/models.py+++ b/src/hi/integrations/core/models.py@@ -3,7 +3,6 @@ from typing import Dictfrom django.db import models-from hi.apps.attribute.enums import AttributeValueTypefrom hi.apps.attribute.models import AttributeModelfrom .enums import IntegrationType@@ -49,19 +48,19 @@ class Integration( models.Model ):return@property- def property_dict(self) -> Dict[ str, 'IntegrationAttribute' ] :- property_dict = dict()- for prop in self.properties.all():- property_dict[prop.name] = prop+ def attribute_dict(self) -> Dict[ str, 'IntegrationAttribute' ] :+ attribute_dict = dict()+ for prop in self.attributes.all():+ attribute_dict[prop.name] = propcontinue- return property_dict+ return attribute_dictclass IntegrationAttribute( AttributeModel ):integration = models.ForeignKey(Integration,- related_name = 'properties',+ related_name = 'attributes',verbose_name = 'Integration',on_delete=models.CASCADE,)diff --git a/src/hi/integrations/core/templates/core/panes/config_tab.html b/src/hi/integrations/core/templates/core/panes/integration_config_tab.htmlsimilarity index 92%rename from src/hi/integrations/core/templates/core/panes/config_tab.htmlrename to src/hi/integrations/core/templates/core/panes/integration_config_tab.htmlindex 72cf2add..d252e7d7 100644--- a/src/hi/integrations/core/templates/core/panes/config_tab.html+++ b/src/hi/integrations/core/templates/core/panes/integration_config_tab.html@@ -36,7 +36,7 @@<div class="col-2">{% if integration.is_enabled %}<a href="{% url 'integration_action' name=integration.integration_type.name action='manage' %}"- class="btn btn-info btn-control" role="button" data-async="modal">MANAGE</a>+ class="btn btn-info btn-control" role="button" data-async="#{{ DIVID.INTEGRATION_TAB }}">MANAGE</a>{% else %} {% endif %}diff --git a/src/hi/integrations/core/views.py b/src/hi/integrations/core/views.pyindex 9a96b8f1..1261782b 100644--- a/src/hi/integrations/core/views.py+++ b/src/hi/integrations/core/views.py@@ -1,6 +1,5 @@import logging-from django.shortcuts import renderfrom django.views.generic import Viewfrom hi.views import bad_request_response@@ -19,7 +18,7 @@ class IntegrationViewMixin:}-class IntegrationActionView( View, IntegrationViewMixin ):+class IntegrationActionView( View ):def get(self, request, *args, **kwargs):@@ -33,11 +32,11 @@ class IntegrationActionView( View, IntegrationViewMixin ):)if action == 'enable':- return integration_gateway.enable( request = request, *args, **kwargs )+ return integration_gateway.enable_modal_view( request = request, *args, **kwargs )elif action == 'disable':- return integration_gateway.disable( request = request, *args, **kwargs )+ return integration_gateway.disable_modal_view( request = request, *args, **kwargs )elif action == 'manage':- return integration_gateway.manage( request = request, *args, **kwargs )+ return integration_gateway.manage_pane_view( request = request, *args, **kwargs )error_message = f'Unknown integration action "{action}".'except Exception as e:diff --git a/src/hi/integrations/hass/hass_gateway.py b/src/hi/integrations/hass/hass_gateway.pyindex aa66c85d..db7df828 100644--- a/src/hi/integrations/hass/hass_gateway.py+++ b/src/hi/integrations/hass/hass_gateway.py@@ -11,13 +11,13 @@ logger = logging.getLogger(__name__)class HassGateway( IntegrationGateway ):- def enable( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:+ def enable_modal_view( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:return views.HassEnableView().post( request )- def disable( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:+ def disable_modal_view( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:return views.HassDisableView().post( request )- def manage( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:+ def manage_pane_view( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:post_action = request.POST.get('action')if post_action == 'sync':diff --git a/src/hi/integrations/hass/templates/hass/panes/manage.html b/src/hi/integrations/hass/templates/hass/panes/manage.htmlindex 3cf8b7b6..7a8b4943 100644--- a/src/hi/integrations/hass/templates/hass/panes/manage.html+++ b/src/hi/integrations/hass/templates/hass/panes/manage.html@@ -5,7 +5,7 @@{% endif %}<div class="col-2">- <form action="{% url 'integration_manage' name=integration_type.name %}"+ <form action="{% url 'hass_sync' %}"method="POST" role="form" data-async="#hi-config-integration-tab">{% csrf_token %}<button type="submit" class="btn btn-primary btn-control" role="button"diff --git a/src/hi/integrations/zoneminder/templates/zoneminder/panes/manage.html b/src/hi/integrations/zoneminder/templates/zoneminder/panes/manage.htmlindex 7e73598d..aa3ef633 100644--- a/src/hi/integrations/zoneminder/templates/zoneminder/panes/manage.html+++ b/src/hi/integrations/zoneminder/templates/zoneminder/panes/manage.html@@ -5,7 +5,7 @@{% endif %}<div class="col-2">- <form action="{% url 'integration_manage' name=integration_type.name %}"+ <form action="{% url 'zm_sync' %}"method="POST" role="form" data-async="#hi-config-integration-tab">{% csrf_token %}<button type="submit" class="btn btn-primary btn-control" role="button"diff --git a/src/hi/integrations/zoneminder/zm_gateway.py b/src/hi/integrations/zoneminder/zm_gateway.pyindex ff15457e..384fea80 100644--- a/src/hi/integrations/zoneminder/zm_gateway.py+++ b/src/hi/integrations/zoneminder/zm_gateway.py@@ -11,18 +11,13 @@ logger = logging.getLogger(__name__)class ZoneMinderGateway( IntegrationGateway ):- def enable( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:+ def enable_modal_view( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:return views.ZmEnableView().get( request )- def disable( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:+ def disable_modal_view( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:return views.ZmDisableView().get( request )- def manage( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:-- post_action = request.POST.get('action')- if post_action == 'sync':- return views.ZmSyncView().post( request, *args, **kwargs )-+ def manage_pane_view( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:return views.ZmManageView().get( request, *args, **kwargs )diff --git a/src/hi/integrations/zoneminder/zm_manager.py b/src/hi/integrations/zoneminder/zm_manager.pyindex d74fb38a..eb94e709 100644--- a/src/hi/integrations/zoneminder/zm_manager.py+++ b/src/hi/integrations/zoneminder/zm_manager.py@@ -66,6 +66,7 @@ class ZoneMinderManager( Singleton ):# Verify integrationattribute_dict = zm_integration.attribute_dictfor zm_attr_name in ZmAttributeName:+ print( f'\nATTR NAME = {zm_attr_name} DICT {attribute_dict}' )zm_prop = attribute_dict.get( zm_attr_name.name )if not zm_prop:raise IntegrationAttributeError( f'Missing ZM attribute {zm_attr_name.name}' )