Skip to content

Commit

Permalink
[hue] align with openhab#15552
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
  • Loading branch information
andrewfg committed Oct 27, 2023
1 parent 294c484 commit 089060e
Show file tree
Hide file tree
Showing 14 changed files with 190 additions and 16 deletions.
5 changes: 3 additions & 2 deletions bundles/org.openhab.binding.hue/doc/readme_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ Device things support some of the following channels:
| dimming-only | Dimmer | Allows access to the `dimming` parameter of the light(s) only. Has no impact on `color-xy` or `on-off` parameters. |
| on-off-only | Switch | Allows access to the `on-off` parameter of the light(s) only. Has no impact on `color-xy` or `dimming` parameters. |
| security-contact | Contact | Indicates whether a security contact has been triggered. (Read Only) |
| security-contact-last-updated | DateTime | The date and time when the security contact state was last updated. (Read Only, Advanced) |
| security-contact-enabled | Switch | Supports enabling / disabling the security contact. (Advanced) |
| security-contact-last-updated | DateTime | The date and time when the security contact state was last updated. (Read Only) (Advanced) |
| security-tamper | Contact | Indicates whether a security tamper contact has been triggered. `Open` means tampering detected. (Read Only) |
| security-tamper-last-updated | DateTime | The date and time when the security tamper contact state was last updated. (Read Only, Advanced) |
| security-tamper-last-updated | DateTime | The date and time when the security tamper contact state was last updated. (Read Only) (Advanced) |

