Skip to content

Commit

Permalink
Alter identifier being used to address each device to use Serial Numb…
Browse files Browse the repository at this point in the history
…er where possible, and full room name.

Signed-off-by: Andrew Schofield <[email protected]> (github: andrew-schofield)
  • Loading branch information
andrew-schofield committed Jan 27, 2018
1 parent 28866d4 commit 6f8fdfa
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@
<channel id="currentSignalRSSI" typeId="signalRSSI-channel" />
<channel id="currentSignalStrength" typeId="signalStrength-channel" />
</channels>

<config-description>
<parameter name="internalID" type="integer">
<label>ID</label>
<description>
Device ID on the network.
</description>
<required>true</required>
</parameter>
</config-description>
</thing-type>

<!-- Room Thing Type -->
Expand All @@ -85,10 +75,10 @@
</channels>

<config-description>
<parameter name="internalID" type="integer">
<label>ID</label>
<parameter name="roomName" type="text">
<label>Room Name</label>
<description>
Device ID on the network.
The room name as it appears in the Wiser app.
</description>
<required>true</required>
</parameter>
Expand All @@ -114,10 +104,10 @@
</channels>

<config-description>
<parameter name="internalID" type="integer">
<label>ID</label>
<parameter name="serialNumber" type="text">
<label>Serial Number</label>
<description>
Device ID on the network.
Device Serial Number.
</description>
<required>true</required>
</parameter>
Expand All @@ -143,10 +133,10 @@
</channels>

