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

[ojelectronics] Initial contribution #7138

Merged
merged 11 commits into from
Jul 11, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

import javax.measure.quantity.Temperature;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.library.types.DateTimeType;
import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.OpenClosedType;
Expand All @@ -31,6 +33,7 @@
import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.RefreshType;
import org.openhab.binding.ojelectronics.internal.config.OJElectronicsThermostatConfiguration;
import org.openhab.binding.ojelectronics.internal.models.groups.Thermostat;

Expand All @@ -44,10 +47,12 @@
public class ThermostatHandler extends BaseThingHandler {

private final String serialNumber;
private @Nullable Thermostat currentThermostat;
private static final Map<Integer, String> REGULATION_MODES = createRegulationMap();
private final Map<String, Consumer<Thermostat>> CHANNEL_REFRESH_ACTION = createChannelRefreshActionMap();

/**
* Creates a new instance of {@link OJElectronicsThermostatHandler}
* Creates a new instance of {@link ThermostatHandler}
*
* @param thing Thing
*/
Expand All @@ -70,7 +75,12 @@ public String getSerialNumber() {
*/
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
// nothing do here
if (command instanceof RefreshType) {
final Thermostat thermostat = currentThermostat;
if (thermostat != null && CHANNEL_REFRESH_ACTION.containsKey(channelUID.getId())) {
CHANNEL_REFRESH_ACTION.get(channelUID.getId()).accept(thermostat);
}
}
}

/**
Expand All @@ -87,29 +97,67 @@ public void initialize() {
* @param thermostat thermostat values
*/
public void handleThermostatRefresh(Thermostat thermostat) {
updateState(BindingConstants.CHANNEL_OWD5_GROUPNAME, StringType.valueOf(thermostat.groupName));
updateState(BindingConstants.CHANNEL_OWD5_GROUPID, new DecimalType(thermostat.groupId));
updateState(BindingConstants.CHANNEL_OWD5_ONLINE,
thermostat.online ? OpenClosedType.OPEN : OpenClosedType.CLOSED);
updateState(BindingConstants.CHANNEL_OWD5_HEATING,
thermostat.heating ? OpenClosedType.OPEN : OpenClosedType.CLOSED);
updateState(BindingConstants.CHANNEL_OWD5_ROOMTEMPERATURE,
new QuantityType<Temperature>(thermostat.roomTemperature / (double) 100, SIUnits.CELSIUS));
updateState(BindingConstants.CHANNEL_OWD5_FLOORTEMPERATURE,
new QuantityType<Temperature>(thermostat.floorTemperature / (double) 100, SIUnits.CELSIUS));
updateState(BindingConstants.CHANNEL_OWD5_THERMOSTATNAME, StringType.valueOf(thermostat.thermostatName));
updateState(BindingConstants.CHANNEL_OWD5_REGULATIONMODE,
StringType.valueOf(getRegulationMode(thermostat.regulationMode)));
updateState(BindingConstants.CHANNEL_OWD5_COMFORTSETPOINT,
new QuantityType<Temperature>(thermostat.comfortSetpoint / (double) 100, SIUnits.CELSIUS));
updateState(BindingConstants.CHANNEL_OWD5_COMFORTENDTIME, new DateTimeType(
ZonedDateTime.ofInstant(thermostat.comfortEndTime.toInstant(), ZoneId.systemDefault())));
updateState(BindingConstants.CHANNEL_OWD5_BOOSTENDTIME,
new DateTimeType(ZonedDateTime.ofInstant(thermostat.boostEndTime.toInstant(), ZoneId.systemDefault())));
currentThermostat = thermostat;
CHANNEL_REFRESH_ACTION.forEach((channelUID, action) -> action.accept(thermostat));
}

private void updateManualSetpoint(Thermostat thermostat) {
updateState(BindingConstants.CHANNEL_OWD5_MANUALSETPOINT,
new QuantityType<Temperature>(thermostat.manualModeSetpoint / (double) 100, SIUnits.CELSIUS));
}

private void updateBoostEndTime(Thermostat thermostat) {
updateState(BindingConstants.CHANNEL_OWD5_BOOSTENDTIME,
new DateTimeType(ZonedDateTime.ofInstant(thermostat.boostEndTime.toInstant(), ZoneId.systemDefault())));
}

private void updateComfortEndTime(Thermostat thermostat) {
updateState(BindingConstants.CHANNEL_OWD5_COMFORTENDTIME, new DateTimeType(
ZonedDateTime.ofInstant(thermostat.comfortEndTime.toInstant(), ZoneId.systemDefault())));
}

private void updateComfortSetpoint(Thermostat thermostat) {
updateState(BindingConstants.CHANNEL_OWD5_COMFORTSETPOINT,
new QuantityType<Temperature>(thermostat.comfortSetpoint / (double) 100, SIUnits.CELSIUS));
}

private void updateRegulationMode(Thermostat thermostat) {
updateState(BindingConstants.CHANNEL_OWD5_REGULATIONMODE,
StringType.valueOf(getRegulationMode(thermostat.regulationMode)));
}

private void updateThermostatName(Thermostat thermostat) {
updateState(BindingConstants.CHANNEL_OWD5_THERMOSTATNAME, StringType.valueOf(thermostat.thermostatName));
}

private void updateFloorTemperature(Thermostat thermostat) {
updateState(BindingConstants.CHANNEL_OWD5_FLOORTEMPERATURE,
new QuantityType<Temperature>(thermostat.floorTemperature / (double) 100, SIUnits.CELSIUS));
}

private void updateRoomTemperature(Thermostat thermostat) {
updateState(BindingConstants.CHANNEL_OWD5_ROOMTEMPERATURE,
new QuantityType<Temperature>(thermostat.roomTemperature / (double) 100, SIUnits.CELSIUS));
}

private void updateHeating(Thermostat thermostat) {
updateState(BindingConstants.CHANNEL_OWD5_HEATING,
thermostat.heating ? OpenClosedType.OPEN : OpenClosedType.CLOSED);
}

private void updateOnline(Thermostat thermostat) {
updateState(BindingConstants.CHANNEL_OWD5_ONLINE,
thermostat.online ? OpenClosedType.OPEN : OpenClosedType.CLOSED);
}

private void updateGroupId(Thermostat thermostat) {
updateState(BindingConstants.CHANNEL_OWD5_GROUPID, new DecimalType(thermostat.groupId));
}

private void updateGroupName(Thermostat thermostat) {
updateState(BindingConstants.CHANNEL_OWD5_GROUPNAME, StringType.valueOf(thermostat.groupName));
}

private String getRegulationMode(int regulationMode) {
return REGULATION_MODES.get(regulationMode);
}
Expand All @@ -125,4 +173,21 @@ private static HashMap<Integer, String> createRegulationMap() {
map.put(9, "Eco");
return map;
};

private HashMap<String, Consumer<Thermostat>> createChannelRefreshActionMap() {
HashMap<String, Consumer<Thermostat>> map = new HashMap<String, Consumer<Thermostat>>();
map.put(BindingConstants.CHANNEL_OWD5_GROUPNAME, this::updateGroupName);
map.put(BindingConstants.CHANNEL_OWD5_GROUPID, this::updateGroupId);
map.put(BindingConstants.CHANNEL_OWD5_ONLINE, this::updateOnline);
map.put(BindingConstants.CHANNEL_OWD5_HEATING, this::updateHeating);
map.put(BindingConstants.CHANNEL_OWD5_ROOMTEMPERATURE, this::updateRoomTemperature);
map.put(BindingConstants.CHANNEL_OWD5_FLOORTEMPERATURE, this::updateFloorTemperature);
map.put(BindingConstants.CHANNEL_OWD5_THERMOSTATNAME, this::updateThermostatName);
map.put(BindingConstants.CHANNEL_OWD5_REGULATIONMODE, this::updateRegulationMode);
map.put(BindingConstants.CHANNEL_OWD5_COMFORTSETPOINT, this::updateComfortSetpoint);
map.put(BindingConstants.CHANNEL_OWD5_COMFORTENDTIME, this::updateComfortEndTime);
map.put(BindingConstants.CHANNEL_OWD5_BOOSTENDTIME, this::updateBoostEndTime);
map.put(BindingConstants.CHANNEL_OWD5_MANUALSETPOINT, this::updateManualSetpoint);
return map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public void start(String sessionId, BiConsumer<@Nullable GroupContentResponseMod
this.sessionId = sessionId;
long refreshTime = config.refreshDelayInSeconds;
scheduler = schedulerService.scheduleWithFixedDelay(this::refresh, refreshTime, refreshTime, TimeUnit.SECONDS);
refresh();
destroyed = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ channel-type.ojelectronics.online.label = Ist Online
channel-type.ojelectronics.heating.label = Heizt
channel-type.ojelectronics.thermostatName.label = Name des Thermostats
channel-type.ojelectronics.regulationMode.label = Regelungsmodus
channel-type.ojelectronics.regulationMode.state.option.auto = Automatisch
channel-type.ojelectronics.regulationMode.state.option.comfort = Komfort
channel-type.ojelectronics.regulationMode.state.option.manual = Manuell
channel-type.ojelectronics.regulationMode.state.option.vacation = Urlaub
channel-type.ojelectronics.regulationMode.state.option.frostProtection = Frostschutz
channel-type.ojelectronics.regulationMode.state.option.boost = Boost
channel-type.ojelectronics.regulationMode.state.option.eco = Spar
channel-type.ojelectronics.comfortSetpoint.label = Komfort-Sollwert
channel-type.ojelectronics.comfortEndTime.label = Komfort-Endzeit
channel-type.ojelectronics.boostEndTime.label = Boost Endzeit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@
<label>Regulation Mode</label>
<state readOnly="true">
<options>
<option value="Auto">Auto</option>
<option value="Comfort">Comfort</option>
<option value="Manual">Manual</option>
<option value="Vacation">Vacation</option>
<option value="Frost Protection">Frost Protection</option>
<option value="Boost">Boost</option>
<option value="Eco">Eco</option>
<option value="auto">Auto</option>
EvilPingu marked this conversation as resolved.
Show resolved Hide resolved
<option value="comfort">Comfort</option>
<option value="manual">Manual</option>
<option value="vacation">Vacation</option>
<option value="frostProtection">Frost Protection</option>
<option value="boost">Boost</option>
<option value="eco">Eco</option>
</options>
</state>
</channel-type>
Expand Down