Skip to content

Commit

Permalink
Consolidate properties for compliance. (openhab#11997)
Browse files Browse the repository at this point in the history
Fixes openhab#11996

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
  • Loading branch information
jlaur authored and andan67 committed Nov 5, 2022
1 parent 28e0be7 commit 1c88350
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ public class MieleBindingConstants {

public static final String BINDING_ID = "miele";
public static final String APPLIANCE_ID = "uid";
public static final String DEVICE_CLASS = "deviceClass";
public static final String MODEL_PROPERTY_NAME = "model";
public static final String PROTOCOL_ADAPTER_PROPERTY_NAME = "protocolAdapter";
public static final String CONNECTION_TYPE_PROPERTY_NAME = "connectionType";

// Properties
public static final String PROPERTY_DEVICE_CLASS = "deviceClass";
public static final String PROPERTY_PROTOCOL_ADAPTER = "protocolAdapter";
public static final String PROPERTY_CONNECTION_TYPE = "connectionType";
public static final String PROPERTY_CONNECTION_BAUD_RATE = "connectionBaudRate";

// JSON-RPC property names
public static final String SERIAL_NUMBER_PROPERTY_NAME = "serialNumber";
public static final String EXTENDED_DEVICE_STATE_PROPERTY_NAME = "extendedDeviceState";
public static final String STATE_PROPERTY_NAME = "state";
public static final String PROGRAM_ID_PROPERTY_NAME = "programId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openhab.core.config.discovery.AbstractDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.slf4j.Logger;
Expand Down Expand Up @@ -96,24 +97,30 @@ private void onApplianceAddedInternal(HomeDevice appliance) {
ThingUID thingUID = getThingUID(appliance);
if (thingUID != null) {
ThingUID bridgeUID = mieleBridgeHandler.getThing().getUID();
Map<String, Object> properties = new HashMap<>(2);
Map<String, Object> properties = new HashMap<>(9);

FullyQualifiedApplianceIdentifier applianceIdentifier = appliance.getApplianceIdentifier();
properties.put(MODEL_PROPERTY_NAME, appliance.getApplianceModel());
properties.put(Thing.PROPERTY_VENDOR, appliance.Vendor);
properties.put(Thing.PROPERTY_MODEL_ID, appliance.getApplianceModel());
properties.put(Thing.PROPERTY_SERIAL_NUMBER, appliance.getSerialNumber());
properties.put(Thing.PROPERTY_FIRMWARE_VERSION, appliance.getFirmwareVersion());
properties.put(PROPERTY_PROTOCOL_ADAPTER, appliance.ProtocolAdapterName);
properties.put(APPLIANCE_ID, applianceIdentifier.getApplianceId());
String deviceClass = appliance.getDeviceClass();
if (deviceClass != null) {
properties.put(DEVICE_CLASS, deviceClass);
properties.put(PROPERTY_DEVICE_CLASS, deviceClass);
}
properties.put(PROTOCOL_ADAPTER_PROPERTY_NAME, appliance.ProtocolAdapterName);
properties.put(APPLIANCE_ID, applianceIdentifier.getApplianceId());
properties.put(SERIAL_NUMBER_PROPERTY_NAME, appliance.getSerialNumber());
String connectionType = appliance.getConnectionType();
if (connectionType != null) {
properties.put(CONNECTION_TYPE_PROPERTY_NAME, connectionType);
properties.put(PROPERTY_CONNECTION_TYPE, connectionType);
}
String connectionBaudRate = appliance.getConnectionBaudRate();
if (connectionBaudRate != null) {
properties.put(PROPERTY_CONNECTION_BAUD_RATE, connectionBaudRate);
}

DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties)
.withBridge(bridgeUID).withLabel((String) properties.get(DEVICE_CLASS))
.withBridge(bridgeUID).withLabel(deviceClass != null ? deviceClass : appliance.getApplianceModel())
.withRepresentationProperty(APPLIANCE_ID).build();

thingDiscovered(discoveryResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ protected void onAppliancePropertyChanged(DeviceProperty dp) {
metaDataCache.put(new StringBuilder().append(dp.Name).toString().trim(), metadata);
}

if (dp.Name.equals(EXTENDED_DEVICE_STATE_PROPERTY_NAME)) {
if (EXTENDED_DEVICE_STATE_PROPERTY_NAME.equals(dp.Name)) {
if (!dp.Value.isEmpty()) {
byte[] extendedStateBytes = DeviceUtil.stringToBytes(dp.Value);
logger.trace("Extended device state for {}: {}", getThing().getUID(),
Expand Down Expand Up @@ -350,16 +350,22 @@ public void onApplianceAdded(HomeDevice appliance) {
if (applianceId.equals(applianceIdentifier.getApplianceId())) {
@NonNull
Map<@NonNull String, @NonNull String> properties = editProperties();
properties.put(MODEL_PROPERTY_NAME, appliance.getApplianceModel());
properties.put(Thing.PROPERTY_VENDOR, appliance.Vendor);
properties.put(Thing.PROPERTY_MODEL_ID, appliance.getApplianceModel());
properties.put(Thing.PROPERTY_SERIAL_NUMBER, appliance.getSerialNumber());
properties.put(Thing.PROPERTY_FIRMWARE_VERSION, appliance.getFirmwareVersion());
properties.put(PROPERTY_PROTOCOL_ADAPTER, appliance.ProtocolAdapterName);
String deviceClass = appliance.getDeviceClass();
if (deviceClass != null) {
properties.put(DEVICE_CLASS, deviceClass);
properties.put(PROPERTY_DEVICE_CLASS, deviceClass);
}
properties.put(PROTOCOL_ADAPTER_PROPERTY_NAME, appliance.ProtocolAdapterName);
properties.put(SERIAL_NUMBER_PROPERTY_NAME, appliance.getSerialNumber());
String connectionType = appliance.getConnectionType();
if (connectionType != null) {
properties.put(CONNECTION_TYPE_PROPERTY_NAME, connectionType);
properties.put(PROPERTY_CONNECTION_TYPE, connectionType);
}
String connectionBaudRate = appliance.getConnectionBaudRate();
if (connectionBaudRate != null) {
properties.put(PROPERTY_CONNECTION_BAUD_RATE, connectionBaudRate);
}
updateProperties(properties);
updateStatus(ThingStatus.ONLINE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public String getSerialNumber() {
return Properties.get("serial.number").getAsString();
}

@NonNull
public String getFirmwareVersion() {
return Properties.get("firmware.version").getAsString();
}

@NonNull
public String getRemoteUid() {
JsonElement remoteUid = Properties.get("remote.uid");
Expand All @@ -163,6 +168,14 @@ public String getConnectionType() {
return connectionType.getAsString();
}

public String getConnectionBaudRate() {
JsonElement baudRate = Properties.get("connection.baud.rate");
if (baudRate == null) {
return null;
}
return baudRate.getAsString();
}

@NonNull
public String getApplianceModel() {
JsonElement model = Properties.get("miele.model");
Expand Down

0 comments on commit 1c88350

Please sign in to comment.