Skip to content

Commit

Permalink
Reworked get-status node to explicitly zero out response fields for r…
Browse files Browse the repository at this point in the history
…eplies without an event (cf. uhppoted/uhppote-core#18)
  • Loading branch information
twystd committed Nov 2, 2023
1 parent 5e1dade commit fd08609
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

### Updated
1. Fixed input/output labels for renamed nodes.
2. Reworked `get-status` to return '' for zero value event timestamps.
3. Reworked `get-status` to explicitly set fields for response with no event.


## [1.1.5](https://github.com/uhppoted/node-red-contrib-uhppoted/releases/tag/v1.1.5) - 2023-08-30
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- [x] set-door-passcodes (cf. https://github.com/uhppoted/uhppoted/issues/40)
- [x] Fix input/output labels
- [x] Rework `get-status` to return '' for zero timestamp (cf. https://github.com/uhppoted/uhppoted-dll/issues/7)
- [ ] Replace Event pointer in GetStatusResponse with zero value (cf. https://github.com/uhppoted/uhppote-core/issues/18)
- [x] Replace Event pointer in GetStatusResponse with zero value (cf. https://github.com/uhppoted/uhppote-core/issues/18)


## TODO
Expand Down
33 changes: 23 additions & 10 deletions nodes/decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,33 @@ module.exports = {
GetStatus: function (bytes, translator) {
const lookup = require('./lookup.js')

const evt = {
index: uint32(bytes, 8),
type: lookup.eventType(bytes, 12, translator),
granted: bool(bytes, 13),
door: uint8(bytes, 14),
direction: lookup.direction(bytes, 15, translator),
card: uint32(bytes, 16),
timestamp: optionalDatetime(bytes, 20),
reason: lookup.reason(bytes, 27, translator)
}

// No event?
if (evt.index === 0) {
evt.type = lookup.noEventType(translator)
evt.granted = false
evt.door = 0
evt.direction = lookup.noEventDirection(translator)
evt.card = 0
evt.timestamp = ''
evt.reason = lookup.noEventReason(translator)
}

return {
deviceId: uint32(bytes, 4),
state: {
serialNumber: uint32(bytes, 4),
event: {
index: uint32(bytes, 8),
type: lookup.eventType(bytes, 12, translator),
granted: bool(bytes, 13),
door: uint8(bytes, 14),
direction: lookup.direction(bytes, 15, translator),
card: uint32(bytes, 16),
timestamp: optionalDatetime(bytes, 20),
reason: lookup.reason(bytes, 27, translator)
},
event: evt,
doors: {
1: bool(bytes, 28),
2: bool(bytes, 29),
Expand Down
10 changes: 5 additions & 5 deletions nodes/locales/en-US/uhppoted-get-status.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ <h4>Example:</h4>
<dt>state.serialNumber<span class="property-type">uint32</span></dt>
<dd>controller serial number</dd>
<dt>state.event.index<span class="property-type">uint32</span></dt>
<dd>event record number</d>
<dd>event record number (0 for no event)</d>
<dt>state.event.type.code<span class="property-type">uint8</span></dt>
<dd>raw event type</dd>
<dd>raw event type (0 for no event)</dd>
<dt>state.event.type.event<span class="property-type">string</span></dt>
<dd>decoded event type</dd>
<dt>state.event.granted<span class="property-type">boolean</span></dt>
<dd>access granted/denied</dd>
<dt>state.event.door<span class="property-type">uint8</span></dt>
<dd>event door ID for swipe/door events</dd>
<dd>event door ID for swipe/door events (0 for unknown)</dd>
<dt>state.event.direction.code<span class="property-type">uint8</span></dt>
<dd>event door direction for swipe/door events</dd>
<dd>event door direction for swipe/door events (0 for unknown)</dd>
<dt>state.event.direction.direction<span class="property-type">uint8</span></dt>
<dd>decoded event door direction for swipe/door events</dd>
<dt>state.event.card<span class="property-type">uint32</span></dt>
<dd>card number for swipe/door events</dd>
<dt>state.event.timestamp<span class="property-type">timestamp</span></dt>
<dd>event timestamp, formatted as YYYY-mm-dd HH:mm:ss</dd>
<dd>event timestamp, formatted as YYYY-mm-dd HH:mm:ss ('' for no timestamp)</dd>
<dt>state.event.reason.code<span class="property-type">uint8</span></dt>
<dd>raw event reason</dd>
<dt>state.event.reason.reason<span class="property-type">string</span></dt>
Expand Down
51 changes: 51 additions & 0 deletions nodes/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,57 @@ module.exports = {
}

return control
},

/**
* Expands an event type '0' (no event) into an object with event code and internationalised
* event message.
*
* @param {function} translator (optional) function to translate event message.
*
* @param {object} { code:byte, event:string }
*
* @exports
*/
noEventType: function (translator) {
return {
code: 0,
event: translate(translator, 'none')
}
},

/**
* Expands an event direction '0' (no event) into an object with event code and internationalised
* event message.
*
* @param {function} translator (optional) function to translate event message.
*
* @param {object} { code:byte, event:string }
*
* @exports
*/
noEventDirection: function (translator) {
return {
code: 0,
direction: translate(translator, 'unknown')
}
},

/**
* Expands an event reason '0' (no event) into an object with event reason and internationalised
* reason description.
*
* @param {function} translator (optional) function to translate reason description.
*
* @param {object} { code: byte, reason: string }
*
* @exports
*/
noEventReason: function (translator) {
return {
code: 0,
reason: translate(translator, 'no reason')
}
}
}

Expand Down

0 comments on commit fd08609

Please sign in to comment.