I have a Nuki Smartlock and when I make two API calls to the Nuki Bridge, I receive JSON responses. I want to apply the same logic to both responses:
When requesting for current states, the JSON looks like this:
[{
"deviceType": 0,
"nukiId": 1234,
"name": "NukiDoor",
"firmwareVersion": "2.9.10",
"lastKnownState": {
"mode": 2,
"state": 3,
"stateName": "unlocked",
"batteryCritical": false,
"batteryCharging": false,
"batteryChargeState": 72,
"doorsensorState": 2,
"doorsensorStateName": "door closed",
"timestamp": "2021-01-04T13:02:52+00:00"
}
}]
And if I perform an Action (like opening the door), I get this additional JSON data:
{
"deviceType": 0,
"nukiId": 1234,
"mode": 2,
"state": 3,
"stateName": "unlocked",
"batteryCritical": "OFF",
"batteryCharging": "OFF",
"batteryChargeState": 72,
"doorsensorState": 2,
"doorsensorStateName": "door closed"
}
Therefore, the .lastKnowState node from the Status-Request matches the pure JSON structure of the Action-JSON.
To achieve this consistency in JavaScript, we need to "extract" the lastKnownState node from the first JSON response. How can this be done effectively?