You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: Add null safety for doorState property to prevent crash with Yale Assure Lock 2 (#165)
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`:
```typescript
// 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:
```typescript
// 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.
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 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](https://gh.io/copilot-coding-agent-tips) in the docs.
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: donavanbecker <[email protected]>
Co-authored-by: Donavan Becker <[email protected]>
0 commit comments