<config-description>
<parameter name="internalID" type="integer">
<label>ID</label>
<parameter name="serialNumber" type="text">
<label>Serial Number</label>
<description>
Device ID on the network.
Device Serial Number.
</description>
<required>true</required>
</parameter>
Expand Down
22 changes: 11 additions & 11 deletions addons/binding/org.openhab.binding.draytonwiser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ This binding integrates the [Drayton Wiser Smart Heating System](https://wiser.d

The Drayton Wiser binding supports the following things:
* Bridge - The network device in the controller that allows us to interact with the other devices in the system
* Controller - The HeatHub attached to the boiler. This also acts as the hub device.
* Rooms - Virtual groups of Room Stats and TRVs that can have temperatures and schedules
* Room Stats - Wireless thermostats which monitor temperature and humidity, and call for heat
* Smart TRVs - Wireless TRVs that monitor temperature and can alter the radiator valve state and call for heat
* Controller - The _HeatHub_ attached to the boiler. This also acts as the hub device.
* Rooms - Virtual groups of _Room Thermostats_ and _TRVs_ that can have temperatures and schedules
* Room Thermostats - Wireless thermostats which monitor temperature and humidity, and call for heat
* Smart TRVs - Wireless TRVs that monitor temperature, alter the radiator valve state and call for heat

## Discovery

Expand All @@ -35,16 +35,16 @@ The `REFRESH` interval defines in seconds, how often the binding will poll the c
```
Bridge draytonwiser:heathub:HeatHub [ ADDR="192.168.1.X", REFRESH=60, AUTHTOKEN="authtoken from hub" ]
{
controller controller [ internalID=0 ]
room livingroom [ internalID=1 ]
room bathroom [ internalID=2 ]
room bedroom [ internalID=3 ]
roomstat livingroomstat [ internalID=1234 ]
itrv livingroomtrv [ internalID=2345 ]
controller controller
room livingroom [ roomName="Living Room" ]
room bathroom [ roomName="Bathroom" ]
room bedroom [ roomName="Bedroom" ]
roomstat livingroomstat [ serialNumber="ABCDEF1234" ]
itrv livingroomtrv [ serialNumber="ABCDEF1235" ]
}
```

The `internalID` above corresponds to the ID of the device reported by the api. Currently this is only obtainable by packet inspection if not using auto-discovery. This should hopefully change in future to use the serial number of the devices where possible (which can be found in the battery compartment of each device).
The `roomName` corresponds to the room name configured in the Wiser App. It is not case sensitive. The `serialNumber` corresponds to the device serial number which can be found on a sticker inside the battery compartment of the Smart Valves/TRVs, and behind the wall mount of the Room Thermostats.

## Channels

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,41 @@ public List<Room> getRooms() {
return domain.getRoom();
}

public @Nullable Room getRoom(Integer id) {
public @Nullable Room getRoom(String name) {
if (domain == null) {
return null;
}

for (Room room : domain.getRoom()) {
if (room.getId().equals(id)) {
if (room.getName().toLowerCase().equals(name.toLowerCase())) {
return room;
}
}

return null;
}

public @Nullable RoomStat getRoomStat(Integer id) {
public @Nullable RoomStat getRoomStat(String serialNumber) {
if (domain == null) {
return null;
}

Integer id = getIdFromSerialNumber(serialNumber);

if (id == null) {
return null;
}

for (RoomStat roomStat : domain.getRoomStat()) {
if (roomStat.getId().equals(id)) {
return roomStat;
}
}

return null;
}

public @Nullable RoomStat getRoomStat(int id) {
if (domain == null) {
return null;
}
Expand All @@ -196,11 +216,17 @@ public List<Room> getRooms() {
return null;
}

public @Nullable SmartValve getSmartValve(Integer id) {
public @Nullable SmartValve getSmartValve(String serialNumber) {
if (domain == null) {
return null;
}

Integer id = getIdFromSerialNumber(serialNumber);

if (id == null) {
return null;
}

for (SmartValve smartValve : domain.getSmartValve()) {
if (smartValve.getId().equals(id)) {
return smartValve;
Expand Down Expand Up @@ -253,17 +279,27 @@ public List<HeatingChannel> getHeatingChannels() {
return domain.getHeatingChannel();
}

public void setRoomSetPoint(Integer roomId, Integer setPoint) {
public void setRoomSetPoint(String roomName, Integer setPoint) {
Room room = getRoom(roomName);
if (room == null) {
return;
}

String payload = "{\"RequestOverride\":{\"Type\":\"Manual\", \"SetPoint\":" + setPoint + "}}";
sendMessageToHeatHub(DraytonWiserBindingConstants.ROOMS_ENDPOINT + roomId.toString(), "PATCH", payload);
sendMessageToHeatHub(DraytonWiserBindingConstants.ROOMS_ENDPOINT + room.getId().toString(), "PATCH", payload);
getDomain();
}

public void setRoomManualMode(Integer roomId, Boolean manualMode) {
public void setRoomManualMode(String roomName, Boolean manualMode) {
Room room = getRoom(roomName);
if (room == null) {
return;
}

String payload = "{\"Mode\":\"" + (manualMode ? "Manual" : "Auto") + "\"}";
sendMessageToHeatHub(DraytonWiserBindingConstants.ROOMS_ENDPOINT + roomId.toString(), "PATCH", payload);
sendMessageToHeatHub(DraytonWiserBindingConstants.ROOMS_ENDPOINT + room.getId().toString(), "PATCH", payload);
payload = "{\"RequestOverride\":{\"Type\":\"None\",\"Originator\" :\"App\",\"DurationMinutes\":0,\"SetPoint\":0}}";
sendMessageToHeatHub(DraytonWiserBindingConstants.ROOMS_ENDPOINT + roomId.toString(), "PATCH", payload);
sendMessageToHeatHub(DraytonWiserBindingConstants.ROOMS_ENDPOINT + room.getId().toString(), "PATCH", payload);
getDomain();
}

Expand Down Expand Up @@ -308,4 +344,19 @@ public void setEcoMode(Boolean ecoMode) {
}
return null;
}

private @Nullable Integer getIdFromSerialNumber(String serialNumber) {
if (domain == null) {
return null;
}

for (Device device : domain.getDevice()) {
if (device.getSerialNumber() != null
&& device.getSerialNumber().toLowerCase().equals(serialNumber.toLowerCase())) {
return device.getId();
}
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/
package org.openhab.binding.draytonwiser.handler;

import java.math.BigDecimal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.library.types.DecimalType;
Expand Down Expand Up @@ -97,7 +95,7 @@ protected void refresh() {
}

private boolean updateRoomData() {
room = getBridgeHandler().getRoom(((BigDecimal) getThing().getConfiguration().get("internalID")).intValue());
room = getBridgeHandler().getRoom(getThing().getConfiguration().get("roomName").toString());
return room != null;
}

Expand All @@ -110,8 +108,7 @@ private State getSetPoint() {
}

private void setSetPoint(Integer setPoint) {
getBridgeHandler().setRoomSetPoint(((BigDecimal) getThing().getConfiguration().get("internalID")).intValue(),
setPoint);
getBridgeHandler().setRoomSetPoint(getThing().getConfiguration().get("roomName").toString(), setPoint);
}

private State getHumidity() {
Expand Down Expand Up @@ -166,7 +163,6 @@ private State getManualModeState() {
}

private void setManualMode(Boolean manualMode) {
getBridgeHandler().setRoomManualMode(((BigDecimal) getThing().getConfiguration().get("internalID")).intValue(),
manualMode);
getBridgeHandler().setRoomManualMode(getThing().getConfiguration().get("roomName").toString(), manualMode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/
package org.openhab.binding.draytonwiser.handler;

import java.math.BigDecimal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.library.types.DecimalType;
Expand Down Expand Up @@ -91,8 +89,7 @@ protected void refresh() {
}

private boolean updateRoomStatData() {
roomStat = getBridgeHandler()
.getRoomStat(((BigDecimal) getThing().getConfiguration().get("internalID")).intValue());
roomStat = getBridgeHandler().getRoomStat(getThing().getConfiguration().get("serialNumber").toString());
return roomStat != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/
package org.openhab.binding.draytonwiser.handler;

import java.math.BigDecimal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.library.types.DecimalType;
Expand Down Expand Up @@ -91,8 +89,7 @@ protected void refresh() {
}

private boolean updateSmartValveData() {
smartValve = getBridgeHandler()
.getSmartValve(((BigDecimal) getThing().getConfiguration().get("internalID")).intValue());
smartValve = getBridgeHandler().getSmartValve(getThing().getConfiguration().get("serialNumber").toString());
return smartValve != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,13 @@ private void onControllerAdded() {
ThingUID bridgeUID = bridgeHandler.getThing().getUID();
Map<String, Object> properties = new HashMap<>();
Device device = bridgeHandler.getExtendedDeviceProperties(0);
properties.put("internalID", 0);
properties.put("Device Type", device.getProductIdentifier());
properties.put("Firmware Version", device.getActiveFirmwareVersion());
properties.put("Manufacturer", device.getManufacturer());
properties.put("Model", device.getModelIdentifier());

DiscoveryResult discoveryResult = DiscoveryResultBuilder
.create(new ThingUID(DraytonWiserBindingConstants.THING_TYPE_CONTROLLER, bridgeUID, "0"))
.create(new ThingUID(DraytonWiserBindingConstants.THING_TYPE_CONTROLLER, bridgeUID, "controller"))
.withProperties(properties).withBridge(bridgeUID).withLabel("Controller").build();

thingDiscovered(discoveryResult);
Expand All @@ -99,15 +98,16 @@ private void onRoomStatAdded(RoomStat r) {
ThingUID bridgeUID = bridgeHandler.getThing().getUID();
Map<String, Object> properties = new HashMap<>();
Device device = bridgeHandler.getExtendedDeviceProperties(r.getId());
properties.put("internalID", r.getId());
properties.put("serialNumber", device.getSerialNumber());
properties.put("Device Type", device.getModelIdentifier());
properties.put("Firmware Version", device.getActiveFirmwareVersion());
properties.put("Manufacturer", device.getManufacturer());
properties.put("Model", device.getProductModel());
properties.put("Serial Number", device.getSerialNumber());

DiscoveryResult discoveryResult = DiscoveryResultBuilder
.create(new ThingUID(DraytonWiserBindingConstants.THING_TYPE_ROOMSTAT, bridgeUID, r.getId().toString()))
.create(new ThingUID(DraytonWiserBindingConstants.THING_TYPE_ROOMSTAT, bridgeUID,
device.getSerialNumber().toString()))
.withProperties(properties).withBridge(bridgeUID).withLabel("Room Thermostat - " + r.getId().toString())
.withRepresentationProperty(device.getSerialNumber()).build();

Expand All @@ -117,7 +117,7 @@ private void onRoomStatAdded(RoomStat r) {
private void onRoomAdded(Room r) {
ThingUID bridgeUID = bridgeHandler.getThing().getUID();
Map<String, Object> properties = new HashMap<>();
properties.put("internalID", r.getId());
properties.put("roomName", r.getName());
DiscoveryResult discoveryResult = DiscoveryResultBuilder
.create(new ThingUID(DraytonWiserBindingConstants.THING_TYPE_ROOM, bridgeUID,
r.getName().replaceAll("[^A-Za-z0-9]", "").toLowerCase()))
Expand All @@ -130,15 +130,16 @@ private void onSmartValveAdded(SmartValve r) {
ThingUID bridgeUID = bridgeHandler.getThing().getUID();
Map<String, Object> properties = new HashMap<>();
Device device = bridgeHandler.getExtendedDeviceProperties(r.getId());
properties.put("internalID", r.getId());
properties.put("serialNumber", device.getSerialNumber());
properties.put("Device Type", device.getModelIdentifier());
properties.put("Firmware Version", device.getActiveFirmwareVersion());
properties.put("Manufacturer", device.getManufacturer());
properties.put("Model", device.getProductModel());
properties.put("Serial Number", device.getSerialNumber());

DiscoveryResult discoveryResult = DiscoveryResultBuilder
.create(new ThingUID(DraytonWiserBindingConstants.THING_TYPE_ITRV, bridgeUID, r.getId().toString()))
.create(new ThingUID(DraytonWiserBindingConstants.THING_TYPE_ITRV, bridgeUID,
device.getSerialNumber().toString()))
.withProperties(properties).withBridge(bridgeUID).withLabel("Smart Valve - " + r.getId().toString())
.withRepresentationProperty(device.getSerialNumber()).build();

Expand Down

0 comments on commit 6f8fdfa

Please sign in to comment.