Skip to content

Commit

Permalink
fix(msg.next): Change to object
Browse files Browse the repository at this point in the history
  • Loading branch information
csuermann committed Jun 22, 2021
1 parent 5d822b7 commit 99e10e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions suncron.html
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ <h3>Sun event outputs</h3>
<span class="property-type">obj</span>
</dt>
<dt>msg.next
<span class="property-type">string</span>
<span class="property-type">obj</span>
</dt>
</dl>
<h4>Details</h4>
Expand Down Expand Up @@ -1261,7 +1261,7 @@ <h5>Example <code>msg.schedule</code> object</h5>
</pre>
<h4>Next</h4>
<p>
The <code>msg.next</code> attribute contains a string hinting at the next upcoming event, e.g. &quot;sunsetStart @ 21:29&quot;
The <code>msg.next</code> attribute contains the event object of the schedule which is coming up next.
</p>
<h3>Schedule event outputs</h3>
<p>
Expand Down
9 changes: 6 additions & 3 deletions suncron.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,22 @@ module.exports = function (RED) {
}
}

let nextEvent
let next

try {
nextEvent = findNextEvent(schedule)
console.log('schedule', schedule)
console.log('nextEvent', nextEvent)
next = schedule[nextEvent.eventName]
} catch (e) {
nextEvent = e.message
next = null
}

node.send({
topic,
payload: castPayload(payload, payloadType),
schedule: formatSchedule(schedule),
next: `${nextEvent.eventName} @ ${nextEvent.eventTime.format('HH:mm')}`,
next,
})
}

Expand Down

0 comments on commit 99e10e7

Please sign in to comment.