Home Information - Your home, your data, organized.
Python
Implement AttributeValueHistory frontend UI (#105)
Tony Cf6871923c563
diff --git a/src/hi/apps/alert/templates/alert/modals/alert_details.html b/src/hi/apps/alert/templates/alert/modals/alert_details.htmlindex 633408e2..286ac731 100644--- a/src/hi/apps/alert/templates/alert/modals/alert_details.html+++ b/src/hi/apps/alert/templates/alert/modals/alert_details.html@@ -48,7 +48,7 @@<div class="card"><div class="card-header bg-primary text-white"><h6 class="mb-0">- <i class="fas fa-camera mr-2"></i>Visual Content+ <span class="mr-2">📷</span>Visual Content</h6></div><div class="card-body p-2">@@ -95,7 +95,7 @@<h6 class="mb-0"><a class="text-decoration-none" data-toggle="collapse" href="#additionalAlarms"role="button" aria-expanded="false" aria-controls="additionalAlarms">- <i class="fas fa-chevron-right mr-2"></i>Previous Alarms ({{ alert.alarm_count|add:"-1" }})+ <span class="mr-2">▶</span>Previous Alarms ({{ alert.alarm_count|add:"-1" }})</a></h6></div>diff --git a/src/hi/apps/attribute/models.py b/src/hi/apps/attribute/models.pyindex 45e678de..0c0d5a6a 100644--- a/src/hi/apps/attribute/models.py+++ b/src/hi/apps/attribute/models.py@@ -197,10 +197,14 @@ class AttributeModel(models.Model):)def _get_history_model_class(self):- """Get the corresponding history model class for this attribute type."""- # This will be implemented by each concrete subclass or use introspection- # For now, return None to avoid errors - will be implemented with concrete models- return None+ """+ Get the corresponding history model class for this attribute type.+ Must be implemented by all concrete subclasses.+ """+ raise NotImplementedError(+ f"{self.__class__.__name__} must implement _get_history_model_class() "+ "to provide history tracking support."+ )def delete( self, *args, **kwargs ):""" Deleting file from MEDIA_ROOT on best effort basis. Ignore if fails. """diff --git a/src/hi/apps/attribute/templates/attribute/modals/attribute_history.html b/src/hi/apps/attribute/templates/attribute/modals/attribute_history.htmlnew file mode 100644index 00000000..63e849eb--- /dev/null+++ b/src/hi/apps/attribute/templates/attribute/modals/attribute_history.html@@ -0,0 +1,75 @@+{% extends "modals/action_ok.html" %}+{% load humanize %}++{% block title_text %}+Attribute History: {{ attribute.name }}+{% endblock %}++{% block body %}+<div class="container-fluid">+ <div class="row mb-3">+ <div class="col-12">+ <p class="text-muted mb-2">+ <strong>Current Value:</strong>+ <span class="badge badge-primary">{{ attribute.value|default:"(empty)" }}</span>+ </p>+ </div>+ </div>++ {% if history_records %}+ <div class="row">+ <div class="col-12">+ <div class="table-responsive">+ <table class="table table-sm table-striped">+ <thead class="thead-light">+ <tr>+ <th scope="col">When</th>+ <th scope="col">Value</th>+ <th scope="col">Action</th>+ </tr>+ </thead>+ <tbody>+ {% for record in history_records %}+ <tr>+ <td class="text-nowrap">+ <small>{{ record.changed_datetime|naturaltime }}</small>+ </td>+ <td>+ <span class="badge badge-light">{{ record.value|default:"(empty)" }}</span>+ </td>+ <td>+ {% if record.value != attribute.value %}+ {% if restore_url_name %}+ <form method="POST"+ action="{% url restore_url_name attribute.pk %}"+ data-async="true"+ style="display: inline;">+ {% csrf_token %}+ <input type="hidden" name="history_id" value="{{ record.pk }}">+ <button type="submit" class="btn btn-sm btn-outline-primary">+ Restore+ </button>+ </form>+ {% endif %}+ {% else %}+ <span class="text-muted">+ <small>Current</small>+ </span>+ {% endif %}+ </td>+ </tr>+ {% endfor %}+ </tbody>+ </table>+ </div>+ </div>+ </div>+ {% else %}+ <div class="row">+ <div class="col-12 text-center text-muted">+ <p>No history available for this attribute.</p>+ </div>+ </div>+ {% endif %}+</div>+{% endblock %}\ No newline at end of filediff --git a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_boolean.html b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_boolean.htmlindex dd68ce73..a28c898f 100644--- a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_boolean.html+++ b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_boolean.html@@ -9,6 +9,16 @@{% if attribute_form.value.value %}checked="on"{% endif %}data-original-value="{% if attribute_form.value.value %}true{% else %}false{% endif %}" ><label for="{{ attribute_form.value.id_for_label }}" class="pl-2 mb-0">{{ attribute_form.name.value }}</label>+ <div class="input-group-append ml-auto">+ {% if history_url_name %}+ <a href="{% url history_url_name attribute_form.instance.pk %}"+ class="btn btn-outline-secondary btn-sm attribute-history-btn"+ data-async="modal"+ title="View attribute history">+ <span class="history-icon">⏱</span>+ </a>+ {% endif %}+ </div></div>{% if attribute_form.show_as_editable and attribute_form.instance.is_editable and attribute_form.instance.attribute_type.can_delete %}diff --git a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_enum.html b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_enum.htmlindex dfaa0466..ce9336fd 100644--- a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_enum.html+++ b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_enum.html@@ -19,6 +19,16 @@{% endfor %}</select>{% endwith %}+ <div class="input-group-append">+ {% if history_url_name %}+ <a href="{% url history_url_name attribute_form.instance.pk %}"+ class="btn btn-outline-secondary btn-sm attribute-history-btn"+ data-async="modal"+ title="View attribute history">+ <span class="history-icon">⏱</span>+ </a>+ {% endif %}+ </div></div>{% if attribute_form.show_as_editable and attribute_form.instance.is_editable and attribute_form.instance.attribute_type.can_delete %}diff --git a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_text.html b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_text.htmlindex 3f1a11b0..e5f2f4ba 100644--- a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_text.html+++ b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_text.html@@ -21,6 +21,16 @@{% else %}{% include "attribute/panes/attribute_form_field_value.html" %}{% endif %}+ <div class="input-group-append">+ {% if history_url_name %}+ <a href="{% url history_url_name attribute_form.instance.pk %}"+ class="btn btn-outline-secondary btn-sm attribute-history-btn"+ data-async="modal"+ title="View attribute history">+ <span class="history-icon">⏱</span>+ </a>+ {% endif %}+ </div></div>{% if attribute_form.show_as_editable and attribute_form.instance.is_editable and attribute_form.instance.attribute_type.can_delete %}diff --git a/src/hi/apps/attribute/views.py b/src/hi/apps/attribute/views.pynew file mode 100644index 00000000..c898fbaf--- /dev/null+++ b/src/hi/apps/attribute/views.py@@ -0,0 +1,114 @@+from django.views.generic import View++import hi.apps.common.antinode as antinode+from hi.views import page_not_found_response+from hi.hi_async_view import HiModalView+++class BaseAttributeHistoryView(HiModalView):+ """+ Abstract base view for displaying attribute history in a modal.+ Subclasses must implement get_attribute_model_class(), get_history_url_name(), and get_restore_url_name().+ """++ def get_template_name(self):+ return 'attribute/modals/attribute_history.html'++ def get_attribute_model_class(self):+ """+ Return the concrete attribute model class for this view.+ Must be implemented by subclasses.+ """+ raise NotImplementedError(+ f"{self.__class__.__name__} must implement get_attribute_model_class()"+ )++ def get_history_url_name(self):+ """+ Return the URL name for the history view.+ Must be implemented by subclasses.+ """+ raise NotImplementedError(+ f"{self.__class__.__name__} must implement get_history_url_name()"+ )++ def get_restore_url_name(self):+ """+ Return the URL name for the restore view.+ Must be implemented by subclasses.+ """+ raise NotImplementedError(+ f"{self.__class__.__name__} must implement get_restore_url_name()"+ )++ def get(self, request, attribute_id, *args, **kwargs):+ model_class = self.get_attribute_model_class()++ try:+ # Get the specific attribute using the concrete model class+ attribute = model_class.objects.get(pk=attribute_id)+ except model_class.DoesNotExist:+ return page_not_found_response(request, "Attribute not found.")++ # Get history records for this attribute+ history_model_class = attribute._get_history_model_class()+ if history_model_class:+ history_records = history_model_class.objects.filter(+ attribute=attribute+ ).order_by('-changed_datetime')[:500] # High limit for safety, pagination TBD+ else:+ history_records = []++ context = {+ 'attribute': attribute,+ 'history_records': history_records,+ 'history_url_name': self.get_history_url_name(),+ 'restore_url_name': self.get_restore_url_name(),+ }++ return self.modal_response(request, context)+++class BaseAttributeRestoreView(View):+ """+ Abstract base view for restoring attribute values from history.+ Subclasses must implement get_attribute_model_class().+ """++ def get_attribute_model_class(self):+ """+ Return the concrete attribute model class for this view.+ Must be implemented by subclasses.+ """+ raise NotImplementedError(+ f"{self.__class__.__name__} must implement get_attribute_model_class()"+ )++ def post(self, request, attribute_id, *args, **kwargs):+ model_class = self.get_attribute_model_class()++ try:+ attribute = model_class.objects.get(pk=attribute_id)+ except model_class.DoesNotExist:+ return page_not_found_response(request, "Attribute not found.")++ history_id = request.POST.get('history_id')+ if not history_id:+ return page_not_found_response(request, "History record not specified.")++ # Get the history record to restore from+ history_model_class = attribute._get_history_model_class()+ if not history_model_class:+ return page_not_found_response(request, "No history available for this attribute type.")++ try:+ history_record = history_model_class.objects.get(pk=history_id, attribute=attribute)+ except history_model_class.DoesNotExist:+ return page_not_found_response(request, "History record not found.")++ # Restore the value from the history record+ attribute.value = history_record.value+ attribute.save() # This will create a new history record++ # Return success response that triggers page reload+ return antinode.refresh_response()diff --git a/src/hi/apps/config/urls.py b/src/hi/apps/config/urls.pyindex b7500e3d..f2f6b293 100644--- a/src/hi/apps/config/urls.py+++ b/src/hi/apps/config/urls.py@@ -12,5 +12,13 @@ urlpatterns = [re_path( r'^internal$',views.ConfigInternalView.as_view(),name='config_internal' ),++ re_path( r'^attribute/history/(?P<attribute_id>\d+)$',+ views.ConfigAttributeHistoryView.as_view(),+ name='config_attribute_history'),++ re_path( r'^attribute/restore/(?P<attribute_id>\d+)$',+ views.ConfigAttributeRestoreView.as_view(),+ name='config_attribute_restore'),]diff --git a/src/hi/apps/config/views.py b/src/hi/apps/config/views.pyindex e90a6aad..6b45826c 100644--- a/src/hi/apps/config/views.py+++ b/src/hi/apps/config/views.py@@ -11,9 +11,11 @@ import hi.apps.common.antinode as antinodefrom hi.enums import ViewMode, ViewTypefrom hi.hi_grid_view import HiGridView+from hi.apps.attribute.views import BaseAttributeHistoryView, BaseAttributeRestoreViewfrom .enums import ConfigPageTypefrom .forms import SubsystemAttributeFormSet+from .models import SubsystemAttributefrom .settings_mixins import SettingsMixinlogger = logging.getLogger('__name__')@@ -98,6 +100,8 @@ class ConfigSettingsView( ConfigPageView, SettingsMixin ):return {'subsystem_attribute_formset_list': subsystem_attribute_formset_list,+ 'history_url_name': 'config_attribute_history',+ 'restore_url_name': 'config_attribute_restore',}def post( self, request, *args, **kwargs ):@@ -121,6 +125,8 @@ class ConfigSettingsView( ConfigPageView, SettingsMixin ):if not all_valid:context = {'subsystem_attribute_formset_list': subsystem_attribute_formset_list,+ 'history_url_name': 'config_attribute_history',+ 'restore_url_name': 'config_attribute_restore',}return render( request, 'config/panes/settings_form.html', context )@@ -167,3 +173,23 @@ class ConfigInternalView( View ):def get(self, request, *args, **kwargs):data = self.get_config_data()return JsonResponse( data, safe = False )+++class ConfigAttributeHistoryView(BaseAttributeHistoryView):+ """View for displaying SubsystemAttribute history in a modal."""++ def get_attribute_model_class(self):+ return SubsystemAttribute++ def get_history_url_name(self):+ return 'config_attribute_history'++ def get_restore_url_name(self):+ return 'config_attribute_restore'+++class ConfigAttributeRestoreView(BaseAttributeRestoreView):+ """View for restoring SubsystemAttribute values from history."""++ def get_attribute_model_class(self):+ return SubsystemAttributediff --git a/src/hi/apps/entity/models.py b/src/hi/apps/entity/models.pyindex 90db13f5..08e7817c 100644--- a/src/hi/apps/entity/models.py+++ b/src/hi/apps/entity/models.py@@ -120,7 +120,7 @@ class EntityAttribute( AttributeModel ):"""Return the history model class for EntityAttribute."""return EntityAttributeHistory-+class EntityState( models.Model ):"""- The (hidden) state of an entity that can be controlled and/or sensed.diff --git a/src/hi/apps/entity/tests/test_views.py b/src/hi/apps/entity/tests/test_views.pyindex 38a92b16..3bebf23c 100644--- a/src/hi/apps/entity/tests/test_views.py+++ b/src/hi/apps/entity/tests/test_views.py@@ -5,7 +5,7 @@ from django.core.files.uploadedfile import SimpleUploadedFilefrom django.urls import reversefrom hi.apps.control.controller_history_manager import ControllerHistoryManager-from hi.apps.entity.models import Entity+from hi.apps.entity.models import Entity, EntityAttributefrom hi.apps.location.models import Location, LocationViewfrom hi.apps.sense.sensor_history_manager import SensorHistoryManagerfrom hi.enums import ViewType@@ -419,3 +419,190 @@ class TestEntityDetailsView(SyncViewTestCase):# May return 500 due to view processing issues before method check# The key is that it shouldn't return 200 (success)self.assertNotEqual(response.status_code, 200)+++class TestEntityAttributeHistoryView(DualModeViewTestCase):+ """+ Tests for EntityAttributeHistoryView - displays EntityAttribute value history in a modal.+ This view shows historical changes and allows restoring previous values.+ """++ def setUp(self):+ super().setUp()+ # Create test entity+ self.entity = Entity.objects.create(+ integration_id='test.entity',+ integration_name='test_integration',+ name='Test Entity',+ entity_type_str='LIGHT'+ )+ # Create test attribute+ self.attribute = EntityAttribute.objects.create(+ entity=self.entity,+ name='brightness',+ value='100',+ attribute_type_str='TEXT'+ )++ def test_get_history_sync(self):+ """Test getting attribute history with synchronous request."""+ url = reverse('entity_attribute_history', kwargs={'attribute_id': self.attribute.id})+ response = self.client.get(url)++ self.assertSuccessResponse(response)+ self.assertHtmlResponse(response)+ self.assertTemplateRendered(response, 'attribute/modals/attribute_history.html')++ # Verify context data+ self.assertEqual(response.context['attribute'], self.attribute)+ self.assertIn('history_records', response.context)++ def test_get_history_async(self):+ """Test getting attribute history with AJAX request."""+ url = reverse('entity_attribute_history', kwargs={'attribute_id': self.attribute.id})+ response = self.async_get(url)++ self.assertSuccessResponse(response)+ self.assertJsonResponse(response)+ self.assertTemplateRendered(response, 'attribute/modals/attribute_history.html')++ @patch.object(EntityAttribute, '_get_history_model_class')+ def test_history_with_no_history_model(self, mock_get_history_model):+ """Test history view when attribute has no history model."""+ mock_get_history_model.return_value = None++ url = reverse('entity_attribute_history', kwargs={'attribute_id': self.attribute.id})+ response = self.client.get(url)++ self.assertSuccessResponse(response)+ self.assertHtmlResponse(response)++ # Should show empty history+ self.assertEqual(len(response.context['history_records']), 0)++ @patch.object(EntityAttribute, '_get_history_model_class')+ def test_history_with_records(self, mock_get_history_model):+ """Test history view with actual history records."""+ # Mock history model and records+ mock_history_model = Mock()+ mock_get_history_model.return_value = mock_history_model++ mock_record = Mock()+ mock_record.pk = 1+ mock_record.value = '75'+ mock_record.changed_datetime = Mock()++ # Create proper mock chain for queryset slicing+ mock_queryset = Mock()+ mock_queryset.__getitem__ = Mock(return_value=[mock_record])+ mock_history_model.objects.filter.return_value.order_by.return_value = mock_queryset++ url = reverse('entity_attribute_history', kwargs={'attribute_id': self.attribute.id})+ response = self.client.get(url)++ self.assertSuccessResponse(response)+ self.assertEqual(response.context['attribute'], self.attribute)+ self.assertEqual(list(response.context['history_records']), [mock_record])++ def test_nonexistent_attribute_returns_404(self):+ """Test that accessing nonexistent attribute returns 404."""+ url = reverse('entity_attribute_history', kwargs={'attribute_id': 99999})+ response = self.client.get(url)++ self.assertEqual(response.status_code, 404)++ def test_post_not_allowed(self):+ """Test that POST requests are not allowed."""+ url = reverse('entity_attribute_history', kwargs={'attribute_id': self.attribute.id})+ response = self.client.post(url)++ self.assertEqual(response.status_code, 405)+++class TestEntityAttributeRestoreView(SyncViewTestCase):+ """+ Tests for EntityAttributeRestoreView - restores EntityAttribute values from history.+ This view handles POST requests to restore previous attribute values.+ """++ def setUp(self):+ super().setUp()+ # Create test entity+ self.entity = Entity.objects.create(+ integration_id='test.entity',+ integration_name='test_integration',+ name='Test Entity',+ entity_type_str='LIGHT'+ )+ # Create test attribute+ self.attribute = EntityAttribute.objects.create(+ entity=self.entity,+ name='brightness',+ value='100',+ attribute_type_str='TEXT'+ )++ @patch.object(EntityAttribute, '_get_history_model_class')+ def test_restore_with_valid_history_record(self, mock_get_history_model):+ """Test successful restore with valid history record."""+ # Mock history model and record+ mock_history_model = Mock()+ mock_get_history_model.return_value = mock_history_model++ mock_history_record = Mock()+ mock_history_record.value = '75'+ mock_history_model.objects.get.return_value = mock_history_record++ url = reverse('entity_attribute_restore', kwargs={'attribute_id': self.attribute.id})+ response = self.client.post(url, {'history_id': '1'})++ self.assertSuccessResponse(response)+ self.assertJsonResponse(response)++ # Verify attribute was updated+ self.attribute.refresh_from_db()+ self.assertEqual(self.attribute.value, '75')++ @patch.object(EntityAttribute, '_get_history_model_class')+ def test_restore_with_no_history_model(self, mock_get_history_model):+ """Test restore when attribute has no history model."""+ mock_get_history_model.return_value = None++ url = reverse('entity_attribute_restore', kwargs={'attribute_id': self.attribute.id})+ response = self.client.post(url, {'history_id': '1'})++ self.assertEqual(response.status_code, 404)++ def test_restore_without_history_id(self):+ """Test restore request without history_id parameter."""+ url = reverse('entity_attribute_restore', kwargs={'attribute_id': self.attribute.id})+ response = self.client.post(url, {})++ self.assertEqual(response.status_code, 404)++ @patch.object(EntityAttribute, '_get_history_model_class')+ def test_restore_with_nonexistent_history_record(self, mock_get_history_model):+ """Test restore with non-existent history record."""+ mock_history_model = Mock()+ mock_get_history_model.return_value = mock_history_model+ mock_history_model.DoesNotExist = Exception+ mock_history_model.objects.get.side_effect = mock_history_model.DoesNotExist()++ url = reverse('entity_attribute_restore', kwargs={'attribute_id': self.attribute.id})+ response = self.client.post(url, {'history_id': '999'})++ self.assertEqual(response.status_code, 404)++ def test_restore_nonexistent_attribute_returns_404(self):+ """Test that restoring nonexistent attribute returns 404."""+ url = reverse('entity_attribute_restore', kwargs={'attribute_id': 99999})+ response = self.client.post(url, {'history_id': '1'})++ self.assertEqual(response.status_code, 404)++ def test_get_not_allowed(self):+ """Test that GET requests are not allowed."""+ url = reverse('entity_attribute_restore', kwargs={'attribute_id': self.attribute.id})+ response = self.client.get(url)++ self.assertEqual(response.status_code, 405)diff --git a/src/hi/apps/entity/transient_models.py b/src/hi/apps/entity/transient_models.pyindex 57ef163a..35f987e6 100644--- a/src/hi/apps/entity/transient_models.py+++ b/src/hi/apps/entity/transient_models.py@@ -79,6 +79,8 @@ class EntityEditData:'entity_form': self.entity_form,'entity_attribute_formset': self.entity_attribute_formset,'entity_attribute_upload_form': self.entity_attribute_upload_form,+ 'history_url_name': 'entity_attribute_history',+ 'restore_url_name': 'entity_attribute_restore',}diff --git a/src/hi/apps/entity/urls.py b/src/hi/apps/entity/urls.pyindex e33d0e12..dbd03d43 100644--- a/src/hi/apps/entity/urls.py+++ b/src/hi/apps/entity/urls.py@@ -21,9 +21,17 @@ urlpatterns = [views.EntityDetailsView.as_view(),name='entity_details' ),- re_path( r'^entity/attribute/upload/(?P<entity_id>\d+)$',+ re_path( r'^attribute/upload/(?P<entity_id>\d+)$',views.EntityAttributeUploadView.as_view(),name='entity_attribute_upload'),++ re_path( r'^attribute/history/(?P<attribute_id>\d+)$',+ views.EntityAttributeHistoryView.as_view(),+ name='entity_attribute_history'),++ re_path( r'^attribute/restore/(?P<attribute_id>\d+)$',+ views.EntityAttributeRestoreView.as_view(),+ name='entity_attribute_restore'),re_path( r'^edit/', include('hi.apps.entity.edit.urls' )),diff --git a/src/hi/apps/entity/views.py b/src/hi/apps/entity/views.pyindex 15e0286a..bcae5d43 100644--- a/src/hi/apps/entity/views.py+++ b/src/hi/apps/entity/views.py@@ -10,6 +10,7 @@ from hi.apps.monitor.status_display_manager import StatusDisplayManagerfrom hi.apps.sense.sensor_history_manager import SensorHistoryMixinfrom hi.hi_async_view import HiModalView, HiSideView+from hi.apps.attribute.views import BaseAttributeHistoryView, BaseAttributeRestoreViewfrom .entity_manager import EntityManagerfrom . import forms@@ -210,3 +211,23 @@ class EntityDetailsView( HiSideView, EntityViewMixin ):is_editing = request.view_parameters.is_editing,)return entity_details_data.to_template_context()+++class EntityAttributeHistoryView(BaseAttributeHistoryView):+ """View for displaying EntityAttribute history in a modal."""++ def get_attribute_model_class(self):+ return EntityAttribute++ def get_history_url_name(self):+ return 'entity_attribute_history'++ def get_restore_url_name(self):+ return 'entity_attribute_restore'+++class EntityAttributeRestoreView(BaseAttributeRestoreView):+ """View for restoring EntityAttribute values from history."""++ def get_attribute_model_class(self):+ return EntityAttributediff --git a/src/hi/apps/location/models.py b/src/hi/apps/location/models.pyindex 487bdf43..9eba327f 100644--- a/src/hi/apps/location/models.py+++ b/src/hi/apps/location/models.py@@ -129,7 +129,7 @@ class LocationAttribute( AttributeModel ):"""Return the history model class for LocationAttribute."""return LocationAttributeHistory-+class LocationView( models.Model, ItemTypeModelMixin ):location = models.ForeignKey(diff --git a/src/hi/apps/location/tests/test_transient_models.py b/src/hi/apps/location/tests/test_transient_models.pyindex 197b7e6b..53e3f92f 100644--- a/src/hi/apps/location/tests/test_transient_models.py+++ b/src/hi/apps/location/tests/test_transient_models.py@@ -47,7 +47,9 @@ class TestLocationEditData(BaseTestCase):'location','location_edit_form','location_attribute_formset',- 'location_attribute_upload_form'+ 'location_attribute_upload_form',+ 'history_url_name',+ 'restore_url_name'}self.assertEqual(set(context.keys()), expected_keys)self.assertEqual(context['location'], location)diff --git a/src/hi/apps/location/transient_models.py b/src/hi/apps/location/transient_models.pyindex 7fb48de9..34892196 100644--- a/src/hi/apps/location/transient_models.py+++ b/src/hi/apps/location/transient_models.py@@ -43,6 +43,8 @@ class LocationEditData:'location_edit_form': self.location_edit_form,'location_attribute_formset': self.location_attribute_formset,'location_attribute_upload_form': self.location_attribute_upload_form,+ 'history_url_name': 'location_attribute_history',+ 'restore_url_name': 'location_attribute_restore',}diff --git a/src/hi/apps/location/urls.py b/src/hi/apps/location/urls.pyindex d22f08c4..257a6cd7 100644--- a/src/hi/apps/location/urls.py+++ b/src/hi/apps/location/urls.py@@ -33,6 +33,14 @@ urlpatterns = [views.LocationItemDetailsView.as_view(),name='location_item_details' ),+ re_path( r'^attribute/history/(?P<attribute_id>\d+)$',+ views.LocationAttributeHistoryView.as_view(),+ name='location_attribute_history'),++ re_path( r'^attribute/restore/(?P<attribute_id>\d+)$',+ views.LocationAttributeRestoreView.as_view(),+ name='location_attribute_restore'),+re_path( r'^edit/', include('hi.apps.location.edit.urls' )),]diff --git a/src/hi/apps/location/views.py b/src/hi/apps/location/views.pyindex b22eb625..f3e5baba 100644--- a/src/hi/apps/location/views.py+++ b/src/hi/apps/location/views.py@@ -11,9 +11,10 @@ from hi.enums import ItemType, ViewTypefrom hi.exceptions import ForceSynchronousExceptionfrom hi.hi_async_view import HiSideViewfrom hi.hi_grid_view import HiGridView+from hi.apps.attribute.views import BaseAttributeHistoryView, BaseAttributeRestoreViewfrom .location_manager import LocationManager-from .models import LocationView+from .models import LocationView, LocationAttributefrom .transient_models import LocationEditData, LocationViewEditDatafrom .view_mixins import LocationViewMixin@@ -162,4 +163,23 @@ class LocationItemDetailsView( View ):return HttpResponseRedirect( redirect_url )raise BadRequest( f'Unknown item type "{item_type}".' )+++class LocationAttributeHistoryView(BaseAttributeHistoryView):+ """View for displaying LocationAttribute history in a modal."""++ def get_attribute_model_class(self):+ return LocationAttribute++ def get_history_url_name(self):+ return 'location_attribute_history'++ def get_restore_url_name(self):+ return 'location_attribute_restore'+++class LocationAttributeRestoreView(BaseAttributeRestoreView):+ """View for restoring LocationAttribute values from history."""+ def get_attribute_model_class(self):+ return LocationAttributediff --git a/src/hi/integrations/models.py b/src/hi/integrations/models.pyindex 2e01f6b0..e43485a9 100644--- a/src/hi/integrations/models.py+++ b/src/hi/integrations/models.py@@ -66,8 +66,8 @@ class IntegrationAttribute( AttributeModel ):def _get_history_model_class(self):"""Return the history model class for IntegrationAttribute."""return IntegrationAttributeHistory--++class IntegrationDetailsModel( models.Model ):"""For use in DB objects that need to be associated with an integrationdiff --git a/src/hi/integrations/urls.py b/src/hi/integrations/urls.pyindex d1f2dae8..1f9d5ce8 100644--- a/src/hi/integrations/urls.py+++ b/src/hi/integrations/urls.py@@ -26,6 +26,14 @@ urlpatterns = [re_path( r'^manage/(?P<integration_id>[\w\-]*)$',views.IntegrationManageView.as_view(),name='integrations_manage' ),++ re_path( r'^attribute/history/(?P<attribute_id>\d+)$',+ views.IntegrationAttributeHistoryView.as_view(),+ name='integration_attribute_history'),++ re_path( r'^attribute/restore/(?P<attribute_id>\d+)$',+ views.IntegrationAttributeRestoreView.as_view(),+ name='integration_attribute_restore'),]diff --git a/src/hi/integrations/views.py b/src/hi/integrations/views.pyindex dadf5512..194313fb 100644--- a/src/hi/integrations/views.py+++ b/src/hi/integrations/views.py@@ -8,9 +8,11 @@ from hi.apps.config.views import ConfigPageViewfrom hi.exceptions import ForceRedirectExceptionfrom hi.hi_async_view import HiModalView+from hi.apps.attribute.views import BaseAttributeHistoryView, BaseAttributeRestoreViewfrom .forms import IntegrationAttributeFormSetfrom .integration_manager import IntegrationManager+from .models import IntegrationAttributelogger = logging.getLogger(__name__)@@ -182,4 +184,23 @@ class IntegrationManageView( ConfigPageView ):},})return template_context+++class IntegrationAttributeHistoryView(BaseAttributeHistoryView):+ """View for displaying IntegrationAttribute history in a modal."""++ def get_attribute_model_class(self):+ return IntegrationAttribute++ def get_history_url_name(self):+ return 'integration_attribute_history'++ def get_restore_url_name(self):+ return 'integration_attribute_restore'+++class IntegrationAttributeRestoreView(BaseAttributeRestoreView):+ """View for restoring IntegrationAttribute values from history."""+ def get_attribute_model_class(self):+ return IntegrationAttributediff --git a/src/hi/services/hass/hass_manage_view_pane.py b/src/hi/services/hass/hass_manage_view_pane.pyindex c4e01855..b336ac3b 100644--- a/src/hi/services/hass/hass_manage_view_pane.py+++ b/src/hi/services/hass/hass_manage_view_pane.py@@ -21,6 +21,8 @@ class HassManageViewPane( IntegrationManageViewPane ):)return {'integration_attribute_formset': integration_attribute_formset,+ 'history_url_name': 'integration_attribute_history',+ 'restore_url_name': 'integration_attribute_restore',}diff --git a/src/hi/services/hass/views.py b/src/hi/services/hass/views.pyindex bd55958d..4d59bf57 100644--- a/src/hi/services/hass/views.py+++ b/src/hi/services/hass/views.py@@ -37,6 +37,8 @@ class HassSettingsView( View, HassMixin ):context = {'integration_attribute_formset': integration_attribute_formset,+ 'history_url_name': 'integration_attribute_history',+ 'restore_url_name': 'integration_attribute_restore',}return render( request, 'hass/panes/hass_settings.html', context )diff --git a/src/hi/services/zoneminder/views.py b/src/hi/services/zoneminder/views.pyindex 51499129..2654fe3e 100644--- a/src/hi/services/zoneminder/views.py+++ b/src/hi/services/zoneminder/views.py@@ -36,6 +36,8 @@ class ZmSettingsView( View, ZoneMinderMixin ):context = {'integration_attribute_formset': integration_attribute_formset,+ 'history_url_name': 'integration_attribute_history',+ 'restore_url_name': 'integration_attribute_restore',}return render( request, 'zoneminder/panes/zm_settings.html', context )diff --git a/src/hi/services/zoneminder/zm_manage_view_pane.py b/src/hi/services/zoneminder/zm_manage_view_pane.pyindex 3c0d5fc0..41cb462e 100644--- a/src/hi/services/zoneminder/zm_manage_view_pane.py+++ b/src/hi/services/zoneminder/zm_manage_view_pane.py@@ -21,6 +21,8 @@ class ZmManageViewPane( IntegrationManageViewPane ):)return {'integration_attribute_formset': integration_attribute_formset,+ 'history_url_name': 'integration_attribute_history',+ 'restore_url_name': 'integration_attribute_restore',}diff --git a/src/hi/static/css/main.css b/src/hi/static/css/main.cssindex 73af94ec..8e3f1fd7 100644--- a/src/hi/static/css/main.css+++ b/src/hi/static/css/main.css@@ -769,3 +769,10 @@ form[data-dirty] {border-radius: 4px;transition: background-color 0.2s ease-in-out;}++/* History icon styling - matches plus-icon pattern */+.history-icon {+ font-size: 1rem;+ color: var(--primary-color);+ padding: 0 0.25rem;+}