The exact list of channels in a given device is determined at run time when the system is started.
Each device reports its own live list of capabilities, and the respective list of channels is created accordingly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public class HueBindingConstants {
public static final String CHANNEL_2_DIMMING_ONLY = "dimming-only";
public static final String CHANNEL_2_ON_OFF_ONLY = "on-off-only";
public static final String CHANNEL_2_SECURITY_CONTACT = "security-contact";
public static final String CHANNEL_2_SECURITY_CONTACT_ENABLED = "security-contact-enabled";
public static final String CHANNEL_2_SECURITY_CONTACT_LAST_UPDATED = "security-contact-last-updated";
public static final String CHANNEL_2_SECURITY_TAMPER = "security-tamper";
public static final String CHANNEL_2_SECURITY_TAMPER_LAST_UPDATED = "security-tamper-last-updated";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.hue.internal.dto.clip2;

import java.time.Instant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public class Resource {
private @Nullable List<ResourceReference> children;
private @Nullable JsonElement status;
private @Nullable @SuppressWarnings("unused") Dynamics dynamics;
private @Nullable @SerializedName("contact-report") ContactReport contactReport;
private @Nullable @SerializedName("tamper-reports") List<TamperReport> tamperReports;
private @Nullable @SerializedName("contact_report") ContactReport contactReport;
private @Nullable @SerializedName("tamper_reports") List<TamperReport> tamperReports;
private @Nullable String state;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.hue.internal.dto.clip2;

import java.time.Instant;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.hue.internal.dto.clip2.enums;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.hue.internal.dto.clip2.enums;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ public void handleCommand(ChannelUID channelUID, Command commandParam) {
putResource = new Resource(ResourceType.LIGHT_LEVEL).setEnabled(command);
break;

case CHANNEL_2_SECURITY_CONTACT_ENABLED:
putResource = new Resource(ResourceType.CONTACT).setEnabled(command);
break;

case CHANNEL_2_SCENE:
if (command instanceof StringType) {
Resource scene = sceneResourceEntries.get(((StringType) command).toString());
Expand Down Expand Up @@ -925,6 +929,7 @@ private boolean updateChannels(Resource resource) {
updateState(CHANNEL_2_SECURITY_CONTACT, resource.getContactState(), fullUpdate);
updateState(CHANNEL_2_SECURITY_CONTACT_LAST_UPDATED,
resource.getContactLastUpdatedState(timeZoneProvider.getTimeZone()), fullUpdate);
updateState(CHANNEL_2_SECURITY_CONTACT_ENABLED, resource.getEnabledState(), fullUpdate);
break;

case TAMPER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ thing-type.hue.device.channel.motion-enabled.description = Motion sensor enabled
thing-type.hue.device.channel.motion-last-updated.label = Motion Last Updated
thing-type.hue.device.channel.motion-last-updated.description = The date and time when the motion value was last updated.
thing-type.hue.device.channel.on-off-only.description = Set the on/off parameter of the light without changing other state parameters.
thing-type.hue.device.channel.rotary-steps-last-updated.label = Rotary Steps Last Updated
thing-type.hue.device.channel.rotary-steps-last-updated.description = The date and time when the rotary steps were last updated.
thing-type.hue.device.channel.security-contact.label = Security Contact
thing-type.hue.device.channel.security-contact.description = Open or closed state of the contact.
thing-type.hue.device.channel.security-contact-enabled.description = Security contact enabled.
thing-type.hue.device.channel.security-contact-last-updated.label = Security Contact Last Updated
thing-type.hue.device.channel.security-contact-last-updated.description = The date and time when the contact state was last updated.
thing-type.hue.device.channel.security-tamper.label = Security Tamper Contact
thing-type.hue.device.channel.security-tamper.description = Tamper or no tamper state of the sensor.
thing-type.hue.device.channel.security-tamper-last-updated.label = Tamper Contact Last Updated
thing-type.hue.device.channel.security-tamper-last-updated.description = The date and time when the tamper contact state was last updated.
thing-type.hue.device.channel.rotary-steps-last-updated.label = Rotary Steps Last Updated
thing-type.hue.device.channel.rotary-steps-last-updated.description = The date and time when the rotary steps were last updated.
thing-type.hue.device.channel.temperature.label = Temperature
thing-type.hue.device.channel.temperature.description = Temperature at the sensor location.
thing-type.hue.device.channel.temperature-enabled.description = Temperature sensor enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<label>Security Contact</label>
<description>Open or closed state of the contact.</description>
</channel>
<channel id="security-contact-enabled" typeId="sensor-enabled">
<description>Security contact enabled.</description>
</channel>
<channel id="security-contact-last-updated" typeId="last-updated-v2">
<label>Security Contact Last Updated</label>
<description>The date and time when the contact state was last updated.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,20 +712,38 @@ void testZoneGroup() {

@Test
void testSecurityContact() {
Resource resource = new Resource(ResourceType.CONTACT);
assertEquals(UnDefType.NULL, resource.getContactState());
assertEquals(UnDefType.NULL, resource.getContactLastUpdatedState(ZoneId.systemDefault()));
resource.setContactReport(new ContactReport().setLastChanged(Instant.now()).setContactState("contact"));
String json = load(ResourceType.CONTACT.name().toLowerCase());
Resources resources = GSON.fromJson(json, Resources.class);
assertNotNull(resources);
List<Resource> list = resources.getResources();
assertNotNull(list);
assertEquals(1, list.size());
Resource resource = list.get(0);
assertEquals(ResourceType.CONTACT, resource.getType());

assertEquals(OpenClosedType.CLOSED, resource.getContactState());
assertTrue(resource.getContactLastUpdatedState(ZoneId.systemDefault()) instanceof DateTimeType);
assertEquals(new DateTimeType("2023-10-10T19:10:55.919Z"),
resource.getContactLastUpdatedState(ZoneId.of("UTC")));

resource.setContactReport(new ContactReport().setLastChanged(Instant.now()).setContactState("no_contact"));
assertEquals(OpenClosedType.OPEN, resource.getContactState());
assertTrue(resource.getContactLastUpdatedState(ZoneId.of("UTC")) instanceof DateTimeType);
}

@Test
void testSecurityTamper() {
Resource resource = new Resource(ResourceType.CONTACT);
assertEquals(UnDefType.NULL, resource.getTamperState());
String json = load(ResourceType.TAMPER.name().toLowerCase());
Resources resources = GSON.fromJson(json, Resources.class);
assertNotNull(resources);
List<Resource> list = resources.getResources();
assertNotNull(list);
assertEquals(1, list.size());
Resource resource = list.get(0);
assertEquals(ResourceType.TAMPER, resource.getType());

assertEquals(OpenClosedType.CLOSED, resource.getTamperState());
assertEquals(new DateTimeType("2023-01-01T00:00:00.001Z"),
resource.getTamperLastUpdatedState(ZoneId.of("UTC")));

Instant start = Instant.now();
List<TamperReport> tamperReports;
Expand All @@ -735,7 +753,7 @@ void testSecurityTamper() {
tamperReports.add(new TamperReport().setTamperState("not_tampered").setLastChanged(start));
resource.setTamperReports(tamperReports);
assertEquals(OpenClosedType.CLOSED, resource.getTamperState());
state = resource.getTamperLastUpdatedState(ZoneId.systemDefault());
state = resource.getTamperLastUpdatedState(ZoneId.of("UTC"));
assertTrue(state instanceof DateTimeType);
assertEquals(start, ((DateTimeType) state).getInstant());

Expand All @@ -744,7 +762,7 @@ void testSecurityTamper() {
tamperReports.add(new TamperReport().setTamperState("tampered").setLastChanged(start.plusSeconds(1)));
resource.setTamperReports(tamperReports);
assertEquals(OpenClosedType.OPEN, resource.getTamperState());
state = resource.getTamperLastUpdatedState(ZoneId.systemDefault());
state = resource.getTamperLastUpdatedState(ZoneId.of("UTC"));
assertTrue(state instanceof DateTimeType);
assertEquals(start.plusSeconds(1), ((DateTimeType) state).getInstant());

Expand All @@ -754,11 +772,30 @@ void testSecurityTamper() {
tamperReports.add(new TamperReport().setTamperState("not_tampered").setLastChanged(start.plusSeconds(2)));
resource.setTamperReports(tamperReports);
assertEquals(OpenClosedType.CLOSED, resource.getTamperState());
state = resource.getTamperLastUpdatedState(ZoneId.systemDefault());
state = resource.getTamperLastUpdatedState(ZoneId.of("UTC"));
assertTrue(state instanceof DateTimeType);
assertEquals(start.plusSeconds(2), ((DateTimeType) state).getInstant());
}

@Test
void testCameraMotion() {
String json = load(ResourceType.CAMERA_MOTION.name().toLowerCase());
Resources resources = GSON.fromJson(json, Resources.class);
assertNotNull(resources);
List<Resource> list = resources.getResources();
assertNotNull(list);
assertEquals(1, list.size());
Resource resource = list.get(0);
assertEquals(ResourceType.CAMERA_MOTION, resource.getType());

Boolean enabled = resource.getEnabled();
assertNotNull(enabled);
assertTrue(enabled);
assertEquals(OnOffType.ON, resource.getMotionState());
assertEquals(new DateTimeType("2020-04-01T20:04:30.395Z"),
resource.getMotionLastUpdatedState(ZoneId.of("UTC")));
}

void testFixedEffectSetter() {
Resource source;
Resource target;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"errors": [],
"data": [
{
"id": "00000000-0000-0000-0000-000000000005",
"id_v1": "/sensors/5",
"owner": {
"rid": "00000000-0000-0000-0000-000000000000",
"rtype": "device"
},
"enabled": true,
"motion": {
"motion": false,
"motion_valid": true,
"motion_report": {
"changed": "2020-04-01T20:04:30.395Z",
"motion": true
}
},
"sensitivity": {
"status": "set",
"sensitivity": 2,
"sensitivity_max": 4
},
"type": "camera_motion"
}
]
}
19 changes: 19 additions & 0 deletions bundles/org.openhab.binding.hue/src/test/resources/contact.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"errors": [
],
"data": [
{
"id": "bcaee909-1b37-454b-814d-9928776ad350",
"owner": {
"rid": "faac7940-a303-4e8e-9f06-075fffb7229c",
"rtype": "device"
},
"enabled": true,
"contact_report": {
"changed": "2023-10-10T19:10:55.919Z",
"state": "contact"
},
"type": "contact"
}
]
}
31 changes: 31 additions & 0 deletions bundles/org.openhab.binding.hue/src/test/resources/tamper.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"errors": [
],
"data": [
{
"id": "6c2ef541-fe03-4cae-ac60-3edcaa93b33e",
"owner": {
"rid": "faac7940-a303-4e8e-9f06-075fffb7229c",
"rtype": "device"
},
"tamper_reports": [
{
"changed": "1970-01-01T00:00:00.000Z",
"source": "battery_door",
"state": "not_tampered"
},
{
"changed": "2023-01-01T00:00:00.001Z",
"source": "battery_door",
"state": "not_tampered"
},
{
"changed": "2023-01-01T00:00:00.000Z",
"source": "battery_door",
"state": "tampered"
}
],
"type": "tamper"
}
]
}

0 comments on commit 089060e

Please sign in to comment.