Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 3, 2025

The plugin was crashing with Cannot read properties of undefined (reading 'includes') when used with Yale Assure Lock 2 devices. The issue occurred because the lock's API response contains a lockStatus object like {"status":"unknown"} without a doorState property, but the code assumed this property would always exist.

The crash happened in the parseStatus method when trying to call .includes() on the undefined doorState:

// This would crash when doorState is undefined
this.lockStatus.doorState.includes('open')
this.lockStatus.doorState.includes('closed')

The fix adds optional chaining to safely handle cases where doorState is undefined:

// Safe version that returns undefined instead of crashing
this.lockStatus.doorState?.includes('open')
this.lockStatus.doorState?.includes('closed')

This minimal change:

  • Prevents the crash by gracefully handling undefined doorState
  • Maintains backward compatibility for locks that do provide doorState
  • Preserves all existing functionality and logic flow
  • Allows the plugin to continue reading battery status and other lock information

The contact sensor functionality will fall back to the existing ContactSensorState when doorState is unavailable, ensuring the plugin remains functional even without door state information.

Fixes #127.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@donavanbecker donavanbecker changed the base branch from latest to beta-3.0.3 September 3, 2025 12:00
@Copilot Copilot AI changed the title [WIP] Bug: Cannot read properties of undefined (reading 'includes') Fix: Add null safety for doorState property to prevent crash with Yale Assure Lock 2 Sep 3, 2025
Copilot finished work on behalf of donavanbecker September 3, 2025 12:07
@Copilot Copilot AI requested a review from donavanbecker September 3, 2025 12:07
@donavanbecker donavanbecker marked this pull request as ready for review September 3, 2025 12:10
@github-actions github-actions bot added fix enhancement New feature or request beta labels Sep 3, 2025
@donavanbecker donavanbecker merged commit f55d1c9 into beta-3.0.3 Sep 3, 2025
7 checks passed
@donavanbecker donavanbecker deleted the copilot/fix-127 branch September 3, 2025 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta enhancement New feature or request fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Cannot read properties of undefined (reading 'includes')
2 participants