Skip to content

Home Information - Your home, your data, organized.

Python

Collection page styling (#228)

Tony C682606caccd8
diff --git a/src/hi/apps/collection/collection_manager.py b/src/hi/apps/collection/collection_manager.py
index 97074911..9e145684 100644
--- a/src/hi/apps/collection/collection_manager.py
+++ b/src/hi/apps/collection/collection_manager.py
@@ -66,16 +66,7 @@ class CollectionManager(Singleton):
entity_list = [ x.entity for x in collection_entity_list ]
entity_status_data_list = StatusDisplayManager().get_entity_status_data_list(
entities = entity_list,
- )
-
- svg_item_factory = SvgItemFactory()
- for entity_status_data in entity_status_data_list:
- svg_icon_item = svg_item_factory.get_display_only_svg_icon_item(
- entity = entity_status_data.entity,
- )
- entity_status_data.display_only_svg_icon_item = svg_icon_item
- continue
-
+ )
return CollectionData(
collection = collection,
entity_status_data_list = entity_status_data_list,
diff --git a/src/hi/apps/collection/edit/forms.py b/src/hi/apps/collection/edit/forms.py
index 77b07605..bda32c51 100644
--- a/src/hi/apps/collection/edit/forms.py
+++ b/src/hi/apps/collection/edit/forms.py
@@ -13,7 +13,6 @@ class CollectionBaseForm( forms.ModelForm ):
'name',
'collection_type_str',
'collection_view_type_str',
- 'order_id',
)
collection_type_str = forms.ChoiceField(
@@ -34,8 +33,14 @@ class CollectionBaseForm( forms.ModelForm ):
class CollectionEditForm( CollectionBaseForm ):
- pass
+ class Meta(CollectionBaseForm.Meta):
+ fields = CollectionBaseForm.Meta.fields + ('order_id',)
+
+ widgets = {
+ 'order_id': forms.NumberInput( attrs={'class': 'form-control'} ),
+ }
+
class CollectionAddForm( CollectionBaseForm ):
diff --git a/src/hi/apps/collection/edit/views.py b/src/hi/apps/collection/edit/views.py
index 387133ce..d3a267bf 100644
--- a/src/hi/apps/collection/edit/views.py
+++ b/src/hi/apps/collection/edit/views.py
@@ -82,7 +82,14 @@ class CollectionAddView( HiModalView ):
cleaneds_data = collection_add_form.clean()
with transaction.atomic():
- collection = collection_add_form.save()
+ collection = collection_add_form.save( commit = False )
+ last_collection = Collection.objects.order_by( '-order_id' ).first()
+ if last_collection:
+ collection.order_id = last_collection.order_id + 1
+ else:
+ collection.order_id = 0
+ collection.save()
+
if cleaneds_data['include_in_location_view']:
self._add_to_location_view(
request = request,
@@ -305,6 +312,7 @@ class CollectionEntityToggleView( View, CollectionViewMixin, EntityViewMixin ):
is_editing = request.view_parameters.is_editing,
)
context = collection_data.to_template_context()
+
template = get_template( 'collection/panes/collection_view.html' )
collection_content = template.render( context, request = request )
diff --git a/src/hi/apps/collection/enums.py b/src/hi/apps/collection/enums.py
index 5974242d..8c3b37e2 100644
--- a/src/hi/apps/collection/enums.py
+++ b/src/hi/apps/collection/enums.py
@@ -23,6 +23,10 @@ class CollectionType(LabeledEnum):
def default(cls):
return cls.OTHER
+ @property
+ def is_cameras(self):
+ return bool( self == CollectionType.CAMERAS )
+
class CollectionViewType(LabeledEnum):
@@ -34,4 +38,5 @@ class CollectionViewType(LabeledEnum):
def is_list(self):
return self == CollectionViewType.LIST
-
+
+
diff --git a/src/hi/apps/collection/models.py b/src/hi/apps/collection/models.py
index 07500657..ce2aa5cd 100644
--- a/src/hi/apps/collection/models.py
+++ b/src/hi/apps/collection/models.py
@@ -30,7 +30,7 @@ class Collection( models.Model, LocationItemModelMixin ):
null = False, blank = False,
)
order_id = models.PositiveIntegerField(
- 'Order Id',
+ 'Position',
default = 0,
db_index = True,
)
@@ -82,7 +82,7 @@ class CollectionEntity(models.Model):
on_delete = models.CASCADE,
)
order_id = models.PositiveIntegerField(
- 'Order Id',
+ 'Position',
default = 0,
)
created_datetime = models.DateTimeField(
diff --git a/src/hi/apps/collection/templates/collection/edit/panes/collection_form.html b/src/hi/apps/collection/templates/collection/edit/panes/collection_form.html
index 95c78910..94ade67f 100644
--- a/src/hi/apps/collection/templates/collection/edit/panes/collection_form.html
+++ b/src/hi/apps/collection/templates/collection/edit/panes/collection_form.html
@@ -42,6 +42,7 @@
{% endif %}
</div>
+{% if collection_form.order_id %}
<div class="sidebar-form-field">
<label for="{{ collection_form.order_id.id_for_label }}" class="sidebar-form-label">{{ collection_form.order_id.label }}</label>
<input type="number" id="{{ collection_form.order_id.id_for_label }}" name="{{ collection_form.order_id.name }}" value="{{ collection_form.order_id.value|default:'' }}" class="sidebar-form-input">
@@ -49,3 +50,4 @@
<div class="sidebar-form-error">{{ collection_form.order_id.errors }}</div>
{% endif %}
</div>
+{% endif %}
diff --git a/src/hi/apps/collection/templates/collection/panes/collection_view.html b/src/hi/apps/collection/templates/collection/panes/collection_view.html
index 76361e64..16bc5833 100644
--- a/src/hi/apps/collection/templates/collection/panes/collection_view.html
+++ b/src/hi/apps/collection/templates/collection/panes/collection_view.html
@@ -1,31 +1,37 @@
<div id="hi-collection-view-main" class="hi-collection-view draggable-container">
<div class="h4"><small>Collection:</small> {{ collection.name }}</div>
-
+
{% if collection.collection_view_type.is_grid %}
- <div class="row">
+ <div class="collection-grid {{ collection_grid_css_class }}">
{% for entity_status_data in entity_status_data_list %}
- <div id="{{ entity_status_data.entity.html_id }}"
- class="{% if entity_status_data_list|length == 1 %}col-12{% elif entity_status_data_list|length <= 4 %}col-6{% else %}col-4{% endif %} {% if request.view_parameters.is_editing %}draggable{% endif %} mb-2"
- {% if request.view_parameters.is_editing %}draggable="true"{% endif %} >
- {% include "entity/panes/entity_status_card.html" with entity_status_data=entity_status_data %}
+ <div id="{{ entity_status_data.entity.html_id }}"
+ class="entity-item {{ entity_status_data.display_category.css_class }} {% if request.view_parameters.is_editing %}draggable{% endif %}"
+ {% if request.view_parameters.is_editing %}draggable="true"{% endif %} >
+ {% include "collection/panes/entity_card_grid.html" with entity_status_data=entity_status_data %}
</div>
- {% empty %}
- <div><em>No entities in collection.</em></div>
{% endfor %}
</div>
-
+
{% else %}
-
- {% for entity_status_data in entity_status_data_list %}
- <div id="{{ entity_status_data.entity.html_id }}"
- class="{% if request.view_parameters.is_editing %}draggable{% endif %}"
- {% if request.view_parameters.is_editing %}draggable="true"{% endif %} >
- {% include "entity/panes/entity_status_row.html" with entity_status_data=entity_status_data %}
+
+ <div class="collection-list">
+ {% for entity_status_data in entity_status_data_list %}
+ <div id="{{ entity_status_data.entity.html_id }}"
+ class="entity-row {{ entity_status_data.display_category.css_class }} {% if request.view_parameters.is_editing %}draggable{% endif %}"
+ {% if request.view_parameters.is_editing %}draggable="true"{% endif %} >
+ {% include "collection/panes/entity_card_list.html" with entity_status_data=entity_status_data %}
+ </div>
+ {% endfor %}
+ </div>
+
+ {% endif %}
+
+ {% if not entity_status_data_list %}
+ <div class="alert alert-info text-center w-100">
+ <div class="h4">No items in collection.</div>
+ {% if not request.view_parameters.is_editing %}
+ <div><em>Use <a href="{% url 'edit_start' %} ">Edit Mode</a> to add items.</em></div>
+ {% endif %}
</div>
- {% empty %}
- <div><em>No entities in collection.</em></div>
- {% endfor %}
-
{% endif %}
-
</div>
diff --git a/src/hi/apps/collection/templates/collection/panes/entity_card_grid.html b/src/hi/apps/collection/templates/collection/panes/entity_card_grid.html
new file mode 100644
index 00000000..96ac642e
--- /dev/null
+++ b/src/hi/apps/collection/templates/collection/panes/entity_card_grid.html
@@ -0,0 +1,12 @@
+<div class="card h-100">
+ <div class="card-body p-3">
+ {% include "collection/panes/entity_card_title.html" with entity_status_data=entity_status_data %}
+ {% if collection.collection_type.is_cameras %}
+ <div>
+ {% include "console/panes/entity_video_stream_w_link.html" with entity=entity_status_data.entity %}
+ </div>
+ {% else %}
+ {% include "collection/panes/entity_state_list.html" with entity_state_status_data_list=entity_status_data.entity_state_status_data_list %}
+ {% endif %}
+ </div>
+</div>
diff --git a/src/hi/apps/collection/templates/collection/panes/entity_card_list.html b/src/hi/apps/collection/templates/collection/panes/entity_card_list.html
new file mode 100644
index 00000000..40c0b7f9
--- /dev/null
+++ b/src/hi/apps/collection/templates/collection/panes/entity_card_list.html
@@ -0,0 +1,19 @@
+<div class="card h-100">
+ <div class="card-body">
+ <div class="d-flex">
+ <div class="entity-title-section flex-shrink-0">
+ {% include "collection/panes/entity_card_title.html" with entity_status_data=entity_status_data %}
+ </div>
+ {% if collection.collection_type.is_cameras %}
+ <div>
+ {% include "console/panes/entity_video_stream_w_link.html" with entity=entity_status_data.entity %}
+ </div>
+ {% else %}
+ <div class="entity-content-section flex-grow-1 ml-3">
+ {% include "collection/panes/entity_state_list.html" with entity_state_status_data_list=entity_status_data.entity_state_status_data_list %}
+ </div>
+ {% endif %}
+ </div>
+ </div>
+</div>
+
diff --git a/src/hi/apps/collection/templates/collection/panes/entity_card_title.html b/src/hi/apps/collection/templates/collection/panes/entity_card_title.html
new file mode 100644
index 00000000..7ac49992
--- /dev/null
+++ b/src/hi/apps/collection/templates/collection/panes/entity_card_title.html
@@ -0,0 +1,14 @@
+{% with entity=entity_status_data.entity %}
+<a href="{% if request.view_parameters.is_editing %}{% url 'entity_edit_mode' entity_id=entity_status_data.entity.id %}{% else %}{% url 'entity_edit' entity_id=entity_status_data.entity.id %}{% endif %}"
+ data-async="true">
+
+ <div class="d-flex justify-content-start">
+ <div class="display-only-svg-icon pr-2">
+ {% include "entity/panes/entity_display_only_svg_icon.html" with svg_icon_item=entity_status_data.display_only_svg_icon_item %}
+ </div>
+ <div>
+ {{ entity.name }}
+ </div>
+ </div>
+</a>
+{% endwith %}
diff --git a/src/hi/apps/collection/templates/collection/panes/entity_state_list.html b/src/hi/apps/collection/templates/collection/panes/entity_state_list.html
new file mode 100644
index 00000000..951e90b9
--- /dev/null
+++ b/src/hi/apps/collection/templates/collection/panes/entity_state_list.html
@@ -0,0 +1,7 @@
+<div>
+ {% for entity_state_status_data in entity_state_status_data_list %}
+ <div class="my-2">
+ {% include "collection/panes/entity_state_row.html" with entity_state_status_data=entity_state_status_data %}
+ </div>
+ {% endfor %}
+</div>
diff --git a/src/hi/apps/collection/templates/collection/panes/entity_state_row.html b/src/hi/apps/collection/templates/collection/panes/entity_state_row.html
new file mode 100644
index 00000000..a6ae0bba
--- /dev/null
+++ b/src/hi/apps/collection/templates/collection/panes/entity_state_row.html
@@ -0,0 +1,19 @@
+{% load common_tags %}
+{% load icons %}
+{% with sensor_response=entity_state_status_data.latest_sensor_response %}
+
+{% if entity_state_status_data.controller_data_list %}
+{% for controller_data in entity_state_status_data.controller_data_list %}
+<div class="text-muted text-center"><small>{{ controller_data.controller.name }}</small></div>
+{% include "control/panes/controller_data.html" with controller_data=controller_data in_modal_context=True %}
+{% endfor %}
+
+{% elif entity_state_status_data.sensor_response_list %}
+<div class="text-muted text-center"><small>{{ sensor_response.sensor.name }}</small></div>
+{% include_with_fallback sensor_response.sensor.entity_state.entity_state_type.value_template_name "sense/panes/sensor_response_value_default.html" %}
+
+{% else %}
+<div class="alert alert-info">No sensors or controllers defined.</div>
+{% endif %}
+
+{% endwith %}
diff --git a/src/hi/apps/collection/tests/test_collection_manager.py b/src/hi/apps/collection/tests/test_collection_manager.py
index e967d67c..84a4da67 100644
--- a/src/hi/apps/collection/tests/test_collection_manager.py
+++ b/src/hi/apps/collection/tests/test_collection_manager.py
@@ -580,3 +580,79 @@ class TestCollectionManager(BaseTestCase):
self.assertTrue(CollectionEntity.objects.filter(
entity=entity, collection=collection
).exists())
+
+ def test_collection_data_enhanced_entity_display_categories(self):
+ """Test collection data generation - entity display category classification."""
+ from hi.apps.entity.models import EntityState
+ from hi.apps.entity.enums import EntityType, EntityStateType
+
+ collection = Collection.objects.create(
+ name='Mixed Collection',
+ collection_type_str='OTHER',
+ collection_view_type_str='GRID'
+ )
+
+ # Create entities for each display category
+ plain_entity = Entity.objects.create(
+ name='Info Display',
+ entity_type_str=str(EntityType.OTHER),
+ has_video_stream=False,
+ )
+
+ video_entity = Entity.objects.create(
+ name='Security Camera',
+ entity_type_str=str(EntityType.CAMERA),
+ has_video_stream=True,
+ )
+
+ state_entity = Entity.objects.create(
+ name='Smart Switch',
+ entity_type_str=str(EntityType.LIGHT),
+ has_video_stream=False,
+ )
+
+ # Add state to state_entity
+ EntityState.objects.create(
+ entity=state_entity,
+ entity_state_type_str=str(EntityStateType.ON_OFF),
+ name='power_state',
+ )
+
+ # Create entity with both video and state (video should win)
+ hybrid_entity = Entity.objects.create(
+ name='PTZ Camera',
+ entity_type_str=str(EntityType.CAMERA),
+ has_video_stream=True,
+ )
+
+ EntityState.objects.create(
+ entity=hybrid_entity,
+ entity_state_type_str=str(EntityStateType.MOVEMENT),
+ name='pan_tilt_state',
+ )
+
+ # Add entities to collection
+ CollectionEntity.objects.create(collection=collection, entity=plain_entity, order_id=1)
+ CollectionEntity.objects.create(collection=collection, entity=video_entity, order_id=2)
+ CollectionEntity.objects.create(collection=collection, entity=state_entity, order_id=3)
+ CollectionEntity.objects.create(collection=collection, entity=hybrid_entity, order_id=4)
+
+ manager = CollectionManager()
+ collection_data = manager.get_collection_data(collection, is_editing=False)
+
+ # Generate basic template context - should only contain basic collection data
+ context = collection_data.to_template_context()
+
+ # Verify basic context contains collection and entity list
+ self.assertIn('collection', context)
+ self.assertIn('entity_status_data_list', context)
+ self.assertEqual(context['collection'], collection)
+ self.assertEqual(len(context['entity_status_data_list']), 4)
+
+ # Verify entity_status_data_list contains proper EntityStatusData objects
+ entity_names = [esd.entity.name for esd in context['entity_status_data_list']]
+ expected_names = ['Info Display', 'Security Camera', 'Smart Switch', 'PTZ Camera']
+ self.assertEqual(entity_names, expected_names)
+
+ return
+
diff --git a/src/hi/apps/collection/tests/test_views.py b/src/hi/apps/collection/tests/test_views.py
index e26a1b58..1754d394 100644
--- a/src/hi/apps/collection/tests/test_views.py
+++ b/src/hi/apps/collection/tests/test_views.py
@@ -1,10 +1,10 @@
import logging
-from unittest.mock import Mock, patch
+from unittest.mock import patch
from django.urls import reverse
from hi.apps.collection.collection_manager import CollectionManager
-from hi.apps.collection.models import Collection
+from hi.apps.collection.models import Collection, CollectionEntity
from hi.apps.entity.models import Entity
from hi.apps.location.models import Location, LocationView
from hi.enums import ViewType
@@ -151,24 +151,6 @@ class TestCollectionViewView(DualModeViewTestCase):
self.assertEqual(response.status_code, 404)
- @patch('hi.apps.collection.views.CollectionManager')
- def test_collection_data_passed_to_template(self, mock_manager_class):
- """Test that collection data is properly passed to template."""
- mock_manager = Mock()
- mock_collection_data = Mock()
- mock_collection_data.to_template_context.return_value = {
- 'collection': self.collection,
- 'entities': [self.entity1, self.entity2]
- }
- mock_manager.get_collection_data.return_value = mock_collection_data
- mock_manager_class.return_value = mock_manager
-
- url = reverse('collection_view', kwargs={'collection_id': self.collection.id})
- response = self.client.get(url)
-
- self.assertSuccessResponse(response)
- mock_manager.get_collection_data.assert_called_once()
-
class TestCollectionDetailsView(DualModeViewTestCase):
"""
@@ -248,3 +230,36 @@ class TestCollectionDetailsView(DualModeViewTestCase):
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
+
+
+class TestCollectionViewContextVariables(DualModeViewTestCase):
+ """
+ Tests for grid class and entity display category context variables.
+ """
+
+ def setUp(self):
+ super().setUp()
+
+ # Create test collection
+ self.collection = Collection.objects.create(
+ name='Test Collection',
+ collection_type_str='ROOM',
+ collection_view_type_str='MAIN'
+ )
+
+ # Create entities with different characteristics
+ self.plain_entity = Entity.objects.create(
+ name='Plain Entity',
+ entity_type_str='GENERAL',
+ has_video_stream=False,
+ )
+ self.video_entity = Entity.objects.create(
+ name='Video Entity',
+ entity_type_str='CAMERA',
+ has_video_stream=True,
+ )
+
+ # Add entities to collection
+ CollectionEntity.objects.create(collection=self.collection, entity=self.plain_entity, order_id=1)
+ CollectionEntity.objects.create(collection=self.collection, entity=self.video_entity, order_id=2)
+
diff --git a/src/hi/apps/collection/transient_models.py b/src/hi/apps/collection/transient_models.py
index 735e51ba..4000cae0 100644
--- a/src/hi/apps/collection/transient_models.py
+++ b/src/hi/apps/collection/transient_models.py
@@ -19,8 +19,21 @@ class CollectionData:
return {
'collection': self.collection,
'entity_status_data_list': self.entity_status_data_list,
+ 'collection_grid_css_class': self.grid_css_class,
+ 'entity_count': len(self.entity_status_data_list),
}
+ @property
+ def grid_css_class(self):
+ if self.collection.collection_type.is_cameras:
+ return 'grid-2-items'
+ entity_count = len(self.entity_status_data_list)
+ if entity_count >= 3:
+ return 'grid-3-plus-items'
+ if entity_count == 2:
+ return 'grid-2-items'
+ return 'grid-1-item'
+
@dataclass
class CollectionViewItem:
diff --git a/src/hi/apps/collection/views.py b/src/hi/apps/collection/views.py
index 950d4842..0523b4b8 100644
--- a/src/hi/apps/collection/views.py
+++ b/src/hi/apps/collection/views.py
@@ -63,7 +63,6 @@ class CollectionViewView( HiGridView, CollectionViewMixin ):
collection = collection,
is_editing = request.view_parameters.is_editing,
)
-
context = collection_data.to_template_context()
context['is_async_request'] = is_ajax( request )
return context
diff --git a/src/hi/apps/console/templates/console/panes/entity_video_stream_w_link.html b/src/hi/apps/console/templates/console/panes/entity_video_stream_w_link.html
new file mode 100644
index 00000000..53cd3ee9
--- /dev/null
+++ b/src/hi/apps/console/templates/console/panes/entity_video_stream_w_link.html
@@ -0,0 +1,9 @@
+{% if entity.has_video_stream %}
+<a href="{% url 'console_entity_video_stream_dispatch' entity_id=entity.id %}"
+ data-entity-id="{{ entity.id }}"
+ data-async="#main-content"
+ class="btn btn-sm btn-outline-primary"
+ role="button">
+ {% include "console/panes/entity_video_stream.html" with entity=entity %}
+</a>
+{% endif %}
diff --git a/src/hi/apps/control/templates/control/modals/controller_history.html b/src/hi/apps/control/templates/control/modals/controller_history.html
index 9cb34664..3f552092 100644
--- a/src/hi/apps/control/templates/control/modals/controller_history.html
+++ b/src/hi/apps/control/templates/control/modals/controller_history.html
@@ -6,8 +6,9 @@
{% block body %}
<h5>Controller History</h5>
-{% include "control/panes/controller_history_list.html" with controller_history_list=controller_history_list %}
-
+<div class="py-2">
+ {% include "control/panes/controller_history_list.html" with controller_history_list=controller_history_list %}
+</div>
{% include "common/panes/pagination.html" with pagination=pagination %}
{% endblock %}
diff --git a/src/hi/apps/control/templates/control/panes/controller_data_row.html b/src/hi/apps/control/templates/control/panes/controller_data_row.html
new file mode 100644
index 00000000..f7ca7c50
--- /dev/null
+++ b/src/hi/apps/control/templates/control/panes/controller_data_row.html
@@ -0,0 +1,21 @@
+{% load common_tags %}
+{% load icons %}
+<div class="row my-2">
+ <div class="col-6 align-self-center">
+ <div class="h6 text-center">
+ {{ controller_data.controller.name }}
+ </div>
+ <div class="d-flex justify-content-around mt-2">
+ <div>
+ <a href="{{ controller_data.controller_history_url }}"
+ class="btn btn-sm btn-outline-primary"
+ data-async="true">
+ {% icon "history" size="sm" %} History
+ </a>
+ </div>
+ </div>
+ </div>
+ <div class="col-6 align-self-center">
+ {% include "control/panes/controller_data.html" with controller_data=controller_data in_modal_context=True %}
+ </div>
+</div>
diff --git a/src/hi/apps/control/templates/control/panes/controller_discrete.html b/src/hi/apps/control/templates/control/panes/controller_discrete.html
index 2da3baa7..3fe5fdbf 100644
--- a/src/hi/apps/control/templates/control/panes/controller_discrete.html
+++ b/src/hi/apps/control/templates/control/panes/controller_discrete.html
@@ -10,8 +10,4 @@
</option>
{% endfor %}
</select>
- <div class="discrete-status">
- <span class="status-label">Current:</span>
- <span class="status-value">{{ controller_data.latest_sensor_response.value }}</span>
- </div>
</div>
diff --git a/src/hi/apps/control/templates/control/panes/controller_history_list.html b/src/hi/apps/control/templates/control/panes/controller_history_list.html
index bd9fe27e..2422d862 100644
--- a/src/hi/apps/control/templates/control/panes/controller_history_list.html
+++ b/src/hi/apps/control/templates/control/panes/controller_history_list.html
@@ -1,16 +1,24 @@
{% load tz %}
{% timezone USER_TIMEZONE %}
-<ul>
- {% for controller_history in controller_history_list %}
- <li>
- {{ controller_history.created_datetime|localtime }} : {{ controller_history.value }}
- </li>
- {% empty %}
- <div><em>No history.</em></div>
- {% endfor %}
- {% if show_all_link and controller_history_list %}
+<div class="table-responsive">
+ <table class="table table-striped">
+ <tbody>
+ {% for controller_history in controller_history_list %}
+ <tr>
+ <td><div class="text-center" status="{{ controller_history.value }}"> {{ controller_history.value }}</div></td>
+ <td>{{ controller_history.created_datetime|localtime }}</td>
+ </tr>
+ {% empty %}
+ <tr><td colspan="2"><div class="alert alert-info" >No history.</div></td></tr>
+ {% endfor %}
+ </tbody>
+ </table>
+</div>
+
+{% if show_all_link and controller_history_list %}
+<div>
<a href="{% url 'control_controller_history' controller_id=controller.id %}"
data-async="true">&gt;&gt; See All</a>
- {% endif %}
-</ul>
+</div>
+{% endif %}
{% endtimezone %}
diff --git a/src/hi/apps/control/transient_models.py b/src/hi/apps/control/transient_models.py
index 5a846202..f20e863a 100644
--- a/src/hi/apps/control/transient_models.py
+++ b/src/hi/apps/control/transient_models.py
@@ -1,6 +1,8 @@
from dataclasses import dataclass
from typing import List
+from django.urls import reverse
+
from hi.apps.sense.transient_models import SensorResponse
from .models import Controller
@@ -11,7 +13,20 @@ class ControllerData:
controller : Controller
latest_sensor_response : SensorResponse
error_list : List[ str ] = None
-
+
+ @property
+ def entity(self):
+ return self.controller.entity_state.entity
+
+ @property
+ def entity_state(self):
+ return self.controller.entity_state
+
+ @property
+ def controller_history_url(self):
+ return reverse( 'control_controller_history',
+ kwargs = { 'controller_id': self.controller.id })
+
@property
def css_class(self):
return self.controller.entity_state.css_class
diff --git a/src/hi/apps/entity/enums.py b/src/hi/apps/entity/enums.py
index 4bb837d3..f3b7b51b 100644
--- a/src/hi/apps/entity/enums.py
+++ b/src/hi/apps/entity/enums.py
@@ -266,9 +266,9 @@ class EntityStateType(LabeledEnum):
Template used to render a sensor's value for this state. Create the
template at the given location to define a state-specific rendering, else
it will fallback to the default template of
- "entity/panes/sensor_value_default.html"
+ "entity/panes/sensor_response_value_default.html"
"""
- return f'sense/panes/sensor_value_{self.name.lower()}.html'
+ return f'sense/panes/sensor_response_value_{self.name.lower()}.html'
def controller_template_name(self):
"""
diff --git a/src/hi/apps/entity/templates/entity/modals/entity_edit.html b/src/hi/apps/entity/templates/entity/modals/entity_edit.html
index 8cacbc81..01411864 100644
--- a/src/hi/apps/entity/templates/entity/modals/entity_edit.html
+++ b/src/hi/apps/entity/templates/entity/modals/entity_edit.html
@@ -1,10 +1,14 @@
{% extends "modals/base.html" %}
{% load icons %}
+{% load integration_tags %}
{% block modal_dialog_class %}hi-modal-dialog-700{% endblock %}
{% block title_text %}{{ entity.name }}{% endblock %}
{% block body %}
+{% if entity.integration_id %}
+<div class="text-muted text-center"><small>From: {% integration_display_name entity %}</small></div>
+{% endif %}
<!-- Root container for this attribute editing context -->
<div id="{{ attr_page_context.container_html_id }}"
class="{{ DIVID.ATTR_V2_CONTAINER_CLASS }}">
diff --git a/src/hi/apps/entity/templates/entity/modals/entity_state_history.html b/src/hi/apps/entity/templates/entity/modals/entity_state_history.html
index ae00e7c4..38b06900 100644
--- a/src/hi/apps/entity/templates/entity/modals/entity_state_history.html
+++ b/src/hi/apps/entity/templates/entity/modals/entity_state_history.html
@@ -49,5 +49,5 @@
{% block action_right %}
<a id="hi-modal-done" role="button" {% if autofocus %}autofocus="autofocus"{% endif %}
- class="btn btn-lg btn-secondary" href="#" data-dismiss="modal">DONE</a>
+ class="btn btn-secondary" href="#" data-dismiss="modal">DONE</a>
{% endblock %}
diff --git a/src/hi/apps/entity/templates/entity/modals/entity_status.html b/src/hi/apps/entity/templates/entity/modals/entity_status.html
index 4e053311..95fad37c 100644
--- a/src/hi/apps/entity/templates/entity/modals/entity_status.html
+++ b/src/hi/apps/entity/templates/entity/modals/entity_status.html
@@ -1,38 +1,36 @@
{% extends "modals/action_3.html" %}
{% load video_tags %}
+{% load integration_tags %}
+
+{% block modal_dialog_class %}hi-modal-dialog-600{% endblock %}
{% block title_text %}
-{{ entity.name }}: Status
+Status
{% endblock %}
{% block body %}
<div class="d-flex justify-content-between mb-2">
+ {% if display_only_svg_icon_item %}
<div class="display-only-svg-icon pr-2">
- {% if display_only_svg_icon_item %}
{% include "entity/panes/entity_display_only_svg_icon.html" with svg_icon_item=display_only_svg_icon_item %}
- {% endif %}
- </div>
- {% if entity_for_video.has_video_stream %}
- <div>
- <a href="{% url 'console_entity_video_stream_dispatch' entity_id=entity_for_video.id %}"
- data-entity-id="{{ entity_for_video.id }}"
- data-async="#main-content"
- class="btn btn-sm btn-outline-primary"
- role="button">
- View Stream
- </a>
</div>
{% endif %}
+ <div class="text-center">
+ <div class="h4 mb-0">{{ entity.name }}</div>
+ {% if entity.integration_id %}
+ <div class="text-muted"><small>From: {% integration_display_name entity %}</small></div>
+ {% endif %}
+ </div>
<div>
<div class="h5 text-muted">{{ entity.entity_type.label }}</div>
</div>
</div>
-{% if entity_for_video.has_video_stream %}
-{% include "console/panes/entity_video_stream.html" with entity=entity_for_video %}
-{% endif %}
+<div>
+ {% include "console/panes/entity_video_stream_w_link.html" with entity=entity_for_video %}
+</div>
-{% include "entity/panes/entity_state_status_card.html" with entity_state_status_data_list=entity_state_status_data_list %}
+{% include "entity/panes/entity_state_status_list.html" with entity_state_status_data_list=entity_state_status_data_list in_modal_context=True %}
{% endblock %}
{% block action_left %}
@@ -44,7 +42,7 @@
{% endblock %}
{% block action_center %}
-<a class="btn btn-primary"
+<a class="btn btn-outline-primary"
href="{% url 'entity_state_history' entity_id=entity.id %}"
data-async="modal">
HISTORY
@@ -53,5 +51,5 @@
{% block action_right %}
<a id="hi-modal-done" role="button" {% if autofocus %}autofocus="autofocus"{% endif %}
- class="btn btn-lg btn-secondary" href="#" data-dismiss="modal">DONE</a>
+ class="btn btn-primary" href="#" data-dismiss="modal">DONE</a>
{% endblock %}
diff --git a/src/hi/apps/entity/templates/entity/panes/entity_state_status_card.html b/src/hi/apps/entity/templates/entity/panes/entity_state_status_card.html
deleted file mode 100644
index 383b421b..00000000
--- a/src/hi/apps/entity/templates/entity/panes/entity_state_status_card.html
+++ /dev/null
@@ -1,42 +0,0 @@
-{% load icons %}
-<div>
- {% for entity_state_status_data in entity_state_status_data_list %}
- <div class="d-flex justify-content-start py-1">
- <div class="align-self-center text-center pr-3" style="min-width: 10rem">
-
- {% if entity_state_status_data.controller_data_list %}
-
- {% for controller_data in entity_state_status_data.controller_data_list %}
- {% include "control/panes/controller_data.html" with controller_data=controller_data in_modal_context=True %}
- {% endfor %}
-
- {% else %}
-
- {% with sensor_response=entity_state_status_data.latest_sensor_response %}
- {% if sensor_response %}
- {% include "sense/panes/sensor_response.html" with sensor_response=sensor_response %}
- {% else %}
- <div><em>No sensors or controllers.</em></div>
- {% endif %}
- {% endwith %}
-
- {% endif %}
- </div>
- <div class="align-self-center">
- {{ entity_state_status_data.entity_state.name }}
- </div>
- <div class="align-self-center ml-auto">
- {% with sensor_response=entity_state_status_data.latest_sensor_response %}
- {% if sensor_response and sensor_response.sensor.provides_video_stream %}
- <small>
- <a href="{% url 'console_entity_video_sensor_history' entity_id=sensor_response.sensor.entity_state.entity.id sensor_id=sensor_response.sensor.id %}"
- data-async="true" class="text-muted">
- {% icon "video" size="sm" css_class="hi-icon-left" %}Browse History
- </a>
- </small>
- {% endif %}
- {% endwith %}
- </div>
- </div>
- {% endfor %}
-</div>
diff --git a/src/hi/apps/entity/templates/entity/panes/entity_state_status_list.html b/src/hi/apps/entity/templates/entity/panes/entity_state_status_list.html
new file mode 100644
index 00000000..64d7fb78
--- /dev/null
+++ b/src/hi/apps/entity/templates/entity/panes/entity_state_status_list.html
@@ -0,0 +1,7 @@
+<div>
+ {% for entity_state_status_data in entity_state_status_data_list %}
+ <div class="my-2">
+ {% include "entity/panes/entity_state_status_row.html" with entity_state_status_data=entity_state_status_data %}
+ </div>
+ {% endfor %}
+</div>
diff --git a/src/hi/apps/entity/templates/entity/panes/entity_state_status_row.html b/src/hi/apps/entity/templates/entity/panes/entity_state_status_row.html
new file mode 100644
index 00000000..6ee5d3f4
--- /dev/null
+++ b/src/hi/apps/entity/templates/entity/panes/entity_state_status_row.html
@@ -0,0 +1,19 @@
+{% load icons %}
+{% with sensor_response=entity_state_status_data.latest_sensor_response %}
+<div class="card">
+ <div class="card-body">
+ {% if entity_state_status_data.controller_data_list %}
+ {% for controller_data in entity_state_status_data.controller_data_list %}
+ {% include "control/panes/controller_data_row.html" with controller_data=controller_data %}
+ {% endfor %}
+
+ {% elif entity_state_status_data.sensor_response_list %}
+ {% include "sense/panes/sensor_response_status_row.html" with sensor_response=entity_state_status_data.latest_sensor_response %}
+
+ {% else %}
+ <div class="alert alert-info">No sensors or controllers defined.</div>
+ {% endif %}
+
+ </div>
+</div>
+{% endwith %}
diff --git a/src/hi/apps/entity/templates/entity/panes/entity_status_card.html b/src/hi/apps/entity/templates/entity/panes/entity_status_card.html
deleted file mode 100644
index 99f25f5c..00000000
--- a/src/hi/apps/entity/templates/entity/panes/entity_status_card.html
+++ /dev/null
@@ -1,6 +0,0 @@
-<div>
- {% include "entity/panes/entity_status_title.html" with entity_status_data=entity_status_data %}
- <div>
- {% include "entity/panes/entity_state_status_card.html" with entity_state_status_data_list=entity_status_data.entity_state_status_data_list %}
- </div>
-</div>
diff --git a/src/hi/apps/entity/templates/entity/panes/entity_status_row.html b/src/hi/apps/entity/templates/entity/panes/entity_status_row.html
deleted file mode 100644
index 0ef58da5..00000000
--- a/src/hi/apps/entity/templates/entity/panes/entity_status_row.html
+++ /dev/null
@@ -1,8 +0,0 @@
-<div class="row border-top my-2 py-1">
- <div class="col-3">
- {% include "entity/panes/entity_status_title.html" with entity_status_data=entity_status_data %}
- </div>
- <div class="col-9">
- {% include "entity/panes/entity_state_status_card.html" with entity_state_status_data_list=entity_status_data.entity_state_status_data_list %}
- </div>
-</div>
diff --git a/src/hi/apps/entity/templates/entity/panes/entity_status_title.html b/src/hi/apps/entity/templates/entity/panes/entity_status_title.html
deleted file mode 100644
index c5e10634..00000000
--- a/src/hi/apps/entity/templates/entity/panes/entity_status_title.html
+++ /dev/null
@@ -1,20 +0,0 @@
-{% with entity=entity_status_data.entity %}
-<div class="d-flex justify-content-start">
- <div class="display-only-svg-icon pr-2">
- {% include "entity/panes/entity_display_only_svg_icon.html" with svg_icon_item=entity_status_data.display_only_svg_icon_item %}
- </div>
- <div>
- {% if request.view_parameters.is_editing %}
- <a href="{% url 'entity_edit_mode' entity_id=entity.id %}"
- data-async="true">
- {{ entity.name }}
- </a>
- {% else %}
- <a href="{% url 'entity_edit' entity_id=entity.id %}"
- data-async="true">
- {{ entity.name }}
- </a>
- {% endif %}
- </div>
-</div>
-{% endwith %}
diff --git a/src/hi/apps/entity/tests/test_entity_manager.py b/src/hi/apps/entity/tests/test_entity_manager.py
index 7e62c064..75ef0799 100644
--- a/src/hi/apps/entity/tests/test_entity_manager.py
+++ b/src/hi/apps/entity/tests/test_entity_manager.py
@@ -384,3 +384,4 @@ class TestEntityManager(BaseTestCase):
except ImportError:
self.skipTest("Location models not available for testing")
return
+
diff --git a/src/hi/apps/entity/tests/test_enums.py b/src/hi/apps/entity/tests/test_enums.py
index 44b57c35..b38be328 100644
--- a/src/hi/apps/entity/tests/test_enums.py
+++ b/src/hi/apps/entity/tests/test_enums.py
@@ -22,7 +22,7 @@ class TestEntityStateType(BaseTestCase):
self.assertNotEqual(on_off_template, temperature_template)
# Templates should follow consistent naming pattern
- self.assertTrue(on_off_template.startswith('sense/panes/sensor_value_'))
+ self.assertTrue(on_off_template.startswith('sense/panes/sensor_response_value_'))
self.assertTrue(on_off_template.endswith('.html'))
# Controller templates should use different namespace
@@ -35,7 +35,7 @@ class TestEntityStateType(BaseTestCase):
# Complex state types should work correctly
multivalued_template = EntityStateType.MULTIVALUED.value_template_name()
- self.assertTrue(multivalued_template.startswith('sense/panes/sensor_value_'))
+ self.assertTrue(multivalued_template.startswith('sense/panes/sensor_response_value_'))
self.assertIn('multivalued', multivalued_template)
return
diff --git a/src/hi/apps/location/models.py b/src/hi/apps/location/models.py
index 24643f66..c71e8f10 100644
--- a/src/hi/apps/location/models.py
+++ b/src/hi/apps/location/models.py
@@ -31,7 +31,7 @@ class Location( models.Model, ItemTypeModelMixin ):
null = False, blank = False,
)
order_id = models.PositiveIntegerField(
- 'Order Id',
+ 'Position',
default = 0,
db_index = True,
)
@@ -163,7 +163,7 @@ class LocationView( models.Model, ItemTypeModelMixin ):
null = False, blank = False,
)
order_id = models.PositiveIntegerField(
- 'Order Id',
+ 'Position',
default = 0,
db_index = True,
)
diff --git a/src/hi/apps/monitor/enums.py b/src/hi/apps/monitor/enums.py
new file mode 100644
index 00000000..23b5d792
--- /dev/null
+++ b/src/hi/apps/monitor/enums.py
@@ -0,0 +1,21 @@
+from hi.apps.common.enums import LabeledEnum
+
+
+class EntityDisplayCategory(LabeledEnum):
+ """
+ Used for styling and layout decisions (e.g., collection templates).
+ """
+
+ PLAIN = ( 'Plain',
+ 'Entity with no states or video stream - displays name and icon only')
+ HAS_STATE = ( 'Has State',
+ 'Entity with sensor/controller states - displays state data and controls')
+ HAS_VIDEO = ( 'Has Video',
+ 'Entity with video stream - displays video player')
+
+ @classmethod
+ def default(cls):
+ return cls.PLAIN
+
+ def css_class(self) -> str:
+ return self.name.lower().replace('_', '-')
diff --git a/src/hi/apps/monitor/status_display_manager.py b/src/hi/apps/monitor/status_display_manager.py
index bf3ee745..516dbefd 100644
--- a/src/hi/apps/monitor/status_display_manager.py
+++ b/src/hi/apps/monitor/status_display_manager.py
@@ -120,7 +120,7 @@ class StatusDisplayManager( Singleton, SensorResponseMixin ):
return EntityStatusData(
entity = entity,
entity_state_status_data_list = list( entity_state_to_status_data.values() ),
- entity_for_video = entity_for_video,
+ entity_for_video = entity_for_video, # Possibly principal entity via delegation
display_only_svg_icon_item = svg_icon_item,
)
@@ -140,16 +140,26 @@ class StatusDisplayManager( Singleton, SensorResponseMixin ):
# each entity has EntityStatusData (even if there are no latest
# sensor responses).
#
+ svg_item_factory = SvgItemFactory()
entity_status_data_list = list()
for entity in entities:
+ svg_icon_item = svg_item_factory.get_display_only_svg_icon_item(
+ entity = entity,
+ )
entity_status_data = entity_to_entity_status_data.get( entity )
if not entity_status_data:
entity_status_data = EntityStatusData(
entity = entity,
- entity_state_status_data_list = list()
+ entity_state_status_data_list = list(),
+ display_only_svg_icon_item = svg_icon_item,
+ # entity_for_video not looking for delegations here
)
+ else:
+ entity_status_data.display_only_svg_icon_item = svg_icon_item
+
entity_status_data_list.append( entity_status_data )
continue
+
return entity_status_data_list
def _get_entity_to_entity_status_data(
@@ -184,9 +194,14 @@ class StatusDisplayManager( Singleton, SensorResponseMixin ):
entity_status_data = EntityStatusData(
entity = entity,
entity_state_status_data_list = list()
+ # entity_for_video not looking for delegations here
+ # display_only_svg_icon_item is filled in later
)
entity_to_entity_status_data[entity] = entity_status_data
- entity_to_entity_status_data[entity].entity_state_status_data_list.append(
+ else:
+ entity_status_data = entity_to_entity_status_data[entity]
+
+ entity_status_data.entity_state_status_data_list.append(
entity_state_status_data
)
continue
diff --git a/src/hi/apps/monitor/transient_models.py b/src/hi/apps/monitor/transient_models.py
index 353be93d..88180eb5 100644
--- a/src/hi/apps/monitor/transient_models.py
+++ b/src/hi/apps/monitor/transient_models.py
@@ -6,6 +6,8 @@ from hi.apps.common.svg_models import SvgIconItem
from hi.apps.entity.models import Entity, EntityState
from hi.apps.sense.transient_models import SensorResponse
+from .enums import EntityDisplayCategory
+
@dataclass
class EntityStateStatusData:
@@ -14,7 +16,7 @@ class EntityStateStatusData:
controller_data_list : List[ ControllerData ]
@property
- def latest_sensor_response(self):
+ def latest_sensor_response(self) -> SensorResponse:
if self.sensor_response_list:
return self.sensor_response_list[0]
return None
@@ -26,9 +28,9 @@ class EntityStatusData:
entity_state_status_data_list : List[ EntityStateStatusData ]
entity_for_video : Entity = None
display_only_svg_icon_item : SvgIconItem = None
-
+
def __post_init__(self):
- if not self.entity_for_video:
+ if not self.entity_for_video and self.entity.has_video_stream:
self.entity_for_video = self.entity
return
@@ -38,7 +40,15 @@ class EntityStatusData:
'entity_state_status_data_list': self.entity_state_status_data_list,
'entity_for_video': self.entity_for_video,
'display_only_svg_icon_item': self.display_only_svg_icon_item,
+ 'display_category': self.display_category,
}
return context
-
+ @property
+ def display_category( self ) -> EntityDisplayCategory:
+ if self.entity_for_video:
+ return EntityDisplayCategory.HAS_VIDEO
+ if len( self.entity_state_status_data_list ) > 0:
+ return EntityDisplayCategory.HAS_STATE
+ return EntityDisplayCategory.PLAIN
+
diff --git a/src/hi/apps/sense/models.py b/src/hi/apps/sense/models.py
index dfc63447..d230f040 100644
--- a/src/hi/apps/sense/models.py
+++ b/src/hi/apps/sense/models.py
@@ -1,6 +1,7 @@
import json
from django.db import models
+from django.urls import reverse
from hi.apps.entity.models import EntityState
@@ -139,6 +140,10 @@ class SensorHistory(models.Model):
return json.loads( self.details )
return dict()
+ @property
+ def has_details(self):
+ return bool( self.detail )
+
@property
def correlation_role(self) -> CorrelationRole:
if self.correlation_role_str:
@@ -149,3 +154,30 @@ class SensorHistory(models.Model):
def correlation_role(self, correlation_role: CorrelationRole):
self.correlation_role_str = str(correlation_role) if correlation_role else None
+ @property
+ def entity(self):
+ return self.sensor.entity_state.entity
+
+ @property
+ def entity_state(self):
+ return self.sensor.entity_state
+
+ @property
+ def video_browse_url(self) -> str:
+ if self.has_video_stream:
+ return reverse( 'console_entity_video_sensor_history_detail',
+ kwargs = { 'entity_id': self.entity.id,
+ 'sensor_id': self.sensor.id,
+ 'sensor_history_id': self.id })
+ if self.sensor.provides_video_stream:
+ return reverse( 'console_entity_video_sensor_history',
+ kwargs = { 'entity_id': self.entity.id,
+ 'sensor_id': self.sensor.id })
+ return None
+
+ @property
+ def details_url(self) -> str:
+ if self.has_details:
+ return reverse( 'sense_sensor_history_details',
+ kwargs = { 'sensor_history_id': self.id })
+ return None
diff --git a/src/hi/apps/sense/sensor_history_manager.py b/src/hi/apps/sense/sensor_history_manager.py
index 7ee87e1f..e4436f65 100644
--- a/src/hi/apps/sense/sensor_history_manager.py
+++ b/src/hi/apps/sense/sensor_history_manager.py
@@ -40,24 +40,46 @@ class SensorHistoryManager( Singleton ):
return
async def add_to_sensor_history( self, sensor_response_list : List[ SensorResponse ] ):
+ """ Side effect: Fills in the sensor_history_id for the SensorResponse instances """
if not sensor_response_list:
return
+ # Build parallel lists to maintain the mapping between SensorResponse and SensorHistory
sensor_history_list = list()
- for sensor_response in sensor_response_list:
+ response_indices = list() # Track which responses need history
+
+ for i, sensor_response in enumerate(sensor_response_list):
if sensor_response.sensor and sensor_response.sensor.persist_history:
sensor_history_list.append( sensor_response.to_sensor_history() )
+ response_indices.append(i)
continue
- await self._bulk_create_sensor_history_async( sensor_history_list )
+ created_histories = await self._bulk_create_sensor_history_async( sensor_history_list )
+
+ # Update the sensor_history_id field in the original SensorResponse objects
+ # Safety check: Only update if we got the expected number of results
+ if created_histories and ( len(created_histories) == len(sensor_history_list) ):
+ for i, history in enumerate(created_histories):
+ response_index = response_indices[i]
+ sensor_response_list[response_index].sensor_history_id = history.id
+ continue
+ elif created_histories:
+ # Log warning if size mismatch - this shouldn't happen in normal operation
+ logger.warning(
+ f'SensorHistory bulk_create returned {len(created_histories)} objects '
+ f'but expected {len(sensor_history_list)}. sensor_history_id not populated.'
+ )
+
return
-
+
async def _bulk_create_sensor_history_async( self, sensor_history_list : List[ SensorHistory ] ):
if not sensor_history_list:
- return
- await sync_to_async( SensorHistory.objects.bulk_create,
- thread_sensitive = True)( sensor_history_list )
- return
+ return []
+
+ # bulk_create returns the list of created objects (with IDs on PostgreSQL and SQLite 3.35+)
+ created_objects = await sync_to_async( SensorHistory.objects.bulk_create,
+ thread_sensitive = True)( sensor_history_list )
+ return created_objects
def get_latest_entity_sensor_history( self,
entity : Entity,
diff --git a/src/hi/apps/sense/sensor_response_manager.py b/src/hi/apps/sense/sensor_response_manager.py
index 89f25b54..e7c2e2d5 100644
--- a/src/hi/apps/sense/sensor_response_manager.py
+++ b/src/hi/apps/sense/sensor_response_manager.py
@@ -198,6 +198,15 @@ class SensorResponseManager( Singleton, SensorHistoryMixin, EventMixin ):
self._latest_sensor_data_dirty = True
+ await self._add_sensors( sensor_response_list = sensor_response_list )
+
+ sensor_history_manager = await self.sensor_history_manager_async()
+
+ # This also has side effect of populating sensor_history_id
+ await sensor_history_manager.add_to_sensor_history(
+ sensor_response_list = sensor_response_list,
+ )
+
pipeline = self._redis_client.pipeline()
for sensor_response in sensor_response_list:
list_cache_key = self.to_sensor_response_list_cache_key( sensor_response.integration_key )
@@ -208,13 +217,6 @@ class SensorResponseManager( Singleton, SensorHistoryMixin, EventMixin ):
continue
pipeline.execute()
- await self._add_sensors( sensor_response_list = sensor_response_list )
-
- sensor_history_manager = await self.sensor_history_manager_async()
-
- await sensor_history_manager.add_to_sensor_history(
- sensor_response_list = sensor_response_list,
- )
return
def to_sensor_response_list_cache_key( self, integration_key : IntegrationKey ) -> str:
diff --git a/src/hi/apps/sense/templates/sense/modals/sensor_history.html b/src/hi/apps/sense/templates/sense/modals/sensor_history.html
index d30b3ad6..057c450e 100644
--- a/src/hi/apps/sense/templates/sense/modals/sensor_history.html
+++ b/src/hi/apps/sense/templates/sense/modals/sensor_history.html
@@ -1,13 +1,25 @@
{% extends "modals/action_done.html" %}
+{% load icons %}
{% block title_text %}
{{ sensor.name }}
{% endblock %}
{% block body %}
-<h5>Sensor History</h5>
-{% include "sense/panes/sensor_history_list.html" with sensor_history_list=sensor_history_list %}
-
+<div class="d-flex justify-content-between">
+ <h5>Sensor History</h5>
+ <div>
+ {% if sensor.provides_video_stream %}
+ <a href="{% url 'console_entity_video_sensor_history' entity_id=sensor.entity_state.entity.id sensor_id=sensor.id %}"
+ data-async="true" class="btn btn-sm btn-outline-primary">
+ {% icon "video" size="sm" css_class="hi-icon-left" %}Browse Videos
+ </a>
+ {% endif %}
+ </div>
+</div>
+<div class="py-2" >
+ {% include "sense/panes/sensor_history_list.html" with sensor_history_list=sensor_history_list %}
+</div>
{% include "common/panes/pagination.html" with pagination=pagination %}
{% endblock %}
diff --git a/src/hi/apps/sense/templates/sense/panes/sensor_history_list.html b/src/hi/apps/sense/templates/sense/panes/sensor_history_list.html
index 6b6fc6e7..a5be37ca 100644
--- a/src/hi/apps/sense/templates/sense/panes/sensor_history_list.html
+++ b/src/hi/apps/sense/templates/sense/panes/sensor_history_list.html
@@ -1,39 +1,55 @@
{% load tz %}
{% timezone USER_TIMEZONE %}
-<ul>
- {% for sensor_history in sensor_history_list %}
- <li>
- {% if sensor_history.details %}
- {% if sensor.provides_video_stream and sensor_history.has_video_stream %}
- {# Redirect video streams to enhanced video browser #}
- <a href="{% url 'console_entity_video_sensor_history_detail' entity_id=sensor.entity_state.entity.id sensor_id=sensor.id sensor_history_id=sensor_history.id %}"
- data-async="true">
- {{ sensor_history.response_datetime|localtime }} : {{ sensor_history.value }}
- </a>
+<div class="table-responsive">
+ <table class="table table-striped">
+ <tbody>
+ {% for sensor_history in sensor_history_list %}
+ {% if sensor_history.has_video_stream %}
+ <tr>
+ <td>
+ <a href="{{ sensor_history.video_browse_url }}" data-async="true">
+ <div class="text-center" status="{{ sensor_history.value }}">
+ {{ sensor_history.value }}
+ </div>
+ </a>
+ </td>
+ <td>{{ sensor_history.response_datetime|localtime }}</td>
+ </tr>
+ </a>
+ {% elif sensor_history.details %}
+ <tr>
+ <td>
+ <a href="{{ sensor_history.details_url }}" data-async="true">
+ <div class="text-center" status="{{ sensor_history.value }}">
+ {{ sensor_history.value }}
+ </div>
+ </a>
+ </td>
+ <td>{{ sensor_history.response_datetime|localtime }}</td>
+ </tr>
{% else %}
- {# Use existing sensor history details modal for non-video sensors #}
- <a href="{% url 'sense_sensor_history_details' sensor_history_id=sensor_history.id %}"
- data-async="true">
- {{ sensor_history.response_datetime|localtime }} : {{ sensor_history.value }}
- </a>
+ <tr>
+ <td><div class="text-center" status="{{ sensor_history.value }}"> {{ sensor_history.value }}</div></td>
+ <td>{{ sensor_history.response_datetime|localtime }}</td>
+ </tr>
{% endif %}
- {% else %}
- {{ sensor_history.response_datetime|localtime }} : {{ sensor_history.value }}
- {% endif %}
- </li>
- {% empty %}
- <div><em>No history.</em></div>
- {% endfor %}
- {% if show_all_link and sensor_history_list %}
- {% if sensor.provides_video_stream %}
- {# Redirect to enhanced video browser for video sensors #}
- <a href="{% url 'console_entity_video_sensor_history' entity_id=sensor.entity_state.entity.id sensor_id=sensor.id %}"
- data-async="true">&gt;&gt; See All</a>
- {% else %}
- {# Use existing sensor history modal for non-video sensors #}
- <a href="{% url 'sense_sensor_history' sensor_id=sensor.id %}"
- data-async="true">&gt;&gt; See All</a>
- {% endif %}
+ {% empty %}
+ <tr><td colspan="2"><div class="alert alert-info" >No history.</div></td></tr>
+ {% endfor %}
+ </tbody>
+ </table>
+</div>
+
+{% if show_all_link and sensor_history_list %}
+<div>
+ {% if sensor.provides_video_stream %}
+ <a href="{% url 'console_entity_video_sensor_history' entity_id=sensor.entity_state.entity.id sensor_id=sensor.id %}"
+ data-async="true">&gt;&gt; See All</a>
+ {% else %}
+ {# Use existing sensor history modal for non-video sensors #}
+ <a href="{% url 'sense_sensor_history' sensor_id=sensor.id %}"
+ data-async="true">&gt;&gt; See All</a>
{% endif %}
-</ul>
-{% endtimezone %}
\ No newline at end of file
+</div>
+{% endif %}
+{% endtimezone %}
diff --git a/src/hi/apps/sense/templates/sense/panes/sensor_response.html b/src/hi/apps/sense/templates/sense/panes/sensor_response.html
deleted file mode 100644
index 05a9594a..00000000
--- a/src/hi/apps/sense/templates/sense/panes/sensor_response.html
+++ /dev/null
@@ -1,4 +0,0 @@
-{% load common_tags %}
-<div class="{{ sensor_response.css_class }}">
- {% include_with_fallback sensor_response.sensor.entity_state.entity_state_type.value_template_name "sense/panes/sensor_value_default.html" %}
-</div>
diff --git a/src/hi/apps/sense/templates/sense/panes/sensor_response_status_row.html b/src/hi/apps/sense/templates/sense/panes/sensor_response_status_row.html
new file mode 100644
index 00000000..2e51e5bc
--- /dev/null
+++ b/src/hi/apps/sense/templates/sense/panes/sensor_response_status_row.html
@@ -0,0 +1,43 @@
+{% load common_tags %}
+{% load icons %}
+<div class="row">
+ <div class="col-6 align-self-center">
+ <div class="h6 text-center">
+ {{ sensor_response.sensor.name }}
+ </div>
+ <div class="d-flex justify-content-around mt-2">
+ {% if sensor_response.has_video_stream %}
+ <div>
+ <a href="{{ sensor_response.video_browse_url }}"
+ class="btn btn-sm btn-outline-primary"
+ data-async="true">
+ {% icon "video" size="sm" %} Video
+ </a>
+ </div>
+ {% endif %}
+ {% if sensor_response.sensor_history_id and sensor_response.has_details %}
+ <div>
+ <a href="{{ sensor_response.details_url }}"
+ class="btn btn-sm btn-outline-primary"
+ data-async="true">
+ {% icon "info-circle" size="sm" %} Details
+ </a>
+ </div>
+ {% endif %}
+ <div>
+ <a href="{{ sensor_response.sensor_history_url }}"
+ class="btn btn-sm btn-outline-primary"
+ data-async="true">
+ {% icon "history" size="sm" %} History
+ </a>
+ </div>
+ </div>
+ </div>
+ <div class="col-6 align-self-center">
+ <a href="{{ sensor_response.click_url }}" title="See details">
+ <div class="{{ sensor_response.css_class }}">
+ {% include_with_fallback sensor_response.sensor.entity_state.entity_state_type.value_template_name "sense/panes/sensor_response_value_default.html" %}
+ </div>
+ </a>
+ </div>
+</div>
diff --git a/src/hi/apps/sense/templates/sense/panes/sensor_response_value_default.html b/src/hi/apps/sense/templates/sense/panes/sensor_response_value_default.html
new file mode 100644
index 00000000..a449190f
--- /dev/null
+++ b/src/hi/apps/sense/templates/sense/panes/sensor_response_value_default.html
@@ -0,0 +1 @@
+<div class="text-center px-2" status="{{ sensor_response.value }}">{{ sensor_response.value }}</div>
diff --git a/src/hi/apps/sense/templates/sense/panes/sensor_value_video_stream.html b/src/hi/apps/sense/templates/sense/panes/sensor_response_value_video_stream.html
similarity index 100%
rename from src/hi/apps/sense/templates/sense/panes/sensor_value_video_stream.html
rename to src/hi/apps/sense/templates/sense/panes/sensor_response_value_video_stream.html
diff --git a/src/hi/apps/sense/templates/sense/panes/sensor_value_default.html b/src/hi/apps/sense/templates/sense/panes/sensor_value_default.html
deleted file mode 100644
index 869f84f1..00000000
--- a/src/hi/apps/sense/templates/sense/panes/sensor_value_default.html
+++ /dev/null
@@ -1 +0,0 @@
-<div class="px-2" status="{{ sensor_response.value }}">{{ sensor_response.value }}</div>
diff --git a/src/hi/apps/sense/tests/test_sensor_history_manager.py b/src/hi/apps/sense/tests/test_sensor_history_manager.py
index 113c61ce..7a3a1217 100644
--- a/src/hi/apps/sense/tests/test_sensor_history_manager.py
+++ b/src/hi/apps/sense/tests/test_sensor_history_manager.py
@@ -151,15 +151,76 @@ class AsyncSensorHistoryManagerTestCase(AsyncTaskTestCase):
detail_attrs={'key': 'value'},
source_image_url='http://example.com/image.jpg'
)
-
+
history = response.to_sensor_history()
-
+
self.assertEqual(history.sensor, self.sensor)
self.assertEqual(len(history.value), 255) # Should be truncated
self.assertEqual(history.response_datetime, response.timestamp)
self.assertEqual(history.source_image_url, response.source_image_url)
self.assertIn('key', history.detail_attrs)
+ def test_add_sensor_history_populates_sensor_history_id(self):
+ """Test that add_to_sensor_history populates sensor_history_id in SensorResponse objects."""
+ # Create sensor with history disabled
+ sensor_no_persist = Sensor.objects.create(
+ name='No Persist Sensor',
+ entity_state=self.entity_state,
+ sensor_type_str='DEFAULT',
+ integration_id='no_persist_test',
+ integration_name='test_integration',
+ persist_history=False
+ )
+
+ async def async_test_logic():
+ # Create multiple sensor responses
+ responses = [
+ SensorResponse(
+ integration_key=self.integration_key,
+ value='value1',
+ timestamp=timezone.make_aware(datetime(2023, 1, 1, 12, 0, 0)),
+ sensor=self.sensor
+ ),
+ SensorResponse(
+ integration_key=self.integration_key,
+ value='value2',
+ timestamp=timezone.make_aware(datetime(2023, 1, 1, 12, 1, 0)),
+ sensor=self.sensor
+ ),
+ SensorResponse(
+ integration_key=IntegrationKey('no_persist_test', 'test_integration'),
+ value='value3',
+ timestamp=timezone.make_aware(datetime(2023, 1, 1, 12, 2, 0)),
+ sensor=sensor_no_persist # This sensor has persist_history=False
+ )
+ ]
+
+ # Verify sensor_history_id starts as None
+ for response in responses:
+ self.assertIsNone(response.sensor_history_id)
+
+ # Add to history
+ await self.manager.add_to_sensor_history(responses)
+
+ # Verify sensor_history_id is populated for sensors with persist_history=True
+ self.assertIsNotNone(responses[0].sensor_history_id)
+ self.assertIsNotNone(responses[1].sensor_history_id)
+ # Should remain None for sensor with persist_history=False
+ self.assertIsNone(responses[2].sensor_history_id)
+
+ # Verify the history records were actually created in the database
+ history_count = await sync_to_async(SensorHistory.objects.filter(sensor=self.sensor).count)()
+ self.assertEqual(history_count, 2)
+
+ # Verify the IDs match actual database records
+ history1 = await sync_to_async(SensorHistory.objects.get)(id=responses[0].sensor_history_id)
+ self.assertEqual(history1.value, 'value1')
+
+ history2 = await sync_to_async(SensorHistory.objects.get)(id=responses[1].sensor_history_id)
+ self.assertEqual(history2.value, 'value2')
+
+ self.run_async(async_test_logic())
+
def test_get_latest_entity_sensor_history_direct_states(self):
"""Test retrieval of sensor history for entity's direct states."""
# Create history records
diff --git a/src/hi/apps/sense/transient_models.py b/src/hi/apps/sense/transient_models.py
index ed097d2d..7c9760c3 100644
--- a/src/hi/apps/sense/transient_models.py
+++ b/src/hi/apps/sense/transient_models.py
@@ -3,6 +3,8 @@ from datetime import datetime
import json
from typing import Dict, Optional
+from django.urls import reverse
+
from hi.apps.entity.enums import EntityStateValue
from hi.integrations.transient_models import IntegrationKey
@@ -27,6 +29,18 @@ class SensorResponse:
def __str__(self):
return json.dumps( self.to_dict() )
+ @property
+ def entity(self):
+ return self.sensor.entity_state.entity
+
+ @property
+ def entity_state(self):
+ return self.sensor.entity_state
+
+ @property
+ def has_details(self):
+ return bool( self.detail_attrs )
+
@property
def css_class(self):
if not self.sensor:
@@ -35,7 +49,40 @@ class SensorResponse:
def is_on(self):
return bool( self.value == str(EntityStateValue.ON) )
+
+ @property
+ def video_browse_url(self) -> str:
+ if self.has_video_stream and self.sensor_history_id:
+ return reverse( 'console_entity_video_sensor_history_detail',
+ kwargs = { 'entity_id': self.entity.id,
+ 'sensor_id': self.sensor.id,
+ 'sensor_history_id': self.sensor_history_id })
+ if self.sensor.provides_video_stream:
+ return reverse( 'console_entity_video_sensor_history',
+ kwargs = { 'entity_id': self.entity.id,
+ 'sensor_id': self.sensor.id })
+ return None
+
+ @property
+ def details_url(self) -> str:
+ if self.has_details:
+ return reverse( 'sense_sensor_history_details',
+ kwargs = { 'sensor_history_id': self.sensor_history_id })
+ return None
+ @property
+ def sensor_history_url(self) -> str:
+ return reverse( 'sense_sensor_history',
+ kwargs = { 'sensor_id': self.sensor.id })
+
+ @property
+ def click_url(self):
+ if self.has_video_stream:
+ return self.video_browse_url
+ if self.sensor_history_id and self.has_details:
+ return self.details_url
+ return self.sensor_history_url
+
def to_dict(self):
return {
'key': str(self.integration_key),
diff --git a/src/hi/integrations/templatetags/integration_tags.py b/src/hi/integrations/templatetags/integration_tags.py
new file mode 100644
index 00000000..756ebac6
--- /dev/null
+++ b/src/hi/integrations/templatetags/integration_tags.py
@@ -0,0 +1,24 @@
+import logging
+from django import template
+
+from hi.integrations.models import IntegrationDetailsModel
+from hi.integrations.integration_manager import IntegrationManager
+
+logger = logging.getLogger(__name__)
+
+register = template.Library()
+
+
+def integration_display_name( model : IntegrationDetailsModel ) -> str:
+ if not model:
+ return None
+ integration_manager = IntegrationManager()
+ try:
+ gateway = integration_manager.get_integration_gateway( model.integration_id )
+ metadata = gateway.get_metadata()
+ return metadata.label
+ except Exception:
+ pass
+ return None
+
diff --git a/src/hi/settings/base.py b/src/hi/settings/base.py
index d7dd5e04..b0f71be8 100644
--- a/src/hi/settings/base.py
+++ b/src/hi/settings/base.py
@@ -258,7 +258,6 @@ PIPELINE = {
'js/antinode.js',
'js/autosize.min.js',
'js/main.js',
- 'js/control.js',
),
'output_filename': 'js/js_before_content.js',
},
diff --git a/src/hi/static/css/main.css b/src/hi/static/css/main.css
index bc7a7ba7..9699d1bb 100644
--- a/src/hi/static/css/main.css
+++ b/src/hi/static/css/main.css
@@ -59,8 +59,8 @@
--status-active-color: #DC3545;
--status-recent-color: #FD7E14;
--status-past-color: #FFD700;
- --status-ok-color: green;
- --status-bad-color: red;
+ --status-ok-color: #177219;
+ --status-bad-color: #a01111;
--status-idle-color: #aaaaaa;
--on-status-active-color: white;
@@ -205,7 +205,7 @@ a.clickable-card:active {
border-color: var(--primary-highlight-color) !important;
}
.bg-primary a, .bg-info a, .btn-primary a, .btn-info a {
- color: color: var(--on-primary-color);
+ color: var(--on-primary-color);
}
.bg-primary a:hover,
.bg-primary a:focus,
@@ -214,7 +214,7 @@ a.clickable-card:active {
.bg-info a:focus,
.bg-info a:active {
opacity: 0.65;
- color: color: var(--on-primary-color);
+ color: var(--on-primary-color);
}
.bg-secondary, .btn-secondary {
@@ -223,13 +223,13 @@ a.clickable-card:active {
border-color: var(--secondary-highlight-color) !important;
}
.bg-secondary a {
- color: color: var(--on-secondary-color);
+ color: var(--on-secondary-color);
}
.bg-secondary a:hover,
.bg-secondary a:focus,
.bg-secondary a:active {
opacity: 0.65;
- color: color: var(--on-secondary-color);
+ color: var(--on-secondary-color);
}
.bg-tertiary, .btn-tertiary {
@@ -238,13 +238,13 @@ a.clickable-card:active {
border-color: var(--tertiary-highlight-color) !important;
}
.bg-tertiary a {
- color: color: var(--on-tertiary-color);
+ color: var(--on-tertiary-color);
}
.bg-tertiary a:hover,
.bg-tertiary a:focus,
.bg-tertiary a:active {
opacity: 0.65;
- color: color: var(--on-tertiary-color);
+ color: var(--on-tertiary-color);
}
.bg-danger, .btn-error, .btn-danger {
@@ -253,7 +253,7 @@ a.clickable-card:active {
border-color: var(--error-highlight-color) !important;
}
.bg-danger a, .btn-error a, .btn-danger a {
- color: color: var(--on-error-color);
+ color: var(--on-error-color);
}
.bg-error a:hover,
.bg-error a:focus,
@@ -262,7 +262,7 @@ a.clickable-card:active {
.bg-danger a:focus,
.bg-danger a:active {
opacity: 0.65;
- color: color: var(--on-error-color);
+ color: var(--on-error-color);
}
.bg-muted, .btn-muted {
@@ -396,13 +396,13 @@ a.clickable-card:active {
/* Edit Mode Styling - Warm color scheme with dashed borders */
#hi-top-content[hi-edit="True"] {
background: var(--edit-mode-tertiary-bg);
- border-bottom: 3px dashed var(--edit-mode-dash-color);
+ border-bottom: 4px dashed var(--edit-mode-dash-color);
box-shadow: inset 0 -2px 8px rgba(212, 119, 94, 0.1);
}
#hi-bottom-content[hi-edit="True"] {
background: var(--edit-mode-tertiary-bg);
- border-top: 3px dashed var(--edit-mode-dash-color);
+ border-top: 4px dashed var(--edit-mode-dash-color);
box-shadow: inset 0 2px 8px rgba(212, 119, 94, 0.1);
}
@@ -415,7 +415,7 @@ a.clickable-card:active {
/* Side panel styling in edit mode */
.hi-screen[hi-edit="True"] #hi-side-content {
background: var(--edit-mode-primary-bg);
- border-left: 3px dashed var(--edit-mode-dash-color);
+ border-left: 4px dashed var(--edit-mode-dash-color);
}
.hi-screen {
@@ -1588,6 +1588,334 @@ g[hover] {
min-width: 0; /* Allow text truncation if needed */
}
+/* ================================= */
+/* Collection Grid Layout */
+/* ================================= */
+
+.collection-grid {
+ display: grid;
+ gap: 15px;
+ margin-bottom: 1rem;
+}
+
+/* Grid responsive layouts */
+.grid-1-item {
+ grid-template-columns: 1fr 2fr;
+}
+
+.grid-2-items {
+ grid-template-columns: 1fr 1fr;
+}
+
+.grid-3-plus-items {
+ grid-template-columns: 1fr 1fr 1fr;
+}
+
+/* Card hover effects for better interaction */
+.collection-grid .card {
+ transition: all 0.2s ease;
+ border: 1px solid var(--line-color);
+ background: var(--white);
+}
+
+.collection-grid .card:hover {
+ transform: translateY(-2px);
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
+ border-color: var(--primary-color);
+}
+
+/* Enhanced typography and spacing in cards */
+.collection-grid .card-body {
+ padding: 1rem !important;
+}
+
+/* Grid card entity title styling */
+.collection-grid .card .entity-status-title {
+ margin-bottom: 0.75rem;
+ font-weight: 600;
+}
+
+.collection-grid .card .display-only-svg-icon {
+ width: 2.5rem;
+ height: 2.5rem;
+}
+
+/* Ensure consistent card heights in grid */
+.collection-grid .card {
+ height: 100%;
+ display: flex;
+ flex-direction: column;
+}
+
+.collection-grid .card-body {
+ flex: 1;
+ display: flex;
+ flex-direction: column;
+}
+
+/* ================================= */
+/* Collection List Layout */
+/* ================================= */
+
+.collection-list {
+ display: flex;
+ flex-direction: column;
+}
+
+.entity-row {
+ display: flex;
+ align-items: flex-start;
+ border-top: 1px solid var(--line-color);
+ padding: 15px 0;
+ transition: background-color 0.2s ease;
+}
+
+.entity-row:hover {
+ background-color: var(--muted-bg-light);
+}
+
+.entity-row:first-child {
+ border-top: none;
+}
+
+/* Entity type-specific flex behavior for responsive layout */
+.entity-row .entity-title-section {
+ display: flex;
+ align-items: flex-start;
+ margin-right: 15px;
+ min-width: 0; /* Allow shrinking */
+ flex: 0 0 200px; /* Default fixed width for consistent alignment */
+}
+
+.entity-row .entity-content-section {
+ flex: 1;
+ min-width: 0; /* Allow shrinking */
+}
+
+/* User-defined entities get more flexible title space to reduce blank space */
+.entity-row.user-defined .entity-title-section {
+ flex: 1;
+ max-width: none;
+}
+
+/* Sensor/controller entities maintain fixed title width for tabular consistency */
+.entity-row.sensor-controller .entity-title-section {
+ flex: 0 0 200px;
+}
+
+/* Video stream entities maintain fixed title width for tabular consistency */
+.entity-row.video-stream .entity-title-section {
+ flex: 0 0 200px;
+}
+
+/* Enhanced styling for entity title display in list view */
+.entity-row .entity-title-section a {
+ font-weight: 500;
+ color: var(--black);
+ text-decoration: none;
+}
+
+.entity-row .entity-title-section a:hover {
+ color: var(--primary-color);
+ text-decoration: none;
+}
+
+/* Better spacing and alignment for entity state content */
+.entity-row .entity-content-section .d-flex {
+ align-items: center;
+ flex-wrap: wrap;
+ gap: 0.5rem;
+}
+
+.entity-row .entity-content-section .text-center {
+ margin-right: 1rem;
+}
+
+/* Improve typography hierarchy in list view */
+.collection-list .entity-row h6,
+.collection-list .entity-row .h6 {
+ margin-bottom: 0.25rem;
+ font-weight: 600;
+ color: var(--black);
+}
+
+.collection-list .entity-row small {
+ color: var(--muted-color);
+ font-size: 0.85rem;
+}
+
+/* Responsive adjustments for smaller screens */
+@media (max-width: 768px) {
+ .grid-3-plus-items {
+ grid-template-columns: 1fr 1fr;
+ }
+
+ .grid-1-item {
+ grid-template-columns: 1fr;
+ }
+
+ .entity-row.sensor-controller .entity-title-section,
+ .entity-row.video-stream .entity-title-section {
+ flex: 0 0 150px;
+ }
+}
+
+@media (max-width: 576px) {
+ .grid-2-items,
+ .grid-3-plus-items {
+ grid-template-columns: 1fr;
+ }
+
+ .collection-grid {
+ gap: 10px;
+ }
+
+ .entity-row {
+ flex-direction: column;
+ align-items: stretch;
+ }
+
+ .entity-row .entity-title-section {
+ margin-right: 0;
+ margin-bottom: 10px;
+ flex: none;
+ }
+}
+
+/* ================================= */
+/* Drag and Drop Styling */
+/* ================================= */
+
+/* Draggable items in collection view */
+.collection-grid .draggable {
+ cursor: grab;
+}
+
+.collection-grid .draggable:active {
+ cursor: grabbing;
+}
+
+.collection-list .draggable {
+ cursor: grab;
+}
+
+.collection-list .draggable:active {
+ cursor: grabbing;
+}
+
+/* Visual feedback during drag operations */
+.collection-grid .draggable.ui-sortable-helper {
+ transform: rotate(2deg) scale(1.05);
+ z-index: 1000;
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
+}
+
+.collection-list .draggable.ui-sortable-helper {
+ background: var(--white);
+ border: 2px solid var(--primary-color);
+ border-radius: 4px;
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
+}
+
+/* Drop zone styling */
+.collection-grid .ui-sortable-placeholder {
+ border: 2px dashed var(--primary-color);
+ background: var(--info-bg-light);
+ border-radius: 8px;
+ min-height: 120px;
+}
+
+.collection-list .ui-sortable-placeholder {
+ border: 2px dashed var(--primary-color);
+ background: var(--info-bg-light);
+ min-height: 60px;
+ border-radius: 4px;
+ margin: 5px 0;
+}
+
+/* List view card styling for thin rows */
+.collection-list .card {
+ margin-bottom: 0.75rem;
+ transition: all 0.2s ease;
+ border: 1px solid var(--line-color);
+}
+
+.collection-list .card:hover {
+ transform: translateY(-1px);
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
+ border-color: var(--primary-color);
+}
+
+.collection-list .card-body {
+ padding: 0.75rem !important;
+}
+
+.collection-list .entity-title-section {
+ min-width: 200px;
+}
+
+/* ================================= */
+/* Entity Display Category Styling */
+/* ================================= */
+
+/* Entity category-specific styling for visual distinction */
+.entity-item.plain .card {
+ border-left: 3px solid var(--muted-color);
+}
+
+.entity-item.has-state .card {
+ border-left: 3px solid var(--primary-color);
+}
+
+.entity-item.has-video .card {
+ border-left: 3px solid var(--secondary-color);
+}
+
+/* List view category styling - solid borders on cards */
+.entity-row.plain .card {
+ border-left: 3px solid var(--muted-color);
+}
+
+.entity-row.has-state .card {
+ border-left: 3px solid var(--primary-color);
+}
+
+.entity-row.has-video .card {
+ border-left: 3px solid var(--secondary-color);
+}
+
+/* Enhanced grid card styling per category */
+.collection-grid .entity-item.plain .card:hover {
+ border-left-color: var(--muted-color);
+ border-left-width: 4px;
+}
+
+.collection-grid .entity-item.has-state .card:hover {
+ border-left-color: var(--primary-color);
+ border-left-width: 4px;
+}
+
+.collection-grid .entity-item.has-video .card:hover {
+ border-left-color: var(--secondary-color);
+ border-left-width: 4px;
+}
+
+/* List view entity category hover styles */
+.collection-list .entity-row.plain .card:hover {
+ border-left-color: var(--muted-color);
+ border-left-width: 4px;
+}
+
+.collection-list .entity-row.has-state .card:hover {
+ border-left-color: var(--primary-color);
+ border-left-width: 4px;
+}
+
+.collection-list .entity-row.has-video .card:hover {
+ border-left-color: var(--secondary-color);
+ border-left-width: 4px;
+}
+
/* Sidebar form styling for narrow edit panels */
.sidebar-form-field {
margin-bottom: 1rem;
diff --git a/src/hi/static/img/hi-inverse-icon-196x196.png b/src/hi/static/img/hi-inverse-icon-196x196.png
new file mode 100644
index 00000000..d033bee7
Binary files /dev/null and b/src/hi/static/img/hi-inverse-icon-196x196.png differ
diff --git a/src/hi/static/js/control.js b/src/hi/static/js/control.js
deleted file mode 100644
index 5d32f222..00000000
--- a/src/hi/static/js/control.js
+++ /dev/null
@@ -1,57 +0,0 @@
-// Control module for all controller types
-// Uses jQuery event delegation for dynamically loaded content
-
-$(document).ready(function() {
-
- // Event delegation for on/off switch status update
- $('body').on('change', '.switch-input', function() {
- var $switch = $(this);
- var $statusText = $switch.closest('.on-off-control').find('.status-text');
- var isChecked = $switch.is(':checked');
- $statusText.text(isChecked ? 'On' : 'Off');
- });
-
- // Event delegation for discrete select status update
- $('body').on('change', '.discrete-select', function() {
- var $select = $(this);
- var value = $select.val();
- var $statusValue = $select.closest('.discrete-control').find('.status-value');
- $statusValue.text(value);
- });
-
- // Event delegation for brightness slider input (real-time display update)
- $('body').on('input', '.brightness-slider', function() {
- var $slider = $(this);
- var value = $slider.val();
- var $display = $slider.closest('.brightness-control').find('.brightness-value');
- $display.text(value + '%');
- });
-
- // Event delegation for brightness quick-set buttons
- $('body').on('click', '.brightness-btn', function() {
- var $button = $(this);
- var value = $button.data('value');
- var $control = $button.closest('.brightness-control');
- var $slider = $control.find('.brightness-slider');
- var $display = $control.find('.brightness-value');
-
- // Update slider value and display
- $slider.val(value);
- $display.text(value + '%');
-
- // Trigger the change event to submit form via existing onchange-async handler
- $slider.trigger('change');
- });
-
-});
-
-// Alternative implementation for manual form submission if needed
-// (The existing antinode.js onchange-async handler should handle this automatically)
-function setBrightness(controllerId, value) {
- var $slider = $('[data-controller-id="' + controllerId + '"]');
- var $display = $slider.closest('.brightness-control').find('.brightness-value');
-
- $slider.val(value);
- $display.text(value + '%');
- $slider.trigger('change');
-}
\ No newline at end of file
diff --git a/src/hi/templates/modals/action_2_with_cancel.html b/src/hi/templates/modals/action_2_with_cancel.html
index 41845443..421297f7 100644
--- a/src/hi/templates/modals/action_2_with_cancel.html
+++ b/src/hi/templates/modals/action_2_with_cancel.html
@@ -2,5 +2,5 @@
{% block action_left %}
<a id="hi-modal-cancel" role="button" {% if autofocus %}autofocus="autofocus"{% endif %}
- class="btn btn-lg btn-tertiary" href="#" data-dismiss="modal">CANCEL</a>
+ class="btn btn-tertiary" href="#" data-dismiss="modal">CANCEL</a>
{% endblock %}
diff --git a/src/hi/templates/modals/action_done.html b/src/hi/templates/modals/action_done.html
index fa14aa0b..484b0798 100644
--- a/src/hi/templates/modals/action_done.html
+++ b/src/hi/templates/modals/action_done.html
@@ -2,5 +2,5 @@
{% block action_center %}
<a id="hi-modal-done" role="button" {% if autofocus %}autofocus="autofocus"{% endif %}
- class="btn btn-lg btn-secondary" href="#" data-dismiss="modal">DONE</a>
+ class="btn btn-secondary" href="#" data-dismiss="modal">DONE</a>
{% endblock %}
diff --git a/src/hi/templates/modals/action_ok.html b/src/hi/templates/modals/action_ok.html
index 3a695b2e..6fae226d 100644
--- a/src/hi/templates/modals/action_ok.html
+++ b/src/hi/templates/modals/action_ok.html
@@ -2,5 +2,5 @@
{% block action_center %}
<a id="hi-modal-ok" role="button" {% if autofocus %}autofocus="autofocus"{% endif %}
- class="btn btn-lg btn-secondary" href="#" data-dismiss="modal">OK</a>
+ class="btn btn-secondary" href="#" data-dismiss="modal">OK</a>
{% endblock %}
diff --git a/src/hi/templates/modals/action_refresh.html b/src/hi/templates/modals/action_refresh.html
index f015fd41..bf3e3f23 100644
--- a/src/hi/templates/modals/action_refresh.html
+++ b/src/hi/templates/modals/action_refresh.html
@@ -2,5 +2,5 @@
{% block action_center %}
<a id="hi-modal-refresh" role="button" {% if autofocus %}autofocus="autofocus"{% endif %}
- class="btn btn-lg btn-secondary" href="#" data-dismiss="modal" onclick="window.location.reload()">OK</a>
+ class="btn btn-secondary" href="#" data-dismiss="modal" onclick="window.location.reload()">OK</a>
{% endblock %}
diff --git a/src/hi/templates/modals/action_with_cancel.html b/src/hi/templates/modals/action_with_cancel.html
index 67c4e182..0eb5f81f 100644
--- a/src/hi/templates/modals/action_with_cancel.html
+++ b/src/hi/templates/modals/action_with_cancel.html
@@ -3,7 +3,7 @@
{% block action_left %}
<a id="hi-modal-cancel" role="button" {% if autofocus %}autofocus="autofocus"{% endif %}
- class="btn btn-lg btn-tertiary" href="#" data-dismiss="modal">
+ class="btn btn-tertiary" href="#" data-dismiss="modal">
{% icon "cancel" size="sm" css_class="hi-icon-left" %}CANCEL
</a>
{% endblock %}
diff --git a/src/hi/templates/modals/base.html b/src/hi/templates/modals/base.html
index 7eec55ac..1bc5ee47 100644
--- a/src/hi/templates/modals/base.html
+++ b/src/hi/templates/modals/base.html
@@ -4,11 +4,11 @@
style="{% block modal_dialog_style %}{% endblock %}">
<div class="modal-content">
<div class="modal-title">
- <div class="row {% block header_class %}bg-secondary{% endblock %} m-0 py-2">
+ <div class="row {% block header_class %}bg-primary{% endblock %} m-0 py-2">
<div class="col-md-2 col-3 align-self-center text-center modal-title-image">
{% block title_image %}
<img class="img-fluid"
- src="{% static 'img/hi-icon-196x196.png' %}"
+ src="{% static 'img/hi-inverse-icon-196x196.png' %}"
alt="HI Logo" \>
{% endblock %}
</div>
diff --git a/src/hi/templates/modals/error_base.html b/src/hi/templates/modals/error_base.html
index a9fd0b19..b0696528 100644
--- a/src/hi/templates/modals/error_base.html
+++ b/src/hi/templates/modals/error_base.html
@@ -1,5 +1,7 @@
{% extends "modals/action_ok.html" %}
+{% block header_class %}bg-secondary{% endblock %}
+
{% block title_text %}
Error
{% endblock %}