Skip to content

Home Information - Your home, your data, organized.

Python

[Feature] Camera side panel buttons to reflect status (Issue #25) (#83)

cassandra-ai-agenta744776a9a26
diff --git a/src/hi/apps/console/templates/console/panes/camera_controls.html b/src/hi/apps/console/templates/console/panes/camera_controls.html
index 1b89dc7d..38a05f09 100644
--- a/src/hi/apps/console/templates/console/panes/camera_controls.html
+++ b/src/hi/apps/console/templates/console/panes/camera_controls.html
@@ -4,7 +4,8 @@
{% for video_stream_entity in video_stream_entity_list %}
<div class="w-50 pl-1 pb-1">
<a href="{% url 'console_sensor_video_stream' sensor_id=video_stream_entity.sensor.id %}"
- class="btn btn-primary btn-control">
+ class="btn btn-primary btn-control btn-camera {% if video_stream_entity.motion_detection_state %}{{ video_stream_entity.motion_detection_state.css_class }}{% endif %}"
+ {% if video_stream_entity.motion_detection_state %}status=""{% endif %}>
{{ video_stream_entity.name }}
</a>
</div>
diff --git a/src/hi/apps/console/tests/test_transient_models.py b/src/hi/apps/console/tests/test_transient_models.py
index 990e1475..1aa64307 100644
--- a/src/hi/apps/console/tests/test_transient_models.py
+++ b/src/hi/apps/console/tests/test_transient_models.py
@@ -2,6 +2,7 @@ import logging
from unittest.mock import Mock
from hi.apps.console.transient_models import VideoStreamEntity
+from hi.apps.entity.enums import EntityStateType
from hi.tests.base_test_case import BaseTestCase
logging.disable(logging.CRITICAL)
@@ -126,3 +127,101 @@ class TestVideoStreamEntity(BaseTestCase):
self.assertEqual(video_stream_entity.entity_state, mock_entity_state)
self.assertEqual(video_stream_entity.sensor, mock_sensor)
return
+
+ def test_motion_detection_state_with_movement_state(self):
+ """Test motion_detection_state property returns MOVEMENT state when it exists."""
+ mock_entity = Mock()
+ mock_entity_state = Mock()
+ mock_sensor = Mock()
+
+ # Create mock movement state
+ mock_movement_state = Mock()
+ mock_movement_state.entity_state_type = EntityStateType.MOVEMENT
+
+ # Create mock non-movement state
+ mock_video_state = Mock()
+ mock_video_state.entity_state_type = EntityStateType.VIDEO_STREAM
+
+ # Setup entity.states.all() to return both states
+ mock_entity.states.all.return_value = [mock_video_state, mock_movement_state]
+
+ video_stream_entity = VideoStreamEntity(
+ entity=mock_entity,
+ entity_state=mock_entity_state,
+ sensor=mock_sensor
+ )
+
+ # Should return the movement state
+ self.assertEqual(video_stream_entity.motion_detection_state, mock_movement_state)
+ return
+
+ def test_motion_detection_state_without_movement_state(self):
+ """Test motion_detection_state property returns None when no MOVEMENT state exists."""
+ mock_entity = Mock()
+ mock_entity_state = Mock()
+ mock_sensor = Mock()
+
+ # Create only non-movement states
+ mock_video_state = Mock()
+ mock_video_state.entity_state_type = EntityStateType.VIDEO_STREAM
+
+ mock_on_off_state = Mock()
+ mock_on_off_state.entity_state_type = EntityStateType.ON_OFF
+
+ # Setup entity.states.all() to return only non-movement states
+ mock_entity.states.all.return_value = [mock_video_state, mock_on_off_state]
+
+ video_stream_entity = VideoStreamEntity(
+ entity=mock_entity,
+ entity_state=mock_entity_state,
+ sensor=mock_sensor
+ )
+
+ # Should return None when no movement state exists
+ self.assertIsNone(video_stream_entity.motion_detection_state)
+ return
+
+ def test_motion_detection_state_with_multiple_movement_states(self):
+ """Test motion_detection_state property returns first MOVEMENT state when multiple exist."""
+ mock_entity = Mock()
+ mock_entity_state = Mock()
+ mock_sensor = Mock()
+
+ # Create multiple movement states
+ mock_movement_state1 = Mock()
+ mock_movement_state1.entity_state_type = EntityStateType.MOVEMENT
+
+ mock_movement_state2 = Mock()
+ mock_movement_state2.entity_state_type = EntityStateType.MOVEMENT
+
+ # Setup entity.states.all() to return multiple movement states
+ mock_entity.states.all.return_value = [mock_movement_state1, mock_movement_state2]
+
+ video_stream_entity = VideoStreamEntity(
+ entity=mock_entity,
+ entity_state=mock_entity_state,
+ sensor=mock_sensor
+ )
+
+ # Should return the first movement state
+ self.assertEqual(video_stream_entity.motion_detection_state, mock_movement_state1)
+ return
+
+ def test_motion_detection_state_with_no_states(self):
+ """Test motion_detection_state property returns None when entity has no states."""
+ mock_entity = Mock()
+ mock_entity_state = Mock()
+ mock_sensor = Mock()
+
+ # Setup entity.states.all() to return empty list
+ mock_entity.states.all.return_value = []
+
+ video_stream_entity = VideoStreamEntity(
+ entity=mock_entity,
+ entity_state=mock_entity_state,
+ sensor=mock_sensor
+ )
+
+ # Should return None when no states exist
+ self.assertIsNone(video_stream_entity.motion_detection_state)
+ return
diff --git a/src/hi/apps/console/transient_models.py b/src/hi/apps/console/transient_models.py
index c2d3775b..5bd90627 100644
--- a/src/hi/apps/console/transient_models.py
+++ b/src/hi/apps/console/transient_models.py
@@ -1,5 +1,7 @@
from dataclasses import dataclass
+from typing import Optional
+from hi.apps.entity.enums import EntityStateType
from hi.apps.entity.models import Entity, EntityState
from hi.apps.sense.models import Sensor
@@ -16,3 +18,14 @@ class VideoStreamEntity:
if name.lower().endswith('camera') and len(name) > len('camera'):
name = name[:-len('camera')].strip()
return name
+
+ @property
+ def motion_detection_state(self) -> Optional[EntityState]:
+ """
+ Returns the motion detection (MOVEMENT) EntityState for this camera entity if it exists.
+ Camera entities typically have a MOVEMENT state for motion detection.
+ """
+ for entity_state in self.entity.states.all():
+ if entity_state.entity_state_type == EntityStateType.MOVEMENT:
+ return entity_state
+ return None
diff --git a/src/hi/static/css/main.css b/src/hi/static/css/main.css
index 87d108e6..8d68d6da 100644
--- a/src/hi/static/css/main.css
+++ b/src/hi/static/css/main.css
@@ -40,15 +40,15 @@
--on-status-on-color: black;
/* These should match those in hi.apps.monitor.StatusStyle */
- --status-active-color: red;
- --status-recent-color: orange;
- --status-past-color: yellow;
+ --status-active-color: #DC3545;
+ --status-recent-color: #FD7E14;
+ --status-past-color: #FFD700;
--status-ok-color: green;
--status-bad-color: red;
--status-idle-color: #aaaaaa;
--on-status-active-color: white;
- --on-status-recent-color: black;
+ --on-status-recent-color: white;
--on-status-past-color: black;
--on-status-ok-color: white;
--on-status-bad-color: white;
@@ -648,3 +648,28 @@ g[hover] {
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
cursor: pointer;
}
+
+/* Camera button status styling */
+.btn-camera[status="active"] {
+ color: var(--on-status-active-color) !important;
+ background-color: var(--status-active-color) !important;
+ border-color: var(--status-active-color) !important;
+ box-shadow: 0 0 5px var(--status-active-color);
+}
+
+.btn-camera[status="recent"] {
+ color: var(--on-status-recent-color) !important;
+ background-color: var(--status-recent-color) !important;
+ border-color: var(--status-recent-color) !important;
+ box-shadow: 0 0 3px var(--status-recent-color);
+}
+
+.btn-camera[status="past"] {
+ color: var(--on-status-past-color) !important;
+ background-color: var(--status-past-color) !important;
+ border-color: var(--status-past-color) !important;
+}
+
+.btn-camera[status="idle"] {
+ /* Default button styling - no changes needed */
+}