Skip to content

Commit

Permalink
Merge branch hive/develop into hive/master.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbrownwsws committed May 17, 2020
1 parent 1da4bd8 commit 22f6333
Show file tree
Hide file tree
Showing 46 changed files with 1,257 additions and 760 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.hive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
<version>2.5.5-SNAPSHOT</version>
<version>2.5.6-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.binding.hive</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,11 @@ public final class HiveBindingConstants {
* The set of {@link ThingTypeUID}s that can be discovered
* (everything but accounts).
*/
// @formatter:off
public static final Set<ThingTypeUID> DISCOVERABLE_THING_TYPES_UIDS = Collections.unmodifiableSet(
SUPPORTED_THING_TYPES_UIDS.stream()
.filter(it -> it != THING_TYPE_ACCOUNT)
.collect(Collectors.toSet())
);
// @formatter:on

/* ######## Channel ids ######## */
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ public final class DefaultFeatureAttribute<T> implements SettableFeatureAttribut
private final @Nullable T targetValue;
private final T displayValue;
private final T reportedValue;
private final Instant reportReceivedTime;
private final Instant reportChangedTime;
private final @Nullable Instant reportReceivedTime;
private final @Nullable Instant reportChangedTime;

private DefaultFeatureAttribute(
final @Nullable T targetValue,
final T displayValue,
final T reportedValue,
final Instant reportChangedTime,
final Instant reportReceivedTime
final @Nullable Instant reportChangedTime,
final @Nullable Instant reportReceivedTime
) {
this.targetValue = targetValue;
this.displayValue = Objects.requireNonNull(displayValue);
this.reportedValue = Objects.requireNonNull(reportedValue);
this.reportChangedTime = Objects.requireNonNull(reportChangedTime);
this.reportReceivedTime = Objects.requireNonNull(reportReceivedTime);
this.reportChangedTime = reportChangedTime;
this.reportReceivedTime = reportReceivedTime;
}

@Override
Expand All @@ -61,12 +61,12 @@ public T getReportedValue() {
}

@Override
public Instant getReportReceivedTime() {
public @Nullable Instant getReportReceivedTime() {
return this.reportReceivedTime;
}

@Override
public Instant getReportChangedTime() {
public @Nullable Instant getReportChangedTime() {
return this.reportChangedTime;
}

Expand Down Expand Up @@ -126,28 +126,24 @@ public Builder<T> reportedValue(final T reportedValue) {
return this;
}

public Builder<T> reportReceivedTime(final Instant reportReceivedTime) {
this.reportReceivedTime = Objects.requireNonNull(reportReceivedTime);
public Builder<T> reportReceivedTime(final @Nullable Instant reportReceivedTime) {
this.reportReceivedTime = reportReceivedTime;

return this;
}

public Builder<T> reportChangedTime(final Instant reportChangedTime) {
this.reportChangedTime = Objects.requireNonNull(reportChangedTime);
public Builder<T> reportChangedTime(final @Nullable Instant reportChangedTime) {
this.reportChangedTime = reportChangedTime;

return this;
}

public DefaultFeatureAttribute<T> build() {
final @Nullable T displayValue = this.displayValue;
final @Nullable T reportedValue = this.reportedValue;
final @Nullable Instant reportReceivedTime = this.reportReceivedTime;
final @Nullable Instant reportChangedTime = this.reportChangedTime;

if (displayValue == null
|| reportedValue == null
|| reportReceivedTime == null
|| reportChangedTime == null
) {
throw new IllegalStateException(BuilderUtil.REQUIRED_ATTRIBUTE_NOT_SET_MESSAGE);
}
Expand All @@ -156,8 +152,8 @@ public DefaultFeatureAttribute<T> build() {
this.targetValue,
displayValue,
reportedValue,
reportChangedTime,
reportReceivedTime
this.reportChangedTime,
this.reportReceivedTime
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.time.Instant;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

/**
*
Expand All @@ -25,6 +26,6 @@
public interface FeatureAttribute<T> {
T getDisplayValue();
T getReportedValue();
Instant getReportReceivedTime();
Instant getReportChangedTime();
@Nullable Instant getReportReceivedTime();
@Nullable Instant getReportChangedTime();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,32 @@
*/
@NonNullByDefault
public final class FeatureAttributeFactory {
private static final String FEATURE_ATTRIBUTE_NULL_MESSAGE = "FeatureAttribute is unexpectedly null";

private FeatureAttributeFactory() {
throw new AssertionError();
}

private static <F> void applyNano1DtoFix(
final FeatureAttributeDto<F> dto
) {
// Try to fix the weirdness of the NANO1 hub
@Nullable F fixupValue = dto.targetValue;
if (dto.reportedValue == null && fixupValue != null) {
dto.reportedValue = fixupValue;
} else if (dto.reportedValue != null) {
fixupValue = dto.reportedValue;
} else {
throw new IllegalStateException("reportedValue is null and I cannot fix it");
}

if (dto.displayValue == null) {
if (fixupValue != null) {
dto.displayValue = fixupValue;
} else {
throw new IllegalStateException("displayValue is null and I cannot fix it");
}
}
}

private static <F, T> void buildFeatureAttribute(
final DefaultFeatureAttribute.Builder<T> featureAttributeBuilder,
final Adapter<F, T> adapter,
Expand All @@ -57,29 +77,29 @@ private static <F, T> void buildFeatureAttribute(
}
featureAttributeBuilder.reportedValue(adapter.apply(reportedValue));

if (reportChangedTime == null) {
throw new HiveClientResponseException("Report Changed Time is unexpectedly null.");
if (reportChangedTime != null) {
featureAttributeBuilder.reportChangedTime(reportChangedTime.asInstant());
}
featureAttributeBuilder.reportChangedTime(reportChangedTime.asInstant());

if (reportReceivedTime == null) {
throw new HiveClientResponseException("Reported Received Time is unexpectedly null.");
if (reportReceivedTime != null) {
featureAttributeBuilder.reportReceivedTime(reportReceivedTime.asInstant());
}
featureAttributeBuilder.reportReceivedTime(reportReceivedTime.asInstant());
}

public static <T> FeatureAttribute<T> getReadOnlyFromDto(final @Nullable FeatureAttributeDto<T> dto) throws HiveClientResponseException {
public static <T> @Nullable FeatureAttribute<T> getReadOnlyFromDto(final @Nullable FeatureAttributeDto<T> dto) throws HiveClientResponseException {
return getReadOnlyFromDtoWithAdapter(Adapter.identity(), dto);
}

public static <F, T> FeatureAttribute<T> getReadOnlyFromDtoWithAdapter(
public static <F, T> @Nullable FeatureAttribute<T> getReadOnlyFromDtoWithAdapter(
final Adapter<F, T> adapter,
final @Nullable FeatureAttributeDto<F> dto
) throws HiveClientResponseException {
if (dto == null) {
throw new HiveClientResponseException(FEATURE_ATTRIBUTE_NULL_MESSAGE);
return null;
}

applyNano1DtoFix(dto);

final DefaultFeatureAttribute.Builder<T> featureAttributeBuilder = DefaultFeatureAttribute.builder();

buildFeatureAttribute(
Expand All @@ -91,18 +111,20 @@ public static <F, T> FeatureAttribute<T> getReadOnlyFromDtoWithAdapter(
return featureAttributeBuilder.build();
}

public static <T> SettableFeatureAttribute<T> getSettableFromDto(final @Nullable FeatureAttributeDto<T> dto) throws HiveClientResponseException {
public static <T> @Nullable SettableFeatureAttribute<T> getSettableFromDto(final @Nullable FeatureAttributeDto<T> dto) throws HiveClientResponseException {
return getSettableFromDtoWithAdapter(Adapter.identity(), dto);
}

public static <F, T> SettableFeatureAttribute<T> getSettableFromDtoWithAdapter(
public static <F, T> @Nullable SettableFeatureAttribute<T> getSettableFromDtoWithAdapter(
final Adapter<F, T> adapter,
final @Nullable FeatureAttributeDto<F> dto
) throws HiveClientResponseException {
if (dto == null) {
throw new HiveClientResponseException(FEATURE_ATTRIBUTE_NULL_MESSAGE);
return null;
}

applyNano1DtoFix(dto);

final DefaultFeatureAttribute.Builder<T> featureAttributeBuilder = DefaultFeatureAttribute.builder();

buildFeatureAttribute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
*/
package org.openhab.binding.hive.internal.client;

import java.net.URI;

import org.eclipse.jdt.annotation.NonNullByDefault;

import java.net.URI;

/**
* Constants related to the Hive API.
*
Expand Down Expand Up @@ -71,9 +71,31 @@ private HiveApiConstants() {
public static final String ACTION_TYPE_GENERIC = "http://alertme.com/schema/json/configuration/configuration.device.action.generic.v1.json#";

/* Attribute Names */
public static final String ATTRIBUTE_NAME_AUTO_BOOST_V1_AUTO_BOOST_DURATION = "autoBoostDuration";
public static final String ATTRIBUTE_NAME_AUTO_BOOST_V1_AUTO_BOOST_TARGET_HEAT_TEMPERATURE = "autoBoostTargetHeatTemperature";
public static final String ATTRIBUTE_NAME_BATTERY_DEVICE_V1_BATTERY_LEVEL = "batteryLevel";
public static final String ATTRIBUTE_NAME_BATTERY_DEVICE_V1_BATTERY_STATE = "batteryState";
public static final String ATTRIBUTE_NAME_BATTERY_DEVICE_V1_BATTERY_VOLTAGE = "batteryVoltage";
public static final String ATTRIBUTE_NAME_BATTERY_DEVICE_V1_NOTIFICATION_STATE = "notificationState";
public static final String ATTRIBUTE_NAME_HEATING_THERMOSTAT_V1_OPERATING_MODE = "operatingMode";
public static final String ATTRIBUTE_NAME_HEATING_THERMOSTAT_V1_OPERATING_STATE = "operatingState";
public static final String ATTRIBUTE_NAME_HEATING_THERMOSTAT_V1_TEMPORARY_OPERATING_MODE_OVERRIDE = "temporaryOperatingModeOverride";
public static final String ATTRIBUTE_NAME_HEATING_THERMOSTAT_V1_TARGET_HEAT_TEMPERATURE = "targetHeatTemperature";
public static final String ATTRIBUTE_NAME_ON_OFF_DEVICE_V1_MODE = "mode";
public static final String ATTRIBUTE_NAME_WATER_HEATER_HEATING_OPERATING_MODE = "operatingMode";
public static final String ATTRIBUTE_NAME_TEMPERATURE_SENSOR_V1_TEMPERATURE = "temperature";
public static final String ATTRIBUTE_NAME_TRANSIENT_MODE_V1_ACTIONS = "actions";
public static final String ATTRIBUTE_NAME_TRANSIENT_MODE_V1_DURATION = "duration";
public static final String ATTRIBUTE_NAME_TRANSIENT_MODE_V1_IS_ENABLED = "isEnabled";
public static final String ATTRIBUTE_NAME_TRANSIENT_MODE_V1_START_DATETIME = "startDatetime";
public static final String ATTRIBUTE_NAME_TRANSIENT_MODE_V1_END_DATETIME = "endDatetime";
public static final String ATTRIBUTE_NAME_WATER_HEATER_V1_OPERATING_MODE = "operatingMode";
public static final String ATTRIBUTE_NAME_WATER_HEATER_V1_IS_ON = "isOn";
public static final String ATTRIBUTE_NAME_WATER_HEATER_V1_TEMPORARY_OPERATING_MODE_OVERRIDE = "temporaryOperatingModeOverride";
public static final String ATTRIBUTE_NAME_ZIGBEE_DEVICE_V1_EUI64 = "eui64";
public static final String ATTRIBUTE_NAME_ZIGBEE_DEVICE_V1_AVERAGE_LQI = "averageLQI";
public static final String ATTRIBUTE_NAME_ZIGBEE_DEVICE_V1_LAST_KNOWN_LQI = "lastKnownLQI";
public static final String ATTRIBUTE_NAME_ZIGBEE_DEVICE_V1_AVERAGE_RSSI = "averageRSSI";
public static final String ATTRIBUTE_NAME_ZIGBEE_DEVICE_V1_LAST_KNOWN_RSSI = "lastKnownRSSI";

/* Group IDs */
public static final String GROUP_ID_TRVS = "trvs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.net.URI;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand All @@ -32,6 +33,9 @@ final class JettyHiveApiRequestFactory implements HiveApiRequestFactory, Session
private static final String ACCESS_TOKEN_HEADER = "X-Omnia-Access-Token";
private static final String CLIENT_ID_HEADER = "X-Omnia-Client";

private static final long TIMEOUT_VALUE = 5;
private static final TimeUnit TIMEOUT_UNIT = TimeUnit.SECONDS;

private final HttpClient httpClient;
private final URI apiBasePath;
private final JsonService jsonService;
Expand Down Expand Up @@ -114,6 +118,11 @@ public HiveApiRequest newRequest(final URI endpointPath) {
request.header(ACCESS_TOKEN_HEADER, session.getSessionId().toString());
}

// Set a short timeout as the Hive API should respond very quickly.
// If a response is taking a long time something has gone wrong so we
// should abort and back off until things are back to normal.
request.timeout(TIMEOUT_VALUE, TIMEOUT_UNIT);

return new JettyHiveApiRequest(
this.jsonService,
request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public AttributeNameGsonAdapter() {
)
.add(
AttributeName.WATER_HEATER_HEATING_OPERATING_MODE,
HiveApiConstants.ATTRIBUTE_NAME_WATER_HEATER_HEATING_OPERATING_MODE
HiveApiConstants.ATTRIBUTE_NAME_WATER_HEATER_V1_OPERATING_MODE
)
.build());
}
Expand Down
Loading

0 comments on commit 22f6333

Please sign in to comment.