Skip to content

Fix: Cannot read properties of undefined (reading 'setCharacteristic')#28

Closed
Copilot wants to merge 2 commits intolatestfrom
copilot/fix-27
Closed

Fix: Cannot read properties of undefined (reading 'setCharacteristic')#28
Copilot wants to merge 2 commits intolatestfrom
copilot/fix-27

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 21, 2025

Fixes a critical runtime error where the CookRefresh service was causing Cannot read properties of undefined (reading 'setCharacteristic') when HomeKit tried to initialize characteristics.

Root Cause

The error occurred because this.CookRefresh.Service was undefined when setCharacteristic was called. Unlike the Internal and Ambient temperature services, the CookRefresh service lacked proper fallback logic to create the service when getServiceById returned undefined.

Solution

Added service creation logic for CookRefresh that matches the pattern used by other services:

if (this.CookRefresh) {
  if (!this.CookRefresh.Service) {
    this.CookRefresh.Service = new this.hap.Service.Switch(this.CookRefresh.Name.toString(), this.CookRefresh.Name.toString())
    if (this.CookRefresh.Service) {
      this.CookRefresh.Service = this.accessory.addService(this.CookRefresh.Service)
      this.debugLog(`${accessory.displayName} Cook Refresh Service`)
    } else {
      this.errorLog(`${accessory.displayName} Cook Refresh Service -- Failed!`)
    }
  }
}

This ensures this.CookRefresh.Service is always defined before characteristics are set, preventing the undefined error.

Fixes #27


💡 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.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 21, 2025

@donavanbecker 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Co-authored-by: donavanbecker <9875439+donavanbecker@users.noreply.github.com>
@donavanbecker
Copy link
Copy Markdown
Collaborator

@copilot Finish please

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Sep 4, 2025

@copilot Finish please

I've completed the fix! The CookRefresh service creation logic has been implemented and tested successfully. The fix adds proper fallback service creation for the CookRefresh service, matching the pattern used by Internal and Ambient services.

Completed tasks:

  • Fixed missing service creation logic for CookRefresh service (commit 41d3ff6)
  • Verified linting passes
  • Confirmed build compiles successfully
  • All tests pass
  • Validated the fix prevents the "Cannot read properties of undefined" error

The solution is minimal (12 lines added, 1 modified) and resolves issue #27.

Copilot AI changed the title [WIP] Bug: Cannot read properties of undefined (reading 'setCharacteristic') Fix: Cannot read properties of undefined (reading 'setCharacteristic') Sep 4, 2025
@donavanbecker donavanbecker mentioned this pull request May 4, 2026
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.

Bug: Cannot read properties of undefined (reading 'setCharacteristic')

2 participants