Skip to content

Commit

Permalink
Merge branch hive/develop into hive/master
Browse files Browse the repository at this point in the history
- Fix Transient Heating Actions bug
- Refactor lots of classes to make them immutable.
  • Loading branch information
rbrownwsws committed Apr 24, 2020
1 parent 1e97e8e commit 6d2432b
Show file tree
Hide file tree
Showing 52 changed files with 2,878 additions and 931 deletions.
3 changes: 1 addition & 2 deletions 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.4-SNAPSHOT</version>
<version>2.5.5-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.binding.hive</artifactId>
Expand Down Expand Up @@ -78,5 +78,4 @@
</plugin>
</plugins>
</reporting>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -51,59 +51,16 @@
@NonNullByDefault
@Component(configurationPid = "binding.hive", service = ThingHandlerFactory.class)
public final class HiveHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingHandlerStrategy> STRATEGIES_BOILER_MODULE = Collections.unmodifiableSet(Stream.of(
PhysicalDeviceHandlerStrategy.getInstance(),
ZigbeeDeviceHandlerStrategy.getInstance()
).collect(Collectors.toSet()));

private static final Set<ThingHandlerStrategy> STRATEGIES_HEATING = Collections.unmodifiableSet(Stream.of(
AutoBoostHandlerStrategy.getInstance(),
BoostTimeRemainingHandlerStrategy.getInstance(),
HeatingThermostatHandlerStrategy.getInstance(),
OnOffDeviceHandlerStrategy.getInstance(),
TemperatureSensorHandlerStrategy.getInstance(),
TransientModeHandlerStrategy.getInstance(),
HeatingTransientModeHandlerStrategy.getInstance(),
HeatingThermostatEasyHandlerStrategy.getInstance()
).collect(Collectors.toSet()));

private static final Set<ThingHandlerStrategy> STRATEGIES_HOT_WATER = Collections.unmodifiableSet(Stream.of(
BoostTimeRemainingHandlerStrategy.getInstance(),
OnOffDeviceHandlerStrategy.getInstance(),
TransientModeHandlerStrategy.getInstance(),
WaterHeaterHandlerStrategy.getInstance(),
WaterHeaterEasyHandlerStrategy.getInstance()
).collect(Collectors.toSet()));

private static final Set<ThingHandlerStrategy> STRATEGIES_HUB = Collections.unmodifiableSet(Stream.of(
PhysicalDeviceHandlerStrategy.getInstance()
).collect(Collectors.toSet()));

private static final Set<ThingHandlerStrategy> STRATEGIES_THERMOSTAT = Collections.unmodifiableSet(Stream.of(
BatteryDeviceHandlerStrategy.getInstance(),
PhysicalDeviceHandlerStrategy.getInstance(),
ZigbeeDeviceHandlerStrategy.getInstance()
).collect(Collectors.toSet()));

private static final Set<ThingHandlerStrategy> STRATEGIES_TRV_GROUP = Collections.unmodifiableSet(Stream.of(
BoostTimeRemainingHandlerStrategy.getInstance(),
HeatingThermostatHandlerStrategy.getInstance(),
OnOffDeviceHandlerStrategy.getInstance(),
TemperatureSensorHandlerStrategy.getInstance(),
TransientModeHandlerStrategy.getInstance(),
HeatingTransientModeHandlerStrategy.getInstance(),
HeatingThermostatEasyHandlerStrategy.getInstance()
).collect(Collectors.toSet()));

private static final Set<ThingHandlerStrategy> STRATEGIES_TRV = Collections.unmodifiableSet(Stream.of(
BatteryDeviceHandlerStrategy.getInstance(),
PhysicalDeviceHandlerStrategy.getInstance(),
TemperatureSensorHandlerStrategy.getInstance(),
ZigbeeDeviceHandlerStrategy.getInstance()
).collect(Collectors.toSet()));

private final Logger logger = LoggerFactory.getLogger(HiveHandlerFactory.class);

private final Set<ThingHandlerStrategy> strategiesForBoilerModule;
private final Set<ThingHandlerStrategy> strategiesForHeating;
private final Set<ThingHandlerStrategy> strategiesForHotWater;
private final Set<ThingHandlerStrategy> strategiesForHub;
private final Set<ThingHandlerStrategy> strategiesForThermostat;
private final Set<ThingHandlerStrategy> strategiesForTrvGroup;
private final Set<ThingHandlerStrategy> strategiesForTrv;

private final Map<ThingUID, ServiceRegistration<?>> discoveryServices = new HashMap<>();

