Skip to content

Conversation

@raman325
Copy link
Collaborator

@raman325 raman325 commented Jan 20, 2026

Summary

Add test coverage for accesslimit_count functionality as requested in PR #551 review, plus refactor entity.py helper methods.

Proposed change

Tests

test_number.py:

  • test_number_entity_converts_float_to_int_for_accesslimit_count: Verifies that float values from NumberEntity frontend are properly converted to integers when stored in the code slot

test_coordinator_events.py:

  • test_lock_unlocked_decrements_accesslimit_count: Verifies the count is decremented when a lock is unlocked with a code slot
  • test_lock_unlocked_decrements_parent_lock_accesslimit_count: Verifies parent lock's count is decremented for child locks not overriding parent
  • test_lock_unlocked_does_not_decrement_when_count_zero: Verifies count doesn't go negative

Refactoring

entity.py:

  • Consolidate _get_code_slots_num and _get_day_of_week_num into single _get_x_num method
  • Use Literal type for property_name parameter for type safety
  • Simplify __init__ by removing redundant guard checks (already handled in helper method)
  • Reorder attribute initialization for clarity

coordinator.py:

Type of change

  • Code quality improvements to existing code or addition of tests

Additional information

Copilot AI review requested due to automatic review settings January 20, 2026 14:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive test coverage for the accesslimit_count functionality in the keymaster integration, as requested in PR #551 review. The tests verify that access limit counts are properly decremented when locks are unlocked, including parent-child lock relationships and edge cases.

Changes:

  • Added test for float-to-int conversion in NumberEntity for accesslimit_count
  • Added tests for accesslimit_count decrement behavior in lock unlock events
  • Added type annotation for consistency in coordinator.py

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/test_number.py Added test verifying float values from NumberEntity frontend are converted to integers when stored in accesslimit_count
tests/test_coordinator_events.py Added three tests for accesslimit_count decrement: basic decrement, parent lock decrement for child locks, and prevention of negative values
custom_components/keymaster/coordinator.py Added type annotation to accesslimit_count variable for consistency with parent lock code path

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Add test for float-to-int conversion when setting accesslimit_count via NumberEntity
- Add tests for accesslimit_count decrement on lock unlock:
  - Basic decrement when slot is used
  - Parent lock decrement for child locks
  - No decrement when count is already at 0
- Add type annotation for consistency in coordinator.py

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@raman325 raman325 force-pushed the fix/accesslimit-count-tests branch from 8bb670a to a6b6e7b Compare January 20, 2026 14:15
- Merge _get_code_slots_num and _get_day_of_week_num into _get_x_num
- Use Literal type for property_name parameter
- Simplify __init__ by removing redundant guard checks
- Reorder attribute initialization for clarity

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@raman325 raman325 changed the title test: add tests for accesslimit_count behavior test: add tests for accesslimit_count behavior; refactor entity helpers Jan 20, 2026
raman325 and others added 2 commits January 20, 2026 09:35
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Rename test functions and update method calls from _get_code_slots_num
and _get_day_of_week_num to _get_x_num("code_slots") and
_get_x_num("accesslimit_day_of_week") respectively.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@raman325 raman325 merged commit 1dcef45 into beta Jan 20, 2026
8 checks passed
@raman325 raman325 deleted the fix/accesslimit-count-tests branch January 20, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants