Commit Graph

82 Commits (e54a734b22cff2dc68e5f4f30eb4fa32841255a6)

Author SHA1 Message Date
Jeff Culverhouse 5973fe2444 fix: prevent UnboundLocalError when large recordings are skipped
Fixed a crash that occurred when recordings >100MB were encountered.
The store_recording_in_media function was attempting to return file_name
outside the scope where it was defined, causing an UnboundLocalError when
get_recorded_file returned None for oversized recordings.

This fix moves the return statement inside the if recording: block and
adds an explicit return None for the case when recording is skipped.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2 weeks ago
Jeff Culverhouse b02757938a fix: use consistent fallback pattern and clarify documentation
- Change protocol_version to use 'or' fallback pattern like other config values
- Update config.yaml.sample comment to clarify both quoted and unquoted values work
- Addresses Copilot feedback on PR #3

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
4 weeks ago
Jeff Culverhouse 58a09548dd feat: add support for MQTT v3.1.1 protocol version
Add configurable MQTT protocol version support to allow users to choose
between MQTT v5 (default) and v3.1.1 for broker compatibility.

Changes:
- Add protocol_version option to MQTT configuration in config.yaml.sample
- Add MQTT_PROTOCOL environment variable support in helpers.py
- Update README.md with MQTT_PROTOCOL documentation
- Update mqtt-helper-graystorm package to latest version with protocol support

The protocol_version accepts "3.1.1" or "5" (default: "5") and can be
configured via config.yaml or the MQTT_PROTOCOL environment variable.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
4 weeks ago
Jeff Culverhouse 8c195f1eb1 fix: add cleanup methods to protocol interface
Fixes mypy errors by adding cleanup_old_recordings and
cleanup_recordings_loop to AmcrestServiceProtocol.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 month ago
Jeff Culverhouse ebe8d04332 feat: add automatic cleanup of old media recordings
Add configurable retention period for saved clips (default: 7 days).
Recordings older than the retention period are automatically deleted
once per day. Dangling symlinks are also cleaned up when their target
files are removed.

Configure via `media.retention_days` in config.yaml or
`MEDIA_RETENTION_DAYS` environment variable. Set to 0 to disable.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 month ago
Jeff Culverhouse cd4e1aa628 fix: formatting 2 months ago
Jeff Culverhouse b0100f0931 fix: make sure all device_names logged are in quotes 2 months ago
Jeff Culverhouse 41ec32af47 fix: always try to log device_name in preference to device_id 2 months ago
Jeff Culverhouse 459a7f023a feat!: move recording_url and motion_region to attributes
these are no longer sensors themselves but attributes of the
motion sensor and they update when a change to motion happens

also, store_recording_in_media now returns the file name
instead of the full path
3 months ago
Jeff Culverhouse 3d412f20f7 refactor: simplify device discovery and state publication 3 months ago
Jeff Culverhouse 336065e340 chore: formatting problem 3 months ago
Jeff Culverhouse bf54589328 fix: handle permission errors when saving recordings 3 months ago
Jeff Culverhouse e709760971 fix: minor linting issues 3 months ago
Jeff Culverhouse 2d48726917 feat: better error handling and logging
* better snapshot and recording handling
* better event handling
* better device discovery
* better device state handling
* better device command handling
* better device command response handling
* better device command error handling
* better device command timeout handling
* better device command retry handling
3 months ago
Jeff Culverhouse bb6acf4074 chore: sync to lowercase logged messages 3 months ago
Jeff Culverhouse 693eb1c542 refactor: use new BaseMqttMixin from mqtt_helper 3 months ago
Jeff Culverhouse 8a9602af3b refactor: pass default quos and retain 3 months ago
Jeff Culverhouse 366ef61544 refactor: simplify device setup; just use cmps instead of modes 3 months ago
Jeff Culverhouse 07b81abecf feature: add 'version' to logged messages; upgrade packages 3 months ago
Jeff Culverhouse 1231871ba7 fix: save recording path as a string not Pathlib path; upgrade packages 3 months ago
Jeff Culverhouse de3022b920 chore: fix type, upgrade packages 3 months ago
Jeff Culverhouse 1315c70805 chore: log changes to intervals 3 months ago
Jeff Culverhouse 165d0c723f fix: fix interval setting 3 months ago
Jeff Culverhouse 8e1cdb313d chore: minor fixes 3 months ago
Jeff Culverhouse 8c7bfd2b9e feat(discovery): unify service and camera discovery to new HA device schema
* Reworked publish.py and amcrest.py to emit single-payload MQTT device discovery blocks using "platform": "mqtt" and nested "cmps" for entities

