Skip to content

Commit

Permalink
[Miele] Fixes openhab#8877
Browse files Browse the repository at this point in the history
Signed-off-by: Karel Goderis <karel.goderis@me.com>
  • Loading branch information
kgoderis committed Oct 27, 2020
1 parent ba5488f commit 5303278
Show file tree
Hide file tree
Showing 24 changed files with 173 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
public class MieleBindingConstants {

public static final String BINDING_ID = "miele";
public static final String APPLIANCE_ID = "uid";
public static final String DEVICE_CLASS = "dc";
public static final String HDM_LAN = "hdm:LAN:";
public static final String HDM_ZIGBEE = "hdm:ZigBee:";
public static final String PROTOCOL_PROPERTY_NAME = "protocol";

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_XGW3000 = new ThingTypeUID(BINDING_ID, "xgw3000");
Expand All @@ -45,8 +40,13 @@ public class MieleBindingConstants {
public static final ThingTypeUID THING_TYPE_COFFEEMACHINE = new ThingTypeUID(BINDING_ID, "coffeemachine");

// Bridge config properties
public static final String HOST = "ipAddress";
public static final String IP_ADDRESS = "ipAddress";
public static final String INTERFACE = "interface";
public static final String USER_NAME = "userName";
public static final String PASSWORD = "password";
public static final String HOST = "host";

// Thing config properties
public static final String APPLIANCE_ID = "uid";
public static final String PROTOCOL_NAME = "protocol";
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration,
}
throw new IllegalArgumentException(
"The thing type " + thingTypeUID + " is not supported by the miele binding.");

// TODO copy configuration.properties to properties
}

