Skip to content

Commit

Permalink
openhab#14 Use QuantityType for power and energy consumption of the i…
Browse files Browse the repository at this point in the history
…n-wall switch handler

Signed-off-by: Christian Oeing <[email protected]>
  • Loading branch information
coeing committed Nov 18, 2020
1 parent 9396b78 commit 21023f5
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@

import java.util.Arrays;

import javax.measure.quantity.Energy;
import javax.measure.quantity.Power;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.boschshc.internal.devices.BoschSHCHandler;
import org.openhab.binding.boschshc.internal.devices.inwallswitch.dto.PowerMeterState;
import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
import org.openhab.binding.boschshc.internal.services.powerswitch.PowerSwitchService;
import org.openhab.binding.boschshc.internal.services.powerswitch.PowerSwitchState;
import org.openhab.binding.boschshc.internal.services.powerswitch.dto.PowerSwitchServiceState;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.types.Command;
Expand All @@ -42,7 +46,7 @@
@NonNullByDefault
public class BoschInWallSwitchHandler extends BoschSHCHandler {

private PowerSwitchService powerSwitchService;
private final PowerSwitchService powerSwitchService;

public BoschInWallSwitchHandler(Thing thing) {
super(thing);
Expand Down Expand Up @@ -92,8 +96,9 @@ void updatePowerMeterState(PowerMeterState state) {
logger.debug("Parsed power meter state of {}: energy {} - power {}", this.getBoschID(), state.energyConsumption,
state.energyConsumption);

updateState(CHANNEL_POWER_CONSUMPTION, new DecimalType(state.powerConsumption));
updateState(CHANNEL_ENERGY_CONSUMPTION, new DecimalType(state.energyConsumption));
updateState(CHANNEL_POWER_CONSUMPTION, new QuantityType<Power>(state.powerConsumption, SmartHomeUnits.WATT));
updateState(CHANNEL_ENERGY_CONSUMPTION,
new QuantityType<Energy>(state.energyConsumption, SmartHomeUnits.WATT_HOUR));
}

/**
Expand Down

0 comments on commit 21023f5

Please sign in to comment.