Skip to content

Commit

Permalink
Prevent TypeError when handling JSON availability payload (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
itavero authored Jan 4, 2025
1 parent 1726609 commit 0a42b37
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Since version 1.0.0, we try to follow the [Semantic Versioning](https://semver.o

- For numeric characteristics that have a range set, the range is automatically updated if an out of range value is received from Zigbee2MQTT.

### Fixed

- Processing JSON availability payload should not result in a TypeError anymore.

## [1.11.0-beta.7] - 2025-01-04

### Changed
Expand Down
6 changes: 3 additions & 3 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ export class Zigbee2mqttPlatform implements DynamicPlatformPlugin {
// Check if payload is a JSON object or a plain string
let isAvailable = false;
if (statePayload.includes('{')) {
const state = JSON.parse(statePayload).availability;
if ('state' in state) {
isAvailable = state.state === 'online';
const json = JSON.parse(statePayload);
if (json !== undefined && 'availability' in json && json.availability !== undefined && 'state' in json.availability) {
isAvailable = json.availability.state === 'online';
}
} else {
isAvailable = statePayload === 'online';
Expand Down

0 comments on commit 0a42b37

Please sign in to comment.