@Override
Expand Down Expand Up @@ -122,7 +124,7 @@ protected ThingHandler createHandler(Thing thing) {

private ThingUID getBridgeThingUID(ThingTypeUID thingTypeUID, ThingUID thingUID, Configuration configuration) {
if (thingUID == null) {
String hostID = (String) configuration.get(HOST);
String hostID = (String) configuration.get(IP_ADDRESS);
thingUID = new ThingUID(thingTypeUID, hostID);
}
return thingUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class MieleApplianceDiscoveryService extends AbstractDiscoveryService imp
private final Logger logger = LoggerFactory.getLogger(MieleApplianceDiscoveryService.class);

private static final int SEARCH_TIME = 60;
private static final String DEVICE_CLASS = "dc";

private MieleBridgeHandler mieleBridgeHandler;

Expand Down Expand Up @@ -88,6 +89,12 @@ protected synchronized void stopScan() {
removeOlderResults(getTimestampOfLastScan());
}

// @Override
// protected void startBackgroundDiscovery() {
// logger.debug("Starting background discovery for new appliances");
// startScan();
// }

@Override
public void onApplianceAdded(HomeDevice appliance) {
onApplianceAddedInternal(appliance);
Expand All @@ -99,7 +106,7 @@ private void onApplianceAddedInternal(HomeDevice appliance) {
ThingUID bridgeUID = mieleBridgeHandler.getThing().getUID();
Map<String, Object> properties = new HashMap<>(2);

properties.put(PROTOCOL_PROPERTY_NAME, appliance.getProtocol());
properties.put(PROTOCOL_NAME, appliance.getProtocol());
properties.put(APPLIANCE_ID, appliance.getApplianceId());

for (JsonElement dc : appliance.DeviceClasses) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public DiscoveryResult createResult(ServiceInfo service) {

InetAddress[] addresses = service.getInetAddresses();
if (addresses.length > 0 && addresses[0] != null) {
properties.put(MieleBindingConstants.HOST, addresses[0].getHostAddress());
properties.put(MieleBindingConstants.IP_ADDRESS, addresses[0].getHostAddress());

Socket socket = null;
try {
Expand All @@ -83,7 +83,8 @@ public DiscoveryResult createResult(ServiceInfo service) {
}

return DiscoveryResultBuilder.create(uid).withProperties(properties)
.withRepresentationProperty(uid.getId()).withLabel("Miele XGW3000 Gateway").build();
.withRepresentationProperty(MieleBindingConstants.IP_ADDRESS).withLabel("Miele XGW3000")
.build();
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package org.openhab.binding.miele.internal.handler;

import static org.openhab.binding.miele.internal.MieleBindingConstants.APPLIANCE_ID;
import static org.openhab.binding.miele.internal.MieleBindingConstants.*;

import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.ChannelUID;
Expand Down Expand Up @@ -45,6 +45,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {

String channelID = channelUID.getId();
String uid = (String) getThing().getConfiguration().getProperties().get(APPLIANCE_ID);
String protocol = (String) getThing().getConfiguration().getProperties().get(PROTOCOL_NAME);

CoffeeMachineChannelSelector selector = (CoffeeMachineChannelSelector) getValueSelectorFromChannelID(channelID);
JsonElement result = null;
Expand All @@ -54,9 +55,9 @@ public void handleCommand(ChannelUID channelUID, Command command) {
switch (selector) {
case SWITCH: {
if (command.equals(OnOffType.ON)) {
result = bridgeHandler.invokeOperation(uid, modelID, "switchOn");
result = bridgeHandler.invokeOperation(protocol, uid, modelID, "switchOn");
} else if (command.equals(OnOffType.OFF)) {
result = bridgeHandler.invokeOperation(uid, modelID, "switchOff");
result = bridgeHandler.invokeOperation(protocol, uid, modelID, "switchOff");
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package org.openhab.binding.miele.internal.handler;

import static org.openhab.binding.miele.internal.MieleBindingConstants.APPLIANCE_ID;
import static org.openhab.binding.miele.internal.MieleBindingConstants.*;

import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.ChannelUID;
Expand Down Expand Up @@ -46,6 +46,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {

String channelID = channelUID.getId();
String uid = (String) getThing().getConfiguration().getProperties().get(APPLIANCE_ID);
String protocol = (String) getThing().getConfiguration().getProperties().get(PROTOCOL_NAME);

DishwasherChannelSelector selector = (DishwasherChannelSelector) getValueSelectorFromChannelID(channelID);
JsonElement result = null;
Expand All @@ -55,9 +56,9 @@ public void handleCommand(ChannelUID channelUID, Command command) {
switch (selector) {
case SWITCH: {
if (command.equals(OnOffType.ON)) {
result = bridgeHandler.invokeOperation(uid, modelID, "start");
result = bridgeHandler.invokeOperation(protocol, uid, modelID, "start");
} else if (command.equals(OnOffType.OFF)) {
result = bridgeHandler.invokeOperation(uid, modelID, "stop");
result = bridgeHandler.invokeOperation(protocol, uid, modelID, "stop");
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package org.openhab.binding.miele.internal.handler;

import static org.openhab.binding.miele.internal.MieleBindingConstants.APPLIANCE_ID;
import static org.openhab.binding.miele.internal.MieleBindingConstants.*;

import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.ChannelUID;
Expand Down Expand Up @@ -45,6 +45,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {

String channelID = channelUID.getId();
String uid = (String) getThing().getConfiguration().getProperties().get(APPLIANCE_ID);
String protocol = (String) getThing().getConfiguration().getProperties().get(PROTOCOL_NAME);

FridgeFreezerChannelSelector selector = (FridgeFreezerChannelSelector) getValueSelectorFromChannelID(channelID);
JsonElement result = null;
Expand All @@ -54,17 +55,17 @@ public void handleCommand(ChannelUID channelUID, Command command) {
switch (selector) {
case SUPERCOOL: {
if (command.equals(OnOffType.ON)) {
result = bridgeHandler.invokeOperation(uid, modelID, "startSuperCooling");
result = bridgeHandler.invokeOperation(protocol, uid, modelID, "startSuperCooling");
} else if (command.equals(OnOffType.OFF)) {
result = bridgeHandler.invokeOperation(uid, modelID, "stopSuperCooling");
result = bridgeHandler.invokeOperation(protocol, uid, modelID, "stopSuperCooling");
}
break;
}
case SUPERFREEZE: {
if (command.equals(OnOffType.ON)) {
result = bridgeHandler.invokeOperation(uid, modelID, "startSuperFreezing");
result = bridgeHandler.invokeOperation(protocol, uid, modelID, "startSuperFreezing");
} else if (command.equals(OnOffType.OFF)) {
result = bridgeHandler.invokeOperation(uid, modelID, "stopSuperFreezing");
result = bridgeHandler.invokeOperation(protocol, uid, modelID, "stopSuperFreezing");
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package org.openhab.binding.miele.internal.handler;

import static org.openhab.binding.miele.internal.MieleBindingConstants.APPLIANCE_ID;
import static org.openhab.binding.miele.internal.MieleBindingConstants.*;

import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.ChannelUID;
Expand Down Expand Up @@ -45,6 +45,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {

String channelID = channelUID.getId();
String uid = (String) getThing().getConfiguration().getProperties().get(APPLIANCE_ID);
String protocol = (String) getThing().getConfiguration().getProperties().get(PROTOCOL_NAME);

FridgeChannelSelector selector = (FridgeChannelSelector) getValueSelectorFromChannelID(channelID);
JsonElement result = null;
Expand All @@ -54,15 +55,15 @@ public void handleCommand(ChannelUID channelUID, Command command) {
switch (selector) {
case SUPERCOOL: {
if (command.equals(OnOffType.ON)) {
result = bridgeHandler.invokeOperation(uid, modelID, "startSuperCooling");
result = bridgeHandler.invokeOperation(protocol, uid, modelID, "startSuperCooling");
} else if (command.equals(OnOffType.OFF)) {
result = bridgeHandler.invokeOperation(uid, modelID, "stopSuperCooling");
result = bridgeHandler.invokeOperation(protocol, uid, modelID, "stopSuperCooling");
}
break;
}
case START: {
if (command.equals(OnOffType.ON)) {
result = bridgeHandler.invokeOperation(uid, modelID, "start");
result = bridgeHandler.invokeOperation(protocol, uid, modelID, "start");
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package org.openhab.binding.miele.internal.handler;

import static org.openhab.binding.miele.internal.MieleBindingConstants.APPLIANCE_ID;
import static org.openhab.binding.miele.internal.MieleBindingConstants.*;

import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.ChannelUID;
Expand Down Expand Up @@ -45,6 +45,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {

String channelID = channelUID.getId();
String uid = (String) getThing().getConfiguration().getProperties().get(APPLIANCE_ID);
String protocol = (String) getThing().getConfiguration().getProperties().get(PROTOCOL_NAME);

HoodChannelSelector selector = (HoodChannelSelector) getValueSelectorFromChannelID(channelID);
JsonElement result = null;
Expand All @@ -54,15 +55,15 @@ public void handleCommand(ChannelUID channelUID, Command command) {
switch (selector) {
case LIGHT: {
if (command.equals(OnOffType.ON)) {
result = bridgeHandler.invokeOperation(uid, modelID, "startLighting");
result = bridgeHandler.invokeOperation(protocol, uid, modelID, "startLighting");
} else if (command.equals(OnOffType.OFF)) {
result = bridgeHandler.invokeOperation(uid, modelID, "stopLighting");
result = bridgeHandler.invokeOperation(protocol, uid, modelID, "stopLighting");
}
break;
}
case STOP: {
if (command.equals(OnOffType.ON)) {
result = bridgeHandler.invokeOperation(uid, modelID, "stop");
result = bridgeHandler.invokeOperation(protocol, uid, modelID, "stop");
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,11 @@ public void handleCommand(ChannelUID channelUID, Command command) {

@Override
public void onApplianceStateChanged(String UID, DeviceClassObject dco) {
String myUID = ((String) getThing().getProperties().get(PROTOCOL_PROPERTY_NAME))
+ (String) getThing().getConfiguration().getProperties().get(APPLIANCE_ID);
String uid = (String) getThing().getConfiguration().getProperties().get(APPLIANCE_ID);
String modelID = StringUtils.right(dco.DeviceClass,
dco.DeviceClass.length() - new String("com.miele.xgw3000.gateway.hdm.deviceclasses.Miele").length());

if (myUID.equals(UID)) {
if (uid.equals(UID)) {
if (modelID.equals(this.modelID)) {
for (JsonElement prop : dco.Properties.getAsJsonArray()) {
try {
Expand Down Expand Up @@ -177,10 +176,9 @@ public void onApplianceStateChanged(String UID, DeviceClassObject dco) {

@Override
public void onAppliancePropertyChanged(String UID, DeviceProperty dp) {
String myUID = ((String) getThing().getProperties().get(PROTOCOL_PROPERTY_NAME))
+ (String) getThing().getConfiguration().getProperties().get(APPLIANCE_ID);
String uid = (String) getThing().getConfiguration().getProperties().get(APPLIANCE_ID);

if (myUID.equals(UID)) {
if (uid.equals(UID)) {
try {
DeviceMetaData dmd = null;
if (dp.Metadata == null) {
Expand Down Expand Up @@ -209,7 +207,8 @@ public void onAppliancePropertyChanged(String UID, DeviceProperty dp) {
try {
selector = getValueSelectorFromMieleID(dp.Name);
} catch (Exception h) {
logger.trace("{} is not a valid channel for a {}", dp.Name, modelID);
logger.trace("{} is not a valid channel for a {}, its raw value would be '{}'", dp.Name, modelID,
dp.Value);
}

String dpValue = StringUtils.trim(StringUtils.strip(dp.Value));
Expand Down
Loading

0 comments on commit 5303278

Please sign in to comment.