Home Information - Your home, your data, organized.
Python
Bug fixes and improvements for ZoneMinder simulator.
Anthony Cassandra519f54b1a97b
diff --git a/src/hi/apps/common/templatetags/common_template_helpers.py b/src/hi/apps/common/templatetags/common_template_helpers.pyindex f8df0856..44269342 100644--- a/src/hi/apps/common/templatetags/common_template_helpers.py+++ b/src/hi/apps/common/templatetags/common_template_helpers.py@@ -1,6 +1,7 @@import osimport randomimport urllib+import uuidfrom django import templatefrom django.conf import settings@@ -16,6 +17,13 @@ def get_item(dictionary, key):return dictionary.get(key)+def generate_uuid():+ uuid_value = str(uuid.uuid4())+ print(f"\n\nGenerated UUID: {uuid_value}\n")+ return uuid_value++@register.simple_tagdef pagination_url( page_number, existing_urlencoded_params = None ):diff --git a/src/hi/apps/control/templates/control/panes/controller_data.html b/src/hi/apps/control/templates/control/panes/controller_data.htmlindex e8b71622..5cb90a35 100644--- a/src/hi/apps/control/templates/control/panes/controller_data.html+++ b/src/hi/apps/control/templates/control/panes/controller_data.html@@ -1,9 +1,10 @@{% load common_template_helpers %}-<div id="hi-controller-{{ controller_data.controller.id }}"+{% generate_uuid as unique_id %}+<div id="hi-controller-{{ controller_data.controller.id }}-{{ unique_id }}"class="{{ controller_data.css_class }}" ><form action="{% url 'control_controller' controller_id=controller_data.controller.id %}"method="post"- class="form" data-async="#hi-controller-{{ controller_data.controller.id }}" data-mode="replace">+ class="form" data-async="#hi-controller-{{ controller_data.controller.id }}-{{ unique_id }}" data-mode="replace">{% csrf_token %}{% include_with_fallback controller_data.controller.entity_state.entity_state_type.controller_template_name "control/panes/controller_default.html" %}diff --git a/src/hi/services/zoneminder/monitors.py b/src/hi/services/zoneminder/monitors.pyindex 5ffc3c48..22b16395 100644--- a/src/hi/services/zoneminder/monitors.py+++ b/src/hi/services/zoneminder/monitors.py@@ -22,6 +22,9 @@ class ZoneMinderMonitor( PeriodicMonitor, ZoneMinderMixin, SensorResponseMixin )# TODO: Move this into the integrations attributes for users to setZONEMINDER_SERVER_TIMEZONE = 'America/Chicago'ZONEMINDER_POLLING_INTERVAL_SECS = 10++ TRACE = True+ CACHING_DISABLED = Truedef __init__( self ):super().__init__(@@ -181,7 +184,7 @@ class ZoneMinderMonitor( PeriodicMonitor, ZoneMinderMixin, SensorResponseMixin )current_poll_datetime = datetimeproxy.now()sensor_response_map = dict()- for zm_monitor in self.zm_manager().get_zm_monitors():+ for zm_monitor in self.zm_manager().get_zm_monitors( force_load = self.CACHING_DISABLED ):video_stream_sensor_response = self._create_video_stream_sensor_response(zm_monitor = zm_monitor,@@ -203,7 +206,7 @@ class ZoneMinderMonitor( PeriodicMonitor, ZoneMinderMixin, SensorResponseMixin )sensor_response_map = dict()active_run_state_name = None- for zm_state in self.zm_manager().get_zm_states():+ for zm_state in self.zm_manager().get_zm_states( force_load = self.CACHING_DISABLED ):if zm_state.active():active_run_state_name = zm_state.name()breakdiff --git a/src/hi/simulator/base_models.py b/src/hi/simulator/base_models.pyindex 4335a317..51aebb3c 100644--- a/src/hi/simulator/base_models.py+++ b/src/hi/simulator/base_models.py@@ -2,8 +2,6 @@ from dataclasses import dataclass, fields, MISSINGfrom datetime import datetimefrom typing import Any, Dict, List, Tuple, Type-import hi.apps.common.datetimeproxy as datetimeproxy-from .enums import SimEntityType, SimStateType@@ -97,8 +95,6 @@ class SimState:# Subclasses may provide a default value for this.value : Any = None-- value_datetime : datetime = None@propertydef name(self):@@ -109,7 +105,6 @@ class SimState:if self.value == value_str:returnself.value = value_str- self.value_datetime = datetimeproxy.now()return@property@@ -131,7 +126,6 @@ class SimState:if not other_sim_state:returnself.value = other_sim_state.value- self.value_datetime = other_sim_state.value_datetimereturndiff --git a/src/hi/simulator/services/zoneminder/constants.py b/src/hi/simulator/services/zoneminder/constants.pyindex f66174a4..e1c50846 100644--- a/src/hi/simulator/services/zoneminder/constants.py+++ b/src/hi/simulator/services/zoneminder/constants.py@@ -1,4 +1,15 @@class ZmSimConstants:+ # TODO: ZoneMinder's API using naive times with no timezone info.+ # Internally, ZoneMinder does have a timezone defined, but it is up to+ # the external API user to know what that is (unfortunately). Thus, in+ # the ZoneMinder integration, it has a timezone attribute the user must+ # set and ensure it matches ZoneMinder. When simulating ZoneMinder's+ # API we also have to ensure the integration configuration matches the+ # timezone used in the simulator. For now, we just hardcode this and+ # expect the developer to make sure the integration setting matches. It+ # would be better if the simulator allowed this to be adjusable through+ # the UI.+ #TIMEZONE_NAME = 'America/Chicago'diff --git a/src/hi/simulator/services/zoneminder/sim_models.py b/src/hi/simulator/services/zoneminder/sim_models.pyindex 2d551c39..953b5bd4 100644--- a/src/hi/simulator/services/zoneminder/sim_models.py+++ b/src/hi/simulator/services/zoneminder/sim_models.py@@ -3,6 +3,7 @@ from datetime import datetimefrom typing import List, Tupleimport hi.apps.common.datetimeproxy as datetimeproxy+from hi.apps.common.utils import str_to_boolfrom hi.simulator.base_models import SimEntityFields, SimState, SimEntityDefinitionfrom hi.simulator.enums import SimEntityType, SimStateType@@ -275,6 +276,10 @@ class ZmMonitorMotionState( SimState ):def name(self):return 'Camera Motion'+ def set_value_from_string( self, value_str : str ):+ self.value = str_to_bool( value_str )+ return+@dataclassclass ZmSimEvent:diff --git a/src/hi/static/js/status.js b/src/hi/static/js/status.jsindex 32f92314..9e578e20 100644--- a/src/hi/static/js/status.js+++ b/src/hi/static/js/status.js@@ -40,7 +40,6 @@const AlarmMessageHtmlAttr = 'alarmMessageHtml';let gServerPollingTimer = null;- let gCssClassElementCache = {};let gLastServerPollSuccessTime = (new Date()).getTime();let gIsServerErrorShowing = false;let gLastStartServerDate = null;@@ -196,7 +195,7 @@function handleCssClassUpdates( updateMap ) {for ( let cssClass in updateMap ) {- let elements = getElementByCssClass( cssClass );+ let elements = getElementsByCssClass( cssClass );let attrMap = updateMap[cssClass];for ( let attrName in attrMap ) {let attrValue = attrMap[attrName];@@ -234,24 +233,9 @@}}- function getElementByCssClass( cssClass ) {-- if ( cssClass in gCssClassElementCache ) {- const cachedElements = gCssClassElementCache[cssClass];- const connectedElements = $(cachedElements).filter( function () {- return this.isConnected;- });- if ( cachedElements.length == connectedElements.length) {- return connectedElements;- }- }+ function getElementsByCssClass( cssClass ) {let elements = $(`.${cssClass}`);- if ( elements.length > 0 ) {- gCssClassElementCache[cssClass] = elements;- } else {- delete gCssClassElementCache[cssClass];- }return elements;}