Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[openwebnet] Add a time stamp when an alarm zone event occurs #14819

Merged
merged 1 commit into from
May 5, 2023
Merged

[openwebnet] Add a time stamp when an alarm zone event occurs #14819

merged 1 commit into from
May 5, 2023

Conversation

fabgio
Copy link
Contributor

@fabgio fabgio commented Apr 15, 2023

Description:
This PR allows to show a time stamp when an alarm zone event occurs on Bticino/Legrand Alarm systems such as an Intrusion or a Tampering This PR closes #14535

Test
Tested on BTicino/Legrand bulgrar-alarm unit 3486

@fabgio fabgio requested a review from mvalla as a code owner April 15, 2023 16:45
Copy link
Contributor

@mvalla mvalla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabgio see required changes.

You also have to generate the default English localization, see: https://github.com/openhab/openhab-addons#translations

This is a second PR after #14743
PS
Do not change again the PR, beacuse each time a new review is required.

| `network` | `bus_alarm_system` | Switch | Alarm system network state (`ON` = network ok, `OFF` = no network) | R |
| `battery` | `bus_alarm_system` | String | Alarm system battery state (`OK`, `FAULT`, `UNLOADED`) | R |
| `armed` | `bus_alarm_system` | Switch | Alarm system is armed (`ON`) or disarmed (`OFF`) | R |
| `alarm` | `bus_alarm_zone` | String | Current alarm for the zone (`SILENT`, `INTRUSION`, `TAMPERING`, `ANTI_PANIC`) | R |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you modifiy only the lines related to adding the new channel?

Copy link
Contributor Author

@fabgio fabgio Apr 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I did'nt change this lines I can't figure out why they appear as changed. I cannot spot any difference.. Can you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe spaces? Copy paste the original lines from original version

@@ -232,31 +240,44 @@ private void updateZoneAlarm(WhatAlarm w) {
switch (w) {
case ZONE_ALARM_INTRUSION:
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_INTRUSION));
updateZoneAlarmTimeStamp();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have to choose when updateZoneAlarmTimeStamp is called. This way it's called 2 times: in the switch inside updateZoneAlarm and then again in the updateZone switch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I choose to call it in updateZone() to invoke it only once

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

break;
case ZONE_ALARM_TAMPERING:
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_TAMPERING));
updateZoneAlarmTimeStamp();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

break;
case ZONE_ALARM_ANTI_PANIC:
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_ANTI_PANIC));
updateZoneAlarmTimeStamp();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -218,6 +225,7 @@ private void updateZone(Alarm msg) {
case ZONE_ALARM_TECHNICAL:
case ZONE_ALARM_TECHNICAL_RESET:
updateZoneAlarm(w);
updateZoneAlarmTimeStamp();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have to choose when updateZoneAlarmTimeStamp is called. This way it's called 2 times: in the switch inside updateZoneAlarm and then again in the updateZone switch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I will call it in updateZone() only

break;
default:
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_NONE));
logger.warn("Alarm.updateZoneAlarm() Ignoring unsupported WHAT {} for zone {}", w, this.deviceWhere);
}
}

private void updateZoneAlarmTimeStamp() {
ZonedDateTime now = ZonedDateTime.now();
ChannelUID cuid = new ChannelUID(getThing().getUID(), CHANNEL_ALARM_ZONE_TIMESTAMP);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is useless. Why don't you do the same like in initialize():
updateState(CHANNEL_ALARM_ZONE_TIMESTAMP, ....

Copy link
Contributor Author

@fabgio fabgio Apr 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -17,6 +17,7 @@
<!-- read only -->
<channel id="state" typeId="alarmZoneState"/>
<channel id="alarm" typeId="zoneAlarm"/>
<channel id="timestamp" typeId="zoneAlarmTimeStamp"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<channel id="timestamp" typeId="zoneAlarmTimeStamp"/>
<channel id="timestamp" typeId="zoneAlarmTimestamp"/>

Timestamp and not TimeStamp (it's one word)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -461,6 +461,14 @@
</state>
</channel-type>

<channel-type id="zoneAlarmTimeStamp">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<channel-type id="zoneAlarmTimeStamp">
<channel-type id="zoneAlarmTimestamp">

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -461,6 +461,14 @@
</state>
</channel-type>

<channel-type id="zoneAlarmTimeStamp">
<item-type>DateTime</item-type>
<label>Zone TimeStamp</label>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<label>Zone TimeStamp</label>
<label>Zone Alarm Timestamp</label>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mvalla mvalla added the enhancement An enhancement or new feature for an existing add-on label Apr 15, 2023
@@ -285,6 +285,8 @@ channel-type.openwebnet.zoneAlarm.state.option.SILENT = Silent
channel-type.openwebnet.zoneAlarm.state.option.TECHNICAL = Technical
channel-type.openwebnet.zoneAlarm.state.option.TECHNICAL_RESET = Technical Reset
channel-type.openwebnet.zoneAlarm.state.option.NONE = None
channel-type.openwebnet.zoneAlarmTimestamp.label = Zone Alarm TimeStamp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
channel-type.openwebnet.zoneAlarmTimestamp.label = Zone Alarm TimeStamp
channel-type.openwebnet.zoneAlarmTimestamp.label = Zone Alarm Timestamp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

<item-type>DateTime</item-type>
<label>Zone TimeStamp</label>
<label>Zone Alarm TimeStamp</label>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<label>Zone Alarm TimeStamp</label>
<label>Zone Alarm Timestamp</label>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -270,14 +264,13 @@ private void updateZoneAlarm(WhatAlarm w) {

private void updateZoneAlarmTimeStamp() {
ZonedDateTime now = ZonedDateTime.now();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ZonedDateTime now = ZonedDateTime.now();

@@ -270,14 +264,13 @@ private void updateZoneAlarm(WhatAlarm w) {

private void updateZoneAlarmTimeStamp() {
ZonedDateTime now = ZonedDateTime.now();
ChannelUID cuid = new ChannelUID(getThing().getUID(), CHANNEL_ALARM_ZONE_TIMESTAMP);
updateState(cuid, new DateTimeType(now.truncatedTo(ChronoUnit.SECONDS)));
updateState(CHANNEL_ALARM_ZONE_ALARM_TIMESTAMP, new DateTimeType(now.truncatedTo(ChronoUnit.SECONDS)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
updateState(CHANNEL_ALARM_ZONE_ALARM_TIMESTAMP, new DateTimeType(now.truncatedTo(ChronoUnit.SECONDS)));
updateState(CHANNEL_ALARM_ZONE_ALARM_TIMESTAMP, new DateTimeType());

Copy link
Contributor Author

@fabgio fabgio Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 266 is unuseful at this point so I would remove it and as a consequence would be updateZoneTimeStamp() implementation still convenient? I could simply invoke updateState(CHANNEL_ALARM_ZONE_ALARM_TIMESTAMP, new DateTimeType()) directly in updateZone()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done as per previous comment

| `network` | `bus_alarm_system` | Switch | Alarm system network state (`ON` = network ok, `OFF` = no network) | R |
| `battery` | `bus_alarm_system` | String | Alarm system battery state (`OK`, `FAULT`, `UNLOADED`) | R |
| `armed` | `bus_alarm_system` | Switch | Alarm system is armed (`ON`) or disarmed (`OFF`) | R |
| `alarm` | `bus_alarm_zone` | String | Current alarm for the zone (`SILENT`, `INTRUSION`, `TAMPERING`, `ANTI_PANIC`) | R |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe spaces? Copy paste the original lines from original version

Copy link
Contributor

@mvalla mvalla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fabgio
Copy link
Contributor Author

fabgio commented Apr 18, 2023

Thank you so much!

@lolodomo
Copy link
Contributor

Please add migration instructions for the new channel.
A link to the documentation
https://next.openhab.org/docs/developer/bindings/thing-xml.html#updating-thing-types

Copy link
Contributor

@mvalla mvalla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never used such migration feature, but I think that:

  • directory is wrong
  • < label > should be the new channel label, not its description
  • according to instructions this is also needed that "In addition to the update instructions, the thing-type definition needs to add a property thingTypeVersion to prevent newly created things from being modified"

@fabgio
Copy link
Contributor Author

fabgio commented Apr 24, 2023

@mvalla I see, I will check in accordance with your tips.

I never used such a migration feature

So do I, that is completely new to me

@fabgio
Copy link
Contributor Author

fabgio commented Apr 25, 2023

@mvalla I fulfilled all of the three points you mentioned above. Moreover I validated update.xml for correctness

@fabgio
Copy link
Contributor Author

fabgio commented May 3, 2023

Do you mean I should remove that line,right? I removed it and validate update.xml with no errors

@lolodomo
Copy link
Contributor

lolodomo commented May 3, 2023

You have update.xml twice in 2 different folders: OH-INF/update and OH.INF/update. Only the first is needed.

@fabgio
Copy link
Contributor Author

fabgio commented May 3, 2023

You are right My local branch does not show OH.INF update whereas the origin does. lets try push it

@fabgio
Copy link
Contributor Author

fabgio commented May 3, 2023

I am striving to get rid of the wrong OH.INF dir from my origin even by forcing push... I will handle this problem

@fabgio
Copy link
Contributor Author

fabgio commented May 3, 2023

ok OH.INF dir has gone now!!!

Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you

@lolodomo
Copy link
Contributor

lolodomo commented May 4, 2023

DCO KO.
Maybe you did not sign-off properly one of your last commits ?
Please fix it in case it is the last one. If not, squash several of your commits.

This reverts commit 3807c80.

Signed-off-by: Giovanni Fabiani <[email protected]>
@fabgio
Copy link
Contributor Author

fabgio commented May 4, 2023

DTO is ok now.. tommorow I will do further integration-tests, waiting for @mvalla review

@fabgio
Copy link
Contributor Author

fabgio commented May 4, 2023

@lolodomo I appreciated your support! Thanks a lot

@lolodomo
Copy link
Contributor

lolodomo commented May 4, 2023

tommorow I will do further integration-tests, waiting for @mvalla review

Do you mean the PR is not yet ready for a merge?

@fabgio
Copy link
Contributor Author

fabgio commented May 4, 2023

Yes, Exactly I prefer to perform a couple of integration tests tomorrow so if everything works as expected and @mvalla agrees, on saturday the PR will be ready for merge!

@lolodomo lolodomo added the work in progress A PR that is not yet ready to be merged label May 5, 2023
@lolodomo
Copy link
Contributor

lolodomo commented May 5, 2023

Current code looks good to me.

@fabgio
Copy link
Contributor Author

fabgio commented May 5, 2023

@lolodomo, i did tests. Good feedbacks! To me the PR is ready for merge

@lolodomo lolodomo removed the work in progress A PR that is not yet ready to be merged label May 5, 2023
Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you

@lolodomo lolodomo merged commit 7bcf2e7 into openhab:main May 5, 2023
@lolodomo lolodomo added this to the 4.0 milestone May 5, 2023
@fabgio
Copy link
Contributor Author

fabgio commented May 5, 2023

Thanks again See you soon!

@fabgio fabgio deleted the 14535_openwebnet_4.0.0 branch May 9, 2023 16:27
@fabgio
Copy link
Contributor Author

fabgio commented May 9, 2023 via email

tb4jc pushed a commit to tb4jc/openhab-addons that referenced this pull request Jun 19, 2023
This reverts commit 3807c80.

Signed-off-by: Giovanni Fabiani <[email protected]>
Signed-off-by: Thomas Burri <[email protected]>
matchews pushed a commit to matchews/openhab-addons that referenced this pull request Aug 9, 2023
This reverts commit 3807c80.

Signed-off-by: Giovanni Fabiani <[email protected]>
Signed-off-by: Matt Myers <[email protected]>
austvik pushed a commit to austvik/openhab-addons that referenced this pull request Mar 27, 2024
This reverts commit 3807c80.

Signed-off-by: Giovanni Fabiani <[email protected]>
Signed-off-by: Jørgen Austvik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[openwebnet] Alarm: add a time stamp when a alarm zone event occurs
3 participants