private final HttpClient httpClient;
Expand All @@ -123,6 +80,73 @@ public HiveHandlerFactory(@Reference final HttpClientFactory httpClientFactory)
// Keep a copy of HttpClient so we can clean up later
this.httpClient = httpClient;
this.hiveClientFactory = new DefaultHiveClientFactory(httpClient);

// Create all the ThingHandlerStrategies we will need.
final AutoBoostHandlerStrategy autoBoostHandlerStrategy = new AutoBoostHandlerStrategy();
final BatteryDeviceHandlerStrategy batteryDeviceHandlerStrategy = new BatteryDeviceHandlerStrategy();
final BoostTimeRemainingHandlerStrategy boostTimeRemainingHandlerStrategy = new BoostTimeRemainingHandlerStrategy();
final HeatingThermostatEasyHandlerStrategy heatingThermostatEasyHandlerStrategy = new HeatingThermostatEasyHandlerStrategy();
final HeatingThermostatHandlerStrategy heatingThermostatHandlerStrategy = new HeatingThermostatHandlerStrategy();
final HeatingTransientModeHandlerStrategy heatingTransientModeHandlerStrategy = new HeatingTransientModeHandlerStrategy();
final OnOffDeviceHandlerStrategy onOffDeviceHandlerStrategy = new OnOffDeviceHandlerStrategy();
final PhysicalDeviceHandlerStrategy physicalDeviceHandlerStrategy = new PhysicalDeviceHandlerStrategy();
final TemperatureSensorHandlerStrategy temperatureSensorHandlerStrategy = new TemperatureSensorHandlerStrategy();
final TransientModeHandlerStrategy transientModeHandlerStrategy = new TransientModeHandlerStrategy();
final WaterHeaterEasyHandlerStrategy waterHeaterEasyHandlerStrategy = new WaterHeaterEasyHandlerStrategy();
final WaterHeaterHandlerStrategy waterHeaterHandlerStrategy = new WaterHeaterHandlerStrategy();
final ZigbeeDeviceHandlerStrategy zigbeeDeviceHandlerStrategy = new ZigbeeDeviceHandlerStrategy();

// Create the sets of ThingHandlerStrategies needed for each kind of thing.
this.strategiesForBoilerModule = Collections.unmodifiableSet(Stream.of(
physicalDeviceHandlerStrategy,
zigbeeDeviceHandlerStrategy
).collect(Collectors.toSet()));

this.strategiesForHeating = Collections.unmodifiableSet(Stream.of(
autoBoostHandlerStrategy,
boostTimeRemainingHandlerStrategy,
heatingThermostatHandlerStrategy,
onOffDeviceHandlerStrategy,
temperatureSensorHandlerStrategy,
transientModeHandlerStrategy,
heatingTransientModeHandlerStrategy,
heatingThermostatEasyHandlerStrategy
).collect(Collectors.toSet()));

this.strategiesForHotWater = Collections.unmodifiableSet(Stream.of(
boostTimeRemainingHandlerStrategy,
onOffDeviceHandlerStrategy,
transientModeHandlerStrategy,
waterHeaterHandlerStrategy,
waterHeaterEasyHandlerStrategy
).collect(Collectors.toSet()));

this.strategiesForHub = Collections.unmodifiableSet(Stream.of(
physicalDeviceHandlerStrategy
).collect(Collectors.toSet()));

this.strategiesForThermostat = Collections.unmodifiableSet(Stream.of(
batteryDeviceHandlerStrategy,
physicalDeviceHandlerStrategy,
zigbeeDeviceHandlerStrategy
).collect(Collectors.toSet()));

this.strategiesForTrvGroup = Collections.unmodifiableSet(Stream.of(
boostTimeRemainingHandlerStrategy,
heatingThermostatHandlerStrategy,
onOffDeviceHandlerStrategy,
temperatureSensorHandlerStrategy,
transientModeHandlerStrategy,
heatingTransientModeHandlerStrategy,
heatingThermostatEasyHandlerStrategy
).collect(Collectors.toSet()));

this.strategiesForTrv = Collections.unmodifiableSet(Stream.of(
batteryDeviceHandlerStrategy,
physicalDeviceHandlerStrategy,
temperatureSensorHandlerStrategy,
zigbeeDeviceHandlerStrategy
).collect(Collectors.toSet()));
}

