Skip to content

Home Information - Your home, your data, organized.

Python

Improved the integration interfaces and flows. WIP.

Anthony Cassandrab6db83c894b1
diff --git a/src/hi/apps/common/processing_result.py b/src/hi/apps/common/processing_result.py
new file mode 100644
index 00000000..6cf4931f
--- /dev/null
+++ b/src/hi/apps/common/processing_result.py
@@ -0,0 +1,10 @@
+from dataclasses import dataclass, field
+from typing import List
+
+
+@dataclass
+class ProcessingResult:
+ """ Generic class for use in reporting the outcome of processing. """
+ title : str
+ message_list : List[ str ] = field( default_factory = list )
+ error_list : List[ str ] = field( default_factory = list )
diff --git a/src/hi/apps/common/templates/common/processing_result.html b/src/hi/apps/common/templates/common/processing_result.html
new file mode 100644
index 00000000..2e6c829c
--- /dev/null
+++ b/src/hi/apps/common/templates/common/processing_result.html
@@ -0,0 +1,26 @@
+<h5>{{ processing_result.title }}</h5>
+
+{% if processing_result.error_list %}
+<div class="alert alert-danger">
+ <h5>Errors</h5>:
+ <ul>
+ {% for error_message in processing_result.error_list %}
+ <li>{{ error_message }}</li>
+ {% endfor %}
+ </ul>
+</div>
+{% endif %}
+
+{% if processing_result.message_list %}
+<div class="alert alert-info">
+ <ul>
+ {% for message in processing_result.message_list %}
+ <li>{{ message }}</li>
+ {% endfor %}
+ </ul>
+</div>
+{% endif %}
+
+{% if not processing_result.error_list %}
+<div><em>No errors.</em></div>
+{% endif %}
diff --git a/src/hi/apps/config/templates/config/panes/home.html b/src/hi/apps/config/templates/config/panes/home.html
index f2a68e69..f62d1f9f 100644
--- a/src/hi/apps/config/templates/config/panes/home.html
+++ b/src/hi/apps/config/templates/config/panes/home.html
@@ -1,49 +1,31 @@
<div class="">
- <h1>Settings</h1>
+ <h1>Administration</h1>
- <div><em>TBD </em></div>
+ <ul class="nav nav-tabs" id="hi-config-tab" role="tablist">
+ <li class="nav-item">
+ <a class="nav-link active" id="hi-settings-tab" data-toggle="tab" href="#hi-settings" role="tab" aria-controls="hi-settings" aria-selected="true">Settings</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" id="hi-integrations-tab" data-toggle="tab" href="#hi-integrations" role="tab" aria-controls="hi-integrations" aria-selected="false">Integrations</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" id="hi-other-tab" data-toggle="tab" href="#hi-other" role="tab" aria-controls="hi-other" aria-selected="false">Other</a>
+ </li>
+ </ul>
- <h2>Integrations</h2>
- {% for integration in integration_list %}
- <div class="row hi-config-integration">
- <div class="col-2">
- {{ integration.integration_type.label }}
+ <div class="tab-content" id="hi-config-tab-content">
+ <div class="tab-pane fade show active" id="hi-settings" role="tabpanel" aria-labelledby="hi-settings-tab">
+ TBD for Settings
</div>
- <div class="col-2">
- {% if integration.is_enabled %}
- <span class="text-success">ENABLED</span>
- {% else %}
- <span class="text-danger">DISABLED</span>
- {% endif %}
+ <div class="tab-pane fade" id="hi-integrations" role="tabpanel" aria-labelledby="hi-integrations-tab">
+ <div id="hi-config-integration-tab">
+ {% include "core/panes/config_tab.html" with integration_list=integration_list %}
+ </div>
</div>
- <div class="col-2">
- {% if integration.is_enabled %}
- <form action="{% url 'config_integration' action='disable' name=integration.integration_type.name %}"
- method="POST" role="form" data-async="#hi-main-content">
- {% csrf_token %}
- <button type="submit" class="btn btn-danger btn-control" role="button"">DISABLE</button>
- </form>
-
- {% else %}
- <form action="{% url 'config_integration' action='enable' name=integration.integration_type.name %}"
- method="POST" role="form" data-async="#hi-main-content">
- {% csrf_token %}
- <button type="submit" class="btn btn-success btn-control" role="button" >ENABLE</button>
- </form>
- {% endif %}
- </div>
- <div class="col-2">
- {% if integration.is_enabled %}
- <form action="{% url 'config_integration' action='sync' name=integration.integration_type.name %}"
- method="POST" role="form" data-async="#hi-main-content">
- {% csrf_token %}
- <button type="submit" class="btn btn-info btn-control" role="button" >SYNC</button>
- </form>
- {% else %}
- ---
- {% endif %}
+
+ <div class="tab-pane fade" id="hi-other" role="tabpanel" aria-labelledby="hi-other-tab">
+ TBD for Other
</div>
</div>
- {% endfor %}
</div>
diff --git a/src/hi/apps/config/urls.py b/src/hi/apps/config/urls.py
index acbda865..15c22b1a 100644
--- a/src/hi/apps/config/urls.py
+++ b/src/hi/apps/config/urls.py
@@ -9,8 +9,4 @@ urlpatterns = [
views.ConfigHomePaneView.as_view(),
name='config_home_pane' ),
- re_path( r'^integration/(?P<action>\w+)/(?P<name>\w+)$',
- views.ConfigIntegrationView.as_view(),
- name='config_integration' ),
-
]
diff --git a/src/hi/apps/config/views.py b/src/hi/apps/config/views.py
index ef2790cf..7e12996e 100644
--- a/src/hi/apps/config/views.py
+++ b/src/hi/apps/config/views.py
@@ -1,41 +1,14 @@
from django.shortcuts import render
from django.views.generic import View
-from hi.integrations.core.enums import IntegrationType
-from hi.integrations.core.integration_manager import IntegrationManager
+from hi.integrations.core.views import IntegrationViewMixin
-class ConfigHomePaneView( View ):
+class ConfigHomePaneView( View, IntegrationViewMixin ):
def get(self, request, *args, **kwargs):
context = {
- 'integration_list': IntegrationManager().get_all_integrations(),
}
+ context.update( self.get_integration_config_tab_context() )
return render( request, 'config/panes/home.html', context )
-
-
-class ConfigIntegrationView( View ):
-
- def post(self, request, *args, **kwargs):
-
- action = kwargs.get('action')
- integration_type = IntegrationType.from_name( kwargs.get('name') )
-
- integration = IntegrationManager().get_integration( integration_type = integration_type )
-
-
- if action == 'enable':
- zzz
- elif action == 'disable':
- zzz
- elif action == 'sync':
- zzz
- else:
- raise ValueError( f'Unknown integration action "{action}". )
-
-
- context = {
- }
- return render( request, 'config/panes/home.html', context )
-
diff --git a/src/hi/integrations/core/integration_manager.py b/src/hi/integrations/core/integration_factory.py
similarity index 66%
rename from src/hi/integrations/core/integration_manager.py
rename to src/hi/integrations/core/integration_factory.py
index 4fc663ca..49f4e5dc 100644
--- a/src/hi/integrations/core/integration_manager.py
+++ b/src/hi/integrations/core/integration_factory.py
@@ -3,13 +3,16 @@ from typing import List
from hi.apps.common.singleton import Singleton
+from hi.integrations.zoneminder.zm_gateway import ZoneMinderGateway
+
from .enums import IntegrationType
+from .integration_gateway import IntegrationGateway
from .models import Integration
logger = logging.getLogger(__name__)
-class IntegrationManager( Singleton ):
+class IntegrationFactory( Singleton ):
def __init_singleton__( self ):
return
@@ -30,3 +33,9 @@ class IntegrationManager( Singleton ):
integration_type_str = str(integration_type),
is_enabled = False,
)
+
+ def get_integration_gateway( self, integration_type : IntegrationType ) -> IntegrationGateway:
+ if integration_type == IntegrationType.ZONEMINDER:
+ return ZoneMinderGateway()
+ else:
+ raise ValueError( f'The "{integration_type}" integration is not yet implemented.' )
diff --git a/src/hi/integrations/core/integration_gateway.py b/src/hi/integrations/core/integration_gateway.py
new file mode 100644
index 00000000..511c7027
--- /dev/null
+++ b/src/hi/integrations/core/integration_gateway.py
@@ -0,0 +1,30 @@
+from django.http import HttpRequest, HttpResponse
+
+from .enums import IntegrationType
+from .models import Integration
+
+
+class IntegrationGateway:
+ """
+ Each integration needs to provide an Integration Manager that implements these methods.
+ """
+
+ def enable( self, request : HttpRequest ) -> HttpResponse:
+ raise NotImplementedError('Subclasses must override this method')
+
+ def disable( self, request : HttpRequest ) -> HttpResponse:
+ raise NotImplementedError('Subclasses must override this method')
+
+ def manage( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:
+ raise NotImplementedError('Subclasses must override this method')
+
+ def get_integration( self, integration_type : IntegrationType ) -> Integration:
+ try:
+ return Integration.objects.get( integration_type_str = str(integration_type) )
+ except Integration.DoesNotExist:
+ return Integration(
+ integration_type_str = str(integration_type),
+ is_enabled = False,
+ )
+
+
diff --git a/src/hi/integrations/core/templates/core/panes/config_tab.html b/src/hi/integrations/core/templates/core/panes/config_tab.html
new file mode 100644
index 00000000..1b467aeb
--- /dev/null
+++ b/src/hi/integrations/core/templates/core/panes/config_tab.html
@@ -0,0 +1,54 @@
+{% if error_message %}
+<div class="alert alert-danger">
+ <b>Error</b>: {{ error_message }}
+</div>
+{% endif %}
+
+{% if info_message %}
+<div class="alert alert-info">
+ {{ info_message }}
+</div>
+{% endif %}
+
+{% for integration in integration_list %}
+<div class="row hi-config-integration">
+ <div class="col-2">
+ {{ integration.integration_type.label }}
+ </div>
+ <div class="col-2">
+ {% if integration.is_enabled %}
+ <span class="text-success">ENABLED</span>
+ {% else %}
+ <span class="text-danger">DISABLED</span>
+ {% endif %}
+ </div>
+ <div class="col-2">
+ {% if integration.is_enabled %}
+ <form action="{% url 'integration_config' name=integration.integration_type.name action='disable' %}"
+ method="POST" role="form" data-async="#hi-config-integration-tab">
+ {% csrf_token %}
+ <button type="submit" class="btn btn-danger btn-control" role="button"">DISABLE</button>
+ </form>
+
+ {% else %}
+ <form action="{% url 'integration_config' name=integration.integration_type.name action='enable' %}"
+ method="POST" role="form" data-async="#hi-config-integration-tab">
+ {% csrf_token %}
+ <button type="submit" class="btn btn-success btn-control" role="button" >ENABLE</button>
+ </form>
+ {% endif %}
+ </div>
+ <div class="col-2">
+ {% if integration.is_enabled %}
+ <a href="{% url 'integration_manage' name=integration.integration_type.name %}"
+ class="btn btn-info btn-control" role="button"
+ data-async="#hi-config-integration-tab" >
+ MANAGE
+ </a>
+ </form>
+ {% else %}
+ ---
+ {% endif %}
+ </div>
+</div>
+{% endfor %}
diff --git a/src/hi/integrations/core/urls.py b/src/hi/integrations/core/urls.py
new file mode 100644
index 00000000..13bd8f0a
--- /dev/null
+++ b/src/hi/integrations/core/urls.py
@@ -0,0 +1,16 @@
+
+from django.urls import re_path
+
+from . import views
+
+
+urlpatterns = [
+
+ re_path( r'^config/(?P<name>\w+)/(?P<action>\w+)$',
+ views.IntegrationConfigTabView.as_view(),
+ name='integration_config' ),
+
+ re_path( r'^manage/(?P<name>\w+)$',
+ views.IntegrationManageView.as_view(),
+ name='integration_manage' ),
+]
diff --git a/src/hi/integrations/core/views.py b/src/hi/integrations/core/views.py
new file mode 100644
index 00000000..b772c53d
--- /dev/null
+++ b/src/hi/integrations/core/views.py
@@ -0,0 +1,66 @@
+from django.shortcuts import render
+from django.views.generic import View
+
+from .enums import IntegrationType
+from .integration_factory import IntegrationFactory
+
+
+class IntegrationViewMixin:
+
+ def get_integration_config_tab_context(self):
+ return {
+ 'integration_list': IntegrationFactory().get_all_integrations(),
+ }
+
+
+class IntegrationConfigTabView( View, IntegrationViewMixin ):
+
+ def post(self, request, *args, **kwargs):
+
+ error_message = None
+ try:
+ integration_type = IntegrationType.from_name( kwargs.get('name') )
+ action = kwargs.get('action')
+
+ integration_gateway = IntegrationFactory().get_integration_gateway(
+ integration_type = integration_type,
+ )
+
+ if action == 'enable':
+ return integration_gateway.enable( request = request )
+ elif action == 'disable':
+ return integration_gateway.disable( request = request )
+
+ error_message = f'Unknown integration config action "{action}".'
+ except Exception as e:
+ error_message = str(e)
+
+ context = {
+ 'error_message': error_message,
+ }
+ context.update( self.get_integration_config_tab_context() )
+ return render( request, 'core/panes/config_tab.html', context )
+
+
+class IntegrationManageView( View, IntegrationViewMixin ):
+
+ def get(self, request, *args, **kwargs):
+
+ error_message = None
+ try:
+ integration_type = IntegrationType.from_name( kwargs.get('name') )
+ integration_gateway = IntegrationFactory().get_integration_gateway(
+ integration_type = integration_type,
+ )
+ return integration_gateway.manage( request = request, *args, **kwargs )
+ except Exception as e:
+ error_message = str(e)
+
+ context = {
+ 'error_message': error_message,
+ }
+ context.update( self.get_integration_config_tab_context() )
+ return render( request, 'core/panes/config_tab.html', context )
+
+ def post(self, request, *args, **kwargs):
+ return self.get( request, *args, **kwargs)
diff --git a/src/hi/integrations/zoneminder/management/commands/zm_test.py b/src/hi/integrations/zoneminder/management/commands/zm_test.py
index c7b19372..12738c10 100644
--- a/src/hi/integrations/zoneminder/management/commands/zm_test.py
+++ b/src/hi/integrations/zoneminder/management/commands/zm_test.py
@@ -20,7 +20,7 @@ class Command( BaseCommand, CommandLoggerMixin ):
'apiurl': 'https://bordeaux:8443/zm/api',
'portalurl': 'https://bordeaux:8443/zm',
'user': 'admin',
- 'password': '--REDACTED--', # TODO: Need to manuallyt tweak this.
+ 'password': '--REDACTED--', # TODO: Need to manually tweak this.
# 'disable_ssl_cert_check': True
}
try:
diff --git a/src/hi/integrations/zoneminder/templates/zoneminder/panes/activate.html b/src/hi/integrations/zoneminder/templates/zoneminder/panes/activate.html
new file mode 100644
index 00000000..371cb61f
--- /dev/null
+++ b/src/hi/integrations/zoneminder/templates/zoneminder/panes/activate.html
@@ -0,0 +1,3 @@
+<h3>ZM Activate</h3>
+
+TBD
diff --git a/src/hi/integrations/zoneminder/templates/zoneminder/panes/deactivate.html b/src/hi/integrations/zoneminder/templates/zoneminder/panes/deactivate.html
new file mode 100644
index 00000000..da04da9e
--- /dev/null
+++ b/src/hi/integrations/zoneminder/templates/zoneminder/panes/deactivate.html
@@ -0,0 +1,3 @@
+<h3>ZM Deactivate</h3>
+
+TBD
diff --git a/src/hi/integrations/zoneminder/templates/zoneminder/panes/manage.html b/src/hi/integrations/zoneminder/templates/zoneminder/panes/manage.html
new file mode 100644
index 00000000..7e73598d
--- /dev/null
+++ b/src/hi/integrations/zoneminder/templates/zoneminder/panes/manage.html
@@ -0,0 +1,14 @@
+<h3>ZoneMinder Integration</h3>
+
+{% if processing_result %}
+{% include "common/processing_result.html" with processing_result=processing_result %}
+{% endif %}
+
+<div class="col-2">
+ <form action="{% url 'integration_manage' name=integration_type.name %}"
+ method="POST" role="form" data-async="#hi-config-integration-tab">
+ {% csrf_token %}
+ <button type="submit" class="btn btn-primary btn-control" role="button"
+ name="action" value="sync" >SYNC</button>
+ </form>
+</div>
diff --git a/src/hi/integrations/zoneminder/views.py b/src/hi/integrations/zoneminder/views.py
new file mode 100644
index 00000000..c875a4ee
--- /dev/null
+++ b/src/hi/integrations/zoneminder/views.py
@@ -0,0 +1,53 @@
+from django.shortcuts import render
+from django.views.generic import View
+
+from hi.integrations.core.enums import IntegrationType
+
+from .zm_manager import ZoneMinderManager
+
+
+class ZmEnableView( View ):
+
+ def post(self, request, *args, **kwargs):
+
+
+ # TODO:
+ # Check if have all needed properties
+ # If not, render form for entering with button to activate
+
+ context = {
+ }
+ return render( request, 'zoneminder/panes/activate.html', context )
+
+
+class ZmDisableView( View ):
+
+ def post(self, request, *args, **kwargs):
+
+ context = {
+ }
+ return render( request, 'zoneminder/panes/deactivate.html', context )
+
+
+class ZmManageView( View ):
+
+ def get(self, request, *args, **kwargs):
+
+ context = {
+ 'integration_type': IntegrationType.ZONEMINDER
+ }
+ return render( request, 'zoneminder/panes/manage.html', context )
+
+
+class ZmSyncView( View ):
+
+ def post(self, request, *args, **kwargs):
+
+ processing_result = ZoneMinderManager().sync()
+
+ context = {
+ 'integration_type': IntegrationType.ZONEMINDER,
+ 'processing_result': processing_result,
+ }
+ return render( request, 'zoneminder/panes/manage.html', context )
+
diff --git a/src/hi/integrations/zoneminder/zm_gateway.py b/src/hi/integrations/zoneminder/zm_gateway.py
new file mode 100644
index 00000000..5ae1bb3f
--- /dev/null
+++ b/src/hi/integrations/zoneminder/zm_gateway.py
@@ -0,0 +1,28 @@
+import logging
+
+from django.http import HttpRequest, HttpResponse
+
+from hi.integrations.core.integration_gateway import IntegrationGateway
+
+from . import views
+
+logger = logging.getLogger(__name__)
+
+
+class ZoneMinderGateway( IntegrationGateway ):
+
+ def enable( self, request : HttpRequest ) -> HttpResponse:
+ return views.ZmEnableView().post( request )
+
+ def disable( self, request : HttpRequest ) -> HttpResponse:
+ return views.ZmDisableView().post( 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 )
+
+ return views.ZmManageView().get( request, *args, **kwargs )
+
+
diff --git a/src/hi/integrations/zoneminder/zm_integration.py b/src/hi/integrations/zoneminder/zm_integration.py
deleted file mode 100644
index 526bde6a..00000000
--- a/src/hi/integrations/zoneminder/zm_integration.py
+++ /dev/null
@@ -1,80 +0,0 @@
-import logging
-import pyzm.api as pyzm_api
-
-from hi.apps.common.database_lock import ExclusionLockContext
-
-from hi.integrations.core.enums import IntegrationType
-from hi.integrations.core.exceptions import IntegrationPropertyError
-from hi.integrations.core.integration_manager import IntegrationManager
-
-from .enums import ZmPropertyName
-
-logger = logging.getLogger(__name__)
-
-
-class ZoneMinderIntegration:
-
- SYNCHRONIZATION_LOCK_NAME = 'zm_integration_sync'
-
- @classmethod
- def create_zm_client(cls):
-
- zm_integration = IntegrationManager().get_integration( IntegrationType.ZONEMINDER )
- if not zm_integration.is_enabled:
- logger.debug( 'ZoneMinder integration is not enabled.' )
- return None
-
- # Verify integration
- property_dict = zm_integration.property_dict
- for zm_prop_name in ZmPropertyName:
- zm_prop = property_dict.get( zm_prop_name.name )
- if not zm_prop:
- raise IntegrationPropertyError( f'Missing ZM property {zm_prop_name.name}' )
- if zm_prop.is_required and not zm_prop.value.strip():
- raise IntegrationPropertyError( f'Missing ZM property value for {zm_prop_name.name}' )
-
- continue
-
- api_options = {
- 'apiurl': property_dict.get( ZmPropertyName.API_URL.name ).value,
- 'portalurl': property_dict.get( ZmPropertyName.PORTAL_URL.name ).value,
- 'user': property_dict.get( ZmPropertyName.API_USER.name ).value,
- 'password': property_dict.get( ZmPropertyName.API_PASSWORD.name ).value,
- # 'disable_ssl_cert_check': True
- }
-
- return pyzm_api.ZMApi( options = api_options )
-
- @classmethod
- def sync( cls ):
- try:
- with ExclusionLockContext( name = cls.SYNCHRONIZATION_LOCK_NAME ):
- logger.debug( 'ZoneMinder integration sync started.' )
- cls._sync_helper()
- except RuntimeError:
- pass
- finally:
- logger.debug( 'ZoneMinder integration sync ended.' )
- return
-
- @classmethod
- def _sync_helper( cls ):
- logger.debug( 'Getting ZM monitors.' )
- zm_client = cls.create_zm_client()
- if not zm_client:
- logger.debug( 'ZoneMinder client not created. ZM integration disabled?.' )
- return
-
- ms = zm_client.monitors()
- for m in ms.list():
-
- logger.debug('Name:{} Enabled:{} Type:{} Dims:{}'.format( m.name(),
- m.enabled(),
- m.type(),
- m.dimensions()) )
- logger.debug( m.status() )
-
- # TODO: Add new cameras if needed
-
- continue
- return
diff --git a/src/hi/integrations/zoneminder/zm_manager.py b/src/hi/integrations/zoneminder/zm_manager.py
index 8b07e66a..23bf6b87 100644
--- a/src/hi/integrations/zoneminder/zm_manager.py
+++ b/src/hi/integrations/zoneminder/zm_manager.py
@@ -1,14 +1,23 @@
import logging
+import pyzm.api as pyzm_api
+from hi.apps.common.database_lock import ExclusionLockContext
+from hi.apps.common.processing_result import ProcessingResult
from hi.apps.common.singleton import Singleton
-from .zm_integration import ZoneMinderIntegration
+from hi.integrations.core.enums import IntegrationType
+from hi.integrations.core.exceptions import IntegrationPropertyError
+from hi.integrations.core.models import Integration
+
+from .enums import ZmPropertyName
logger = logging.getLogger(__name__)
class ZoneMinderManager( Singleton ):
+ SYNCHRONIZATION_LOCK_NAME = 'zm_integration_sync'
+
def __init_singleton__( self ):
self._is_loading = False
self._zm_client = None
@@ -25,9 +34,77 @@ class ZoneMinderManager( Singleton ):
return
try:
self._is_loading = True
- self._zm_client = ZoneMinderIntegration.create_zm_client()
+ self._zm_client = self.create_zm_client()
finally:
self._is_loading = False
logger.debug( 'ZoneMinder loading completed.' )
return
+
+ def create_zm_client(self):
+ try:
+ zm_integration = Integration.objects.get( integration_type_str = str(IntegrationType.ZONEMINDER) )
+ except Integration.DoesNotExist:
+ logger.debug( 'ZoneMinder integration is not enabled.' )
+
+ if not zm_integration.is_enabled:
+ logger.debug( 'ZoneMinder integration is not enabled.' )
+ return None
+
+ # Verify integration
+ property_dict = zm_integration.property_dict
+ for zm_prop_name in ZmPropertyName:
+ zm_prop = property_dict.get( zm_prop_name.name )
+ if not zm_prop:
+ raise IntegrationPropertyError( f'Missing ZM property {zm_prop_name.name}' )
+ if zm_prop.is_required and not zm_prop.value.strip():
+ raise IntegrationPropertyError( f'Missing ZM property value for {zm_prop_name.name}' )
+
+ continue
+
+ api_options = {
+ 'apiurl': property_dict.get( ZmPropertyName.API_URL.name ).value,
+ 'portalurl': property_dict.get( ZmPropertyName.PORTAL_URL.name ).value,
+ 'user': property_dict.get( ZmPropertyName.API_USER.name ).value,
+ 'password': property_dict.get( ZmPropertyName.API_PASSWORD.name ).value,
+ # 'disable_ssl_cert_check': True
+ }
+
+ return pyzm_api.ZMApi( options = api_options )
+
+ def sync( self ) -> ProcessingResult:
+ try:
+ with ExclusionLockContext( name = self.SYNCHRONIZATION_LOCK_NAME ):
+ logger.debug( 'ZoneMinder integration sync started.' )
+ return self._sync_helper()
+ except RuntimeError as e:
+ return ProcessingResult(
+ title = 'ZM Sync Result',
+ error_list = [ str(e) ],
+ )
+ finally:
+ logger.debug( 'ZoneMinder integration sync ended.' )
+
+ def _sync_helper( self ) -> ProcessingResult:
+ processing_result = ProcessingResult( title = 'ZM Sync Result' )
+
+ logger.debug( 'Getting ZM monitors.' )
+ zm_client = self.zm_client
+ if not zm_client:
+ logger.debug( 'ZoneMinder client not created. ZM integration disabled?' )
+ processing_result.error_list.append( 'Sync problem. ZM integration disabled?' )
+ return processing_result
+
+ ms = zm_client.monitors()
+ for m in ms.list():
+
+ logger.debug('Name:{} Enabled:{} Type:{} Dims:{}'.format( m.name(),
+ m.enabled(),
+ m.type(),
+ m.dimensions()) )
+ logger.debug( m.status() )
+
+ # TODO: Add new cameras if needed
+
+ continue
+ return processing_result
diff --git a/src/hi/templates/panes/side_panel.html b/src/hi/templates/panes/side_panel.html
index da310328..9a279ecf 100644
--- a/src/hi/templates/panes/side_panel.html
+++ b/src/hi/templates/panes/side_panel.html
@@ -4,7 +4,7 @@
<a href="{% url 'config_home_pane' %}"
class="btn btn-tertiary btn-control" role="button"
data-async="#hi-main-content" >
- SETTINGS
+ ADMIN
</a>
</div>
diff --git a/src/hi/urls.py b/src/hi/urls.py
index 7b518744..62398b14 100644
--- a/src/hi/urls.py
+++ b/src/hi/urls.py
@@ -27,6 +27,7 @@ urlpatterns = [
re_path( r'^index.html$', views.HomeView.as_view(), name='home_index' ),
re_path( r'^config/', include('hi.apps.config.urls' )),
+ re_path( r'^integration/', include('hi.integrations.core.urls' )),
re_path( r'^location/', include('hi.apps.location.urls' )),
]