Files
Tony C 565e0e1882 VideoStream Architecture Refactor (#110)
* Implement VideoStream infrastructure (Phase 1)

- Add VideoStreamType enum with URL and OTHER types
- Create VideoStream dataclass with stream_type, source_url, and metadata
- Add get_entity_video_stream() and get_sensor_response_video_stream() methods to IntegrationGateway base class
- Add has_video_stream field to Entity model with migration
- Add provides_video_stream field to Sensor model with migration
- Add has_video_stream field to SensorResponse dataclass and update serialization methods

This establishes the foundational infrastructure for treating video streams as first-class domain objects rather than fake sensor values.

* Implement ZoneMinder integration updates (Phase 2)

- Add get_entity_video_stream() and get_sensor_response_video_stream() methods to ZoneMinderGateway
- Update ZM sync to set has_video_stream=True for camera entities
- Add provides_video_stream parameter to HiModelHelper.create_movement_sensor() and create_sensor()
- Update ZM sync to set provides_video_stream=True for MOVEMENT sensors
- Remove VIDEO_STREAM sensor creation entirely from ZM sync
- Update tests to reflect removal of VIDEO_STREAM sensors
- Fix linting issues with proper line break formatting

ZoneMinder camera entities now use has_video_stream flag and movement sensors provide video streams through the new VideoStream infrastructure instead of fake VIDEO_STREAM sensors.

* Remove VIDEO_STREAM EntityState completely (Phase 3)

- Remove VIDEO_STREAM from EntityStateType enum and related code
- Remove create_video_stream_sensor() method from HiModelHelper
- Remove VIDEO_STREAM from HASS converter sensor creation logic
- Update EntityStateType suppress_display_name/suppress_history to remove VIDEO_STREAM references
- Remove VIDEO_STREAM from EntityPairingManager CREATE_BY_DEFAULT_MAP
- Update ConsoleManager and EntityManager to return empty lists for video stream queries
- Replace defunct VIDEO_STREAM tests with Phase 4 placeholder tests
- Update TransientViewManager tests to expect no suggestions (will be restored in Phase 4)
- Update alert delegation tests to use MOVEMENT sensors for testing delegation logic

Phase 3 completes the removal of VIDEO_STREAM EntityState abuse. Video display functionality
will be rebuilt in Phase 4 using the new VideoStream infrastructure and integration gateway methods.

* Complete Phase 4: Update UI components and remove old VideoStream infrastructure

- Remove old SensorVideoStreamView and sensor_video_stream.html template
- Remove old console_sensor_video_stream URL pattern
- Remove VideoStreamEntity class from transient_models.py
- Update camera_controls.html template to use Entity objects directly
- Fix failing unit tests to expect proper TransientViewManager behavior
- Restore comprehensive test assertions for VideoStream infrastructure
- Clean up unused imports and linting issues
- All tests passing and linting clean

* Remove Entity.motion_detection_state circular dependency and generalize status display

- Remove motion_detection_state() method from Entity model to eliminate circular dependency
- Add CameraControlDisplayData dataclass for structured camera control information
- Implement priority-based EntityState selection in ConsoleManager with TTL caching
- Optimize database queries using prefetch_related and in-memory processing
- Update camera_controls template to use generalized status entity state approach
- Maintain backward compatibility with legacy get_video_stream_entity_list method

* Fix template reference to use camera_control_display_list instead of video_stream_entity_list

* Migrate templates to VideoStream system, eliminate image_url video dependencies

- Add sensor_response field to AlarmSourceDetails to pass SensorResponse objects to templates
- Update Event.to_alarm() to include complete SensorResponse data in alarm source details
- Enhance Alert.get_first_visual_content() to prioritize video streams over static images
- Create video template tags in console app for VideoStream URL generation
- Update all alert and sensor templates to use VideoStream system exclusively
- Add error handling for integration gateway unavailability in template rendering
- Remove template dependencies on image_url field for video content display

* Phase 2: Rename image_url to source_image_url across codebase

Refactor field naming to clarify distinction between static source images
and VideoStream URLs, addressing GitHub issue #106 Phase 2.

Changes:
- Rename SensorResponse.image_url to source_image_url
- Rename AlarmSourceDetails.image_url to source_image_url
- Create Django migration for SensorHistory.image_url to source_image_url
- Update Alert.get_first_visual_content() return dict keys
- Maintain backward compatibility in SensorResponse.from_string()
- Update all test files and references

All 1525 tests passing, confirming successful data-preserving migration.

* Phase 3: Update ZoneMinder to use static snapshots for source_image_url

Change ZoneMinder integration to populate source_image_url with static event
snapshot URLs instead of video stream URLs, completing GitHub issue #106.

Changes:
- Replace get_event_video_stream_url() with zm_event.image_url() in monitors
- Preserve video stream methods for VideoStream system integration gateway
- Static snapshot provides appropriate thumbnail for alarm display

All 1525 tests passing.

* Eliminate AlarmSourceDetails and use SensorResponse directly

Simplify alarm system by removing redundant AlarmSourceDetails wrapper and
using SensorResponse directly for all alarm source details.

Changes:
- Remove AlarmSourceDetails class from alarm.py
- Update Alarm.source_details_list to List[SensorResponse]
- Simplify Event.to_alarm() to pass SensorResponse list directly
- Update weather_alert_alarm_mapper to create SensorResponse objects
- Update Alert.get_first_visual_content() to work with SensorResponse
- Update ViewUrlUtils to access sensor through SensorResponse
- Update alarm_source_details.html template for direct SensorResponse usage
- Partial test file updates (21 tests still need fixing)

This eliminates circular dependency and removes unnecessary complexity.

* Fix all unit tests after AlarmSourceDetails elimination

Update all failing test files to use SensorResponse instead of
AlarmSourceDetails, ensuring complete test coverage.

Changes:
- Add SensorResponse and IntegrationKey imports to all test files
- Replace AlarmSourceDetails construction with SensorResponse objects
- Use synthetic integration keys for test data
- Maintain test semantics and coverage

All 1525 tests now passing with no compromised coverage.

* Fix unit test linting errors and improve code quality

- Fix undefined 'timestamp' variables in alert synthetic_data.py
- Fix indentation issues in SensorResponse constructor calls
- Remove unnecessary f-string formatting in video_tags.py
- Add missing newline at end of video_tags.py file

* A series of post-work minor refactorings.

* Removed session-specific comments and filled test gaps.

* Fixed some lingering issues with VideoStream refactor.

* Add data migration for Issue #106 VideoStream refactor and fix video delegation in status template

- Create Django data migration 0007_video_stream_data_migration.py
- Updates ZoneMinder entities and sensors for new video stream model
- Removes obsolete VIDEO_STREAM EntityStates and sensors
- Add SQL migration documentation for manual verification
- Fix StatusDisplayManager to resolve video entity for delegation
- Fix template to use resolved video entity
- Fix linting issues in test files

* Added new LabeledEnumField custom Djsngo model field for future use.

* Fixing bugs arounf getting video stream to display.

* Improved alert details modal.

* Fix linting issues: add newline and proper comment formatting
2025-08-24 18:10:52 +00:00
..