* Simplified service entity publication (publish_service_discovery) into unified "device" payload

* Replaced component_type with platform throughout topics and interface definitions

* Refactored build_camera() to generate full per-camera device definition including all sensors, switches, and media links

* Updated publish_device_state() to support targeted subject/sub publishing

* Increased snapshot timeout and backoff (20s, 8s) for better camera stability

* Updated type handling in amcrest_api for network config parsing (cast from tuple or str)

* Bumped coverage dependency → 7.11.2 and refreshed json-logging-graystorm SHA
3 months ago
Jeff Culverhouse 94a4297665 refactor: fully async device setup and improved SDK value handling
- Converted device initialization and state building to async coroutines
- Parallelized Amcrest camera connections using asyncio.gather
- Added clean_value() helper for tuple/list/string SDK outputs
- Added fallback for missing DefaultInterface in network config
- Improved error handling, timeouts, and type annotations
- Verified code quality (ruff, black, mypy all passing)
3 months ago
Jeff Culverhouse a6aee2159d feature: add reboot button, fix other switches 3 months ago
Jeff Culverhouse 1d8c622603 feature: added max_size (MB) to 'media' config section 3 months ago
Jeff Culverhouse 8e12793ae0 refactor: only record specific events as events, not snapshots for example 3 months ago
Jeff Culverhouse 114073e465 feature: add api_call counter, save/restore state to /config dir; simplify getting class vars 3 months ago
Jeff Culverhouse 8a585191a6 fix: simply event for reporting to HA 3 months ago
Jeff Culverhouse ee053122bd fix: always setup defaults for all states expected at init time 3 months ago
Jeff Culverhouse 2ca75d4128 fix: return last known state if we fail to get current state, so upsert just works 3 months ago
Jeff Culverhouse 40e235c2df chore: no need for timezone in config, just set in ENV; update sample files and README 3 months ago
Jeff Culverhouse 33ab97597f fix: more generic Dockerfile; remove old/; better logging for failed /media writes 3 months ago
Jeff Culverhouse 1b111b8a4f fix: add last_device_check sensor; fix service status; only post messages on changes 3 months ago
Jeff Culverhouse a414715f26 fix: code cleanup; fix service sensors; reduce logging 3 months ago
Jeff Culverhouse e8ea58b42d fix: add heartbeat bits and pieces 3 months ago
Jeff Culverhouse 57efd3e86b chore: switch 2 errors to just info 3 months ago
Jeff Culverhouse 35c8486b96 chore: std Dockerfile and docker-compose, plus a few other fixes 3 months ago
Jeff Culverhouse 11e18b1b73 chore: move safe_publish to our helper 3 months ago
Jeff Culverhouse 06e6ce24bb fix: adjust server avty and states 3 months ago
Jeff Culverhouse d0381e28a3 fix: backoff 5+ sec for snapshot retries 3 months ago
Jeff Culverhouse f38251344e fix: one wrong sensor state topic; allow None (null) value to be sent 3 months ago
Jeff Culverhouse 1d52185673 feature: move things around, cleaner code 3 months ago
Jeff Culverhouse 9eb890bad8 feature: added media option to store event recordings on filesystem 3 months ago
Jeff Culverhouse 1a4954b647 refactor: change snapshot from camerga to image entity 3 months ago
Jeff Culverhouse ec3f096246 fix: when motion goes idle, also clear region 3 months ago
Jeff Culverhouse e230a7673f feat!: complete MQTT and service refactor, add timestamp + event tracking, and new modular mixins
- Rewrote MQTT handling with reconnect, structured logging, and Home Assistant re-discovery triggers
- Introduced modular mixins (`helpers`, `mqtt`, `amcrest_api`) for cleaner architecture
- Replaced `util.py` with internal mixin helpers and `to_gb()` conversions
- Added new `event_text` and `event_time` sensors (with `device_class: timestamp`)
- Added support for doorbell and human-detection binary sensors
- Improved reconnect logic, last-will handling, and clean shutdown on signals
- Overhauled device discovery and state publishing to use unified upsert logic
- Simplified event handling and privacy mode inference from motion/human/doorbell events
- Introduced `tools/clear_mqtt.sh` for quick topic cleanup
- Added full pyproject.toml with lint/test/dev config (Black, Ruff, Pytest)
- Embedded full metadata and image labels in Docker build

BREAKING CHANGE:
Project layout moved to `src/amcrest2mqtt/`, internal class and import paths changed.
Users must update configs and volumes to the new structure before deploying.
3 months ago
Jeff Culverhouse ec34875f68 move app; fix Dockerfile 12 months ago