Skip to content

Commit

Permalink
[innogysmarthome] Fix Dimmer / Rollershutter / Gen 1 devices and Push…
Browse files Browse the repository at this point in the history
…button (#6721)

* [innogysmarthome] Fix "updateAvailable" for Gen 1 devices

Closes #6613

Signed-off-by: Hilbrand Bouwkamp <[email protected]>

* [innogysmarthome] Don't set state twice

Both dimmer and rollershutter set first the state as ONOFF and then as PercentType. It should set only one time because the percentage is the value actual wanted.

Closes #6610

Signed-off-by: Hilbrand Bouwkamp <[email protected]>

* [innogysmarthome] Improved handling pushbutton

Not all devices send same push button events. Some send 2 (StateChanged and ButtonPressed) others only 1 (StateChanged).
When ButtonPressed is send the StateChanged doesn't contain lastPressedButtonIndex. So in that case we ignore the StateChanged event.
The previous implementation assumed type was also always present, but that is not the case so it can't be used as an check.

Closes #6624

Signed-off-by: Hilbrand Bouwkamp <[email protected]>
  • Loading branch information
Hilbrand authored and J-N-K committed Jan 1, 2020
1 parent 22812f7 commit ddebca0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public class State {
private DoubleState wHRating;

/** SHC device states */
private StringState updateAvailable;
// Removed updateAvailable because it is different between version 1 and 2 devices and not used anyway
// Related to openhab-addons #6613
// private StringState updateAvailable

private DateTimeState lastReboot;

Expand Down Expand Up @@ -174,20 +176,6 @@ public void setWHRating(DoubleState wHRating) {
this.wHRating = wHRating;
}

/**
* @return the updateAvailable
*/
public StringState getUpdateAvailable() {
return updateAvailable;
}

/**
* @param updateAvailable the updateAvailable to set
*/
public void setUpdateAvailable(StringState updateAvailable) {
this.updateAvailable = updateAvailable;
}

/**
* @return the lastReboot
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.time.format.FormatStyle;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down Expand Up @@ -389,7 +390,9 @@ public void onDeviceStateChanged(final Device device) {
}

// CAPABILITY STATES
for (final Capability c : device.getCapabilityMap().values()) {
for (final Entry<String, Capability> entry : device.getCapabilityMap().entrySet()) {
final Capability c = entry.getValue();

logger.debug("->capability:{} ({}/{})", c.getId(), c.getType(), c.getName());

if (c.getCapabilityState() == null) {
Expand Down Expand Up @@ -420,11 +423,6 @@ public void onDeviceStateChanged(final Device device) {
final Integer dimLevel = c.getCapabilityState().getDimmerActuatorState();
if (dimLevel != null) {
logger.debug("Dimlevel state {}", dimLevel);
if (dimLevel > 0) {
updateState(CHANNEL_DIMMER, OnOffType.ON);
} else {
updateState(CHANNEL_DIMMER, OnOffType.OFF);
}
updateState(CHANNEL_DIMMER, new PercentType(dimLevel));
} else {
logger.debug("State for {} is STILL NULL!! cstate-id: {}, c-id: {}", c.getType(),
Expand All @@ -436,11 +434,6 @@ public void onDeviceStateChanged(final Device device) {
if (rollerShutterLevel != null) {
rollerShutterLevel = invertValueIfConfigured(CHANNEL_ROLLERSHUTTER, rollerShutterLevel);
logger.debug("RollerShutterlevel state {}", rollerShutterLevel);
if (rollerShutterLevel > 0) {
updateState(CHANNEL_ROLLERSHUTTER, UpDownType.DOWN);
} else {
updateState(CHANNEL_ROLLERSHUTTER, UpDownType.UP);
}
updateState(CHANNEL_ROLLERSHUTTER, new PercentType(rollerShutterLevel));
} else {
logger.debug("State for {} is STILL NULL!! cstate-id: {}, c-id: {}", c.getType(),
Expand Down Expand Up @@ -822,20 +815,24 @@ public void onDeviceStateChanged(final Device changedDevice, final Event event)

// PushButtonSensor
} else if (capability.isTypePushButtonSensor()) {
// if the same button is pressed more than once
// the buttonIndex and LastKeyPressCounter come with two events
// updates should only do when arriving value
// Some devices send both StateChanged and ButtonPressed. But only one should be handled.
// If ButtonPressed is send lastPressedButtonIndex is not set in StateChanged so ignore
// StateChanged.
// type is also not always present if null will be interpreted as a normal key press.
final Integer tmpButtonIndex = event.getProperties().getLastPressedButtonIndex();
final Integer tmpLastKeyPressCounter = event.getProperties().getLastKeyPressCounter();
final String lastKeyPressType = event.getProperties().getLastKeyPressType();
if (tmpButtonIndex != null && lastKeyPressType != null) {

if (tmpButtonIndex != null) {
capabilityState.setPushButtonSensorButtonIndexState(tmpButtonIndex);
capabilityState.setPushButtonSensorButtonIndexType(lastKeyPressType);
}
if (tmpLastKeyPressCounter != null) {
capabilityState.setPushButtonSensorCounterState(tmpLastKeyPressCounter);
capabilityState
.setPushButtonSensorButtonIndexType(event.getProperties().getLastKeyPressType());

final Integer tmpLastKeyPressCounter = event.getProperties().getLastKeyPressCounter();

if (tmpLastKeyPressCounter != null) {
capabilityState.setPushButtonSensorCounterState(tmpLastKeyPressCounter);
}
deviceChanged = true;
}
deviceChanged = true;

// EnergyConsumptionSensor
} else if (capability.isTypeEnergyConsumptionSensor()) {
Expand Down

0 comments on commit ddebca0

Please sign in to comment.