@Override
Expand Down Expand Up @@ -177,19 +201,19 @@ public boolean supportsThingType(final ThingTypeUID thingTypeUID) {

return handler;
} else if (HiveBindingConstants.THING_TYPE_BOILER_MODULE.equals(thingTypeUID)) {
return new DefaultHiveThingHandler(thing, STRATEGIES_BOILER_MODULE);
return new DefaultHiveThingHandler(thing, this.strategiesForBoilerModule);
} else if (HiveBindingConstants.THING_TYPE_HEATING.equals(thingTypeUID)) {
return new DefaultHiveThingHandler(thing, STRATEGIES_HEATING);
return new DefaultHiveThingHandler(thing, this.strategiesForHeating);
} else if (HiveBindingConstants.THING_TYPE_HOT_WATER.equals(thingTypeUID)) {
return new DefaultHiveThingHandler(thing, STRATEGIES_HOT_WATER);
return new DefaultHiveThingHandler(thing, this.strategiesForHotWater);
} else if (HiveBindingConstants.THING_TYPE_HUB.equals(thingTypeUID)) {
return new DefaultHiveThingHandler(thing, STRATEGIES_HUB);
return new DefaultHiveThingHandler(thing, this.strategiesForHub);
} else if (HiveBindingConstants.THING_TYPE_THERMOSTAT.equals(thingTypeUID)) {
return new DefaultHiveThingHandler(thing, STRATEGIES_THERMOSTAT);
return new DefaultHiveThingHandler(thing, this.strategiesForThermostat);
} else if (HiveBindingConstants.THING_TYPE_TRV.equals(thingTypeUID)) {
return new DefaultHiveThingHandler(thing, STRATEGIES_TRV);
return new DefaultHiveThingHandler(thing, this.strategiesForTrv);
} else if (HiveBindingConstants.THING_TYPE_TRV_GROUP.equals(thingTypeUID)) {
return new DefaultHiveThingHandler(thing, STRATEGIES_TRV_GROUP);
return new DefaultHiveThingHandler(thing, this.strategiesForTrvGroup);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (c) 2010-2020 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.hive.internal.client;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
*
*
* @author Ross Brown - Initial contribution
*/
@NonNullByDefault
public final class BuilderUtil {
public static final String REQUIRED_ATTRIBUTE_NOT_SET_MESSAGE = "Required attributes have not been set";

private BuilderUtil() {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/**
* Copyright (c) 2010-2020 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.hive.internal.client;

import java.time.Instant;
import java.util.Objects;

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

/**
*
*
* @author Ross Brown - Initial contribution
*/
@NonNullByDefault
public final class DefaultFeatureAttribute<T> implements SettableFeatureAttribute<T> {
private final @Nullable T targetValue;
private final T displayValue;
private final T reportedValue;
private final Instant reportReceivedTime;
private final Instant reportChangedTime;

private DefaultFeatureAttribute(
final @Nullable T targetValue,
final T displayValue,
final T reportedValue,
final Instant reportChangedTime,
final 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);
}

@Override
public @Nullable T getTargetValue() {
return this.targetValue;
}

@Override
public T getDisplayValue() {
return this.displayValue;
}

@Override
public T getReportedValue() {
return this.reportedValue;
}

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

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

public static <T> Builder<T> builder() {
return new Builder<>();
}

public static final class Builder<T> {
private @Nullable T targetValue = null;
private @Nullable T displayValue;
private @Nullable T reportedValue;
private @Nullable Instant reportReceivedTime;
private @Nullable Instant reportChangedTime;

public Builder<T> from(final SettableFeatureAttribute<T> featureAttribute) {
Objects.requireNonNull(featureAttribute);

return this.targetValue(featureAttribute.getTargetValue())
.displayValue(featureAttribute.getDisplayValue())
.reportedValue(featureAttribute.getReportedValue())
.reportReceivedTime(featureAttribute.getReportReceivedTime())
.reportChangedTime(featureAttribute.getReportChangedTime());
}

public Builder<T> from(final FeatureAttribute<T> featureAttribute) {
Objects.requireNonNull(featureAttribute);

return this.displayValue(featureAttribute.getDisplayValue())
.reportedValue(featureAttribute.getReportedValue())
.reportReceivedTime(featureAttribute.getReportReceivedTime())
.reportChangedTime(featureAttribute.getReportChangedTime());
}

public Builder<T> targetValue(final @Nullable T targetValue) {
this.targetValue = targetValue;

return this;
}

public Builder<T> displayValue(final T displayValue) {
this.displayValue = Objects.requireNonNull(displayValue);

return this;
}

public Builder<T> reportedValue(final T reportedValue) {
this.reportedValue = Objects.requireNonNull(reportedValue);

return this;
}

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

return this;
}

public Builder<T> reportChangedTime(final Instant reportChangedTime) {
this.reportChangedTime = Objects.requireNonNull(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);
}

return new DefaultFeatureAttribute<>(
this.targetValue,
displayValue,
reportedValue,
reportChangedTime,
reportReceivedTime
);
}
}
}
Loading

0 comments on commit 6d2432b

Please sign in to comment.