Skip to content

Commit

Permalink
[rules] Refactor EventObject (#136)
Browse files Browse the repository at this point in the history
* [rules] Refactor EventObject to only have properties which have a value

This allows `undefined` checks for the properties.
Fixes the issue described in #134.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

* [README] Update for EventObject changes

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

* [rules] Move ruleConfig JSDoc to extra typedef

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

* [README] Correct EventObject

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

* Move CHANGELOG to extra file

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

* Update CHANGELOG

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

* Update rules/rules.js: Address review comment

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

Co-authored-by: Jonathan Gilbert <github.10.jgilbert@xoxy.net>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

* [rules] Extract logic for adding values from HashMap to function

Addresses review comment.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

* [rules] Remove `command` from event object

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

* [rules] Event object holds no data when Core provided no event data

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

* [rules] Mark `state` var of Event object as deprecated

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

* [rules] Mark `receivedTrigger` of Event Object as deprecated

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

* [rules] Remove `status` from Event object JSDoc

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

Co-authored-by: Jonathan Gilbert <github.10.jgilbert@xoxy.net>
  • Loading branch information
florian-h05 and jpg0 authored Jun 14, 2022
1 parent 5376e87 commit 7a2946b
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 121 deletions.
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Changelog

## 2.0.0 (to be released)

| Type | Namespace | Description | Reference | Breaking |
|-------------|-----------|----------------------------------------------------------|------------------------------------------------|----------|
| Bugfix | rules | Failed rule run logs a useful error message | https://github.com/openhab/openhab-js/pull/116 | No |
| Enhancement | utils | Allow `dumpObject` to also dump own properties | https://github.com/openhab/openhab-js/pull/121 | No |
| Bugfix | rules | Fix `removeItem` not working | https://github.com/openhab/openhab-js/pull/122 | No |
| Enhancement | triggers | Add PWM Automation trigger | https://github.com/openhab/openhab-js/pull/126 | No |
| Enhancement | triggers | Add PID Automation trigger | https://github.com/openhab/openhab-js/pull/131 | No |
| Enhancement | things | Add Thing class & add `getThing`(s) | https://github.com/openhab/openhab-js/pull/132 | No |
| Enhancement | rules | Refactor EventObject to only hold properties with values | TODO | **Yes** |

Also see the [Release Milestone](https://github.com/openhab/openhab-js/milestone/1).

## 1.2.3

Changelog is incomplete!

| Namespace | Description | Reference | Breaking |
|-----------|--------------------------------------------------------------------|------------------------------------------------|----------|
| items | `addItem(...)` and `updateItem(...)` use `itemConfig` as parameter | https://github.com/openhab/openhab-js/pull/109 | **Yes** |
| time | Add timeUtils | https://github.com/openhab/openhab-js/pull/101 | No |


## 1.2.2

Changelog is incomplete!

| Namespace | Description | Reference | Breaking |
|-----------|---------------------------------------------------------------------|-----------------------------------------------|----------|
| items | item.history.lastUpdate() returns `ZonedDateTime` instead of `Date` | https://github.com/openhab/openhab-js/pull/67 | **Yes** |
25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ binding](https://www.openhab.org/addons/automation/jsscripting/).
- [Default Installation](#default-installation)
- [Custom Installation](#custom-installation)
- [Configuration](#configuration)
- [Latest Changes](#latest-changes)
- [Breaking Changes](#breaking-changes)
- [UI Based Rules](#ui-based-rules)
- [Adding Triggers](#adding-triggers)
- [Adding Actions](#adding-actions)
Expand Down Expand Up @@ -66,12 +64,6 @@ This will be used instead of the binding provided version.

### Configuration

## Latest Changes

### Breaking Changes
- item.history.lastUpdate() returns `ZonedDateTime` instead of `Date`
- `addItem(...)` and `updateItem(...)` use [`itemConfig`](#itemconfig) as parameter

## UI Based Rules

The quickest way to add rules is through the openHAB Web UI.
Expand Down Expand Up @@ -904,18 +896,21 @@ This tables gives an overview over the `event` object:
|-------------------|-----------------------------------------------------|-------------------------------------------------------------------------------------|------------------------|
| `oldState` | `ItemStateChangeTrigger`, `GroupStateChangeTrigger` | Previous state of Item or Group that triggered event | `previousState` |
| `newState` | `ItemStateChangeTrigger`, `GroupStateChangeTrigger` | New state of Item or Group that triggered event | N/A |
| `state` | `ItemStateUpdateTrigger`, `GroupStateUpdateTrigger` | State of Item that triggered event | `triggeringItem.state` |
| `receivedState` | `ItemStateUpdateTrigger`, `GroupStateUpdateTrigger` | State of Item that triggered event | `triggeringItem.state` |
| `receivedCommand` | `ItemCommandTrigger`, `GroupCommandTrigger` | Command that triggered event | `receivedCommand` |
| `receivedState` | `ItemStateUpdateTrigger`, `GroupStateUpdateTrigger` | State that triggered event | N/A |
| `receivedTrigger` | `ChannelEventTrigger` | Trigger that triggered event | N/A |
| `itemName` | all | Name of Item that triggered event | `triggeringItem.name` |
| `eventType` | all except `ThingStatus****Trigger`s | Type of event that triggered event (change, command, time, triggered, update) | N/A |
| `triggerType` | all except `ThingStatus****Trigger`s | Type of trigger that triggered event (for `TimeOfDayTrigger`: `GenericCronTrigger`) | N/A |
| `itemName` | `Item****Trigger` | Name of Item that triggered event | `triggeringItem.name` |
| `receivedEvent` | `ChannelEventTrigger` | Channel event that triggered event | N/A |
| `channelUID` | `ChannelEventTrigger` | UID of channel that triggered event | N/A |
| `oldStatus` | `ThingStatusChangeTrigger` | Previous state of Thing that triggered event | N/A |
| `newStatus` | `ThingStatusChangeTrigger` | New state of Thing that triggered event | N/A |
| `status` | `ThingStatusUpdateTrigger` | State of Thing that triggered event | N/A |
| `thingUID` | `Thing****Trigger` | UID of Thing that triggered event | N/A |
| `eventType` | all | Type of event that triggered event (change, command, time, triggered, update) | N/A |
| `triggerType` | all except `PWMTrigger`, `PIDTrigger` | Type of trigger that triggered event (for `TimeOfDayTrigger`: `GenericCronTrigger`) | N/A |
All properties are typeof `string`.
**NOTE:**
`ThingStatusUpdateTrigger`, `ThingStatusChangeTrigger` use *Thing* and `ChannelEventTrigger` uses the the trigger channel name as value for `itemName`.
`Group****Trigger`s use the equivalent `Item****Trigger` as trigger for each member.
See [openhab-js : EventObject](https://openhab.github.io/openhab-js/rules.html#.EventObject) for full API documentation.
Expand Down
Loading

0 comments on commit 7a2946b

Please sign in to comment.