Skip to content

Commit

Permalink
[draytonwiser] Fix bug where all items were discoverd as smart plugs
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Schofield <the.uncle.fungus@gmail.com>
  • Loading branch information
andrew-schofield committed Jul 14, 2020
1 parent c67c4d0 commit acdc665
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
import org.eclipse.smarthome.config.discovery.DiscoveryResult;
import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder;
import org.eclipse.smarthome.config.discovery.DiscoveryService;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.ThingUID;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerService;
import org.eclipse.smarthome.core.thing.binding.ThingTypeProvider;
import org.eclipse.smarthome.core.thing.xml.internal.ThingTypeXmlProvider;
import org.openhab.binding.draytonwiser.internal.DraytonWiserRefreshListener;
import org.openhab.binding.draytonwiser.internal.handler.DraytonWiserPropertyHelper;
import org.openhab.binding.draytonwiser.internal.handler.HeatHubHandler;
Expand Down Expand Up @@ -108,7 +111,7 @@ private void onHotWaterAdded(final DraytonWiserDTO domainDTOProxy, final HotWate
final DeviceDTO device = domainDTOProxy.getExtendedDeviceProperties(hotWaterId);

if (device != null) {
onThingWithSerialNumber("Hot Water", device, getRoomName(domainDTOProxy, hotWaterId));
onThingWithSerialNumber(THING_TYPE_HOTWATER, "Hot Water", device, getRoomName(domainDTOProxy, hotWaterId));
}
}

Expand All @@ -117,7 +120,7 @@ private void onRoomStatAdded(final DraytonWiserDTO domainDTOProxy, final RoomSta
final DeviceDTO device = domainDTOProxy.getExtendedDeviceProperties(roomStatId);

if (device != null) {
onThingWithSerialNumber("Thermostat", device, getRoomName(domainDTOProxy, roomStatId));
onThingWithSerialNumber(THING_TYPE_ROOMSTAT, "Thermostat", device, getRoomName(domainDTOProxy, roomStatId));
}
}

Expand All @@ -139,15 +142,15 @@ private void onSmartValveAdded(final DraytonWiserDTO domainDTOProxy, final Smart
final DeviceDTO device = domainDTOProxy.getExtendedDeviceProperties(smartValueId);

if (device != null) {
onThingWithSerialNumber("TRV", device, getRoomName(domainDTOProxy, smartValueId));
onThingWithSerialNumber(THING_TYPE_ITRV, "TRV", device, getRoomName(domainDTOProxy, smartValueId));
}
}

private void onSmartPlugAdded(final DraytonWiserDTO domainDTOProxy, final SmartPlugDTO smartPlug) {
final DeviceDTO device = domainDTOProxy.getExtendedDeviceProperties(smartPlug.getId());

if (device != null) {
onThingWithSerialNumber("Smart Plug", device, smartPlug.getName());
onThingWithSerialNumber(THING_TYPE_SMARTPLUG, "Smart Plug", device, smartPlug.getName());
}
}

Expand All @@ -156,15 +159,15 @@ private String getRoomName(final DraytonWiserDTO domainDTOProxy, final Integer r
return assignedRoom == null ? "" : assignedRoom.getName();
}

private void onThingWithSerialNumber(final String deviceType, final DeviceDTO device, final String name) {
private void onThingWithSerialNumber(final ThingTypeUID deviceType, final String deviceTypeName, final DeviceDTO device, final String name) {
final String serialNumber = device.getSerialNumber();
logger.debug("{} discovered, serialnumber: {}", deviceType, serialNumber);
logger.debug("{} discovered, serialnumber: {}", deviceTypeName, serialNumber);
final Map<String, Object> properties = new HashMap<>();

DraytonWiserPropertyHelper.setPropertiesWithSerialNumber(device, properties);
final DiscoveryResult discoveryResult = DiscoveryResultBuilder
.create(new ThingUID(THING_TYPE_SMARTPLUG, bridgeUID, serialNumber)).withProperties(properties)
.withBridge(bridgeUID).withLabel((name.isEmpty() ? "" : (name + " - ")) + deviceType)
.create(new ThingUID(deviceType, bridgeUID, serialNumber)).withProperties(properties)
.withBridge(bridgeUID).withLabel((name.isEmpty() ? "" : (name + " - ")) + deviceTypeName)
.withRepresentationProperty(serialNumber).build();

thingDiscovered(discoveryResult);
Expand Down

0 comments on commit acdc665

Please sign in to comment.