diff --git a/src/darwin/Framework/CHIP/MTRDevice_XPC.mm b/src/darwin/Framework/CHIP/MTRDevice_XPC.mm index d5356320b24d4c..bc5fa52b327236 100644 --- a/src/darwin/Framework/CHIP/MTRDevice_XPC.mm +++ b/src/darwin/Framework/CHIP/MTRDevice_XPC.mm @@ -322,7 +322,20 @@ - (oneway void)device:(NSNumber *)nodeID internalStateUpdated:(NSDictionary *)di - (MTRDeviceState)state { NSNumber * stateNumber = MTR_SAFE_CAST(self._internalState[kMTRDeviceInternalPropertyDeviceState], NSNumber); - return stateNumber ? static_cast(stateNumber.unsignedIntegerValue) : MTRDeviceStateUnknown; + switch (static_cast(stateNumber.unsignedIntegerValue)) { + case MTRDeviceStateUnknown: + return MTRDeviceStateUnknown; + + case MTRDeviceStateUnreachable: + return MTRDeviceStateUnreachable; + + case MTRDeviceStateReachable: + return MTRDeviceStateReachable; + } + + MTR_LOG_ERROR("stateNumber from internal state is an invalid value: %@", stateNumber); + + return MTRDeviceStateUnknown; } - (BOOL)deviceCachePrimed