Skip to content

Commit

Permalink
Merge pull request openhab#1 from paulianttila/melcloud
Browse files Browse the repository at this point in the history
Some code review fixes
  • Loading branch information
lucacalcaterra authored Sep 17, 2019
2 parents 3043d0b + 7c8dd5b commit 1c1f395
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 41 deletions.
27 changes: 0 additions & 27 deletions bundles/org.openhab.binding.melcloud/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion bundles/org.openhab.binding.melcloud/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

### N.B.: For developers who wants contribute not use this repo. Use Instead the openhab2-fork at https://github.com/lucacalcaterra/openhab2-addons
# MELCloud Binding

This is an openHAB binding for Mitsubishi MELCloud (https://www.melcloud.com/).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.binding.ihc-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${project.version}/xml/features</repository>

<feature name="openhab-binding-melcloud" description="MELCloud Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.melcloud/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public void login(String username, String password, int languageId)
logger.debug("Login response: {}", loginResponse);
LoginClientResponse resp = gson.fromJson(loginResponse, LoginClientResponse.class);
if (resp.getErrorId() != null) {

String errorMsg = String.format("Login failed, error code: %s", resp.getErrorId());
if (resp.getErrorMessage() != null) {
errorMsg.concat(String.format(" (%s)", resp.getErrorMessage()));
Expand All @@ -103,19 +102,16 @@ public List<Device> fetchDeviceList() throws MelCloudCommException {
if (building.getStructure().getDevices() != null) {
devices.addAll(building.getStructure().getDevices());
}

building.getStructure().getFloors().forEach(floor -> {
if (floor.getDevices() != null) {
devices.addAll(floor.getDevices());
}

floor.getAreas().forEach(area -> {
if (area.getDevices() != null) {
devices.addAll(area.getDevices());
}
});
});

});
logger.debug("Found {} devices", devices.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ public class AcDeviceConfig {
public String toString() {
return "[deviceID=" + deviceID + ", buildingID=" + buildingID + ", pollingInterval=" + pollingInterval + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ public class AccountConfig {

@Override
public String toString() {
return "[username=" + username + ", password=" + password + ", languageId=" + language + "]";
return "[username=" + username + ", password=" + getPasswordForPrinting() + ", languageId=" + language + "]";
}

private String getPasswordForPrinting() {
if (password != null) {
return password.isEmpty() ? "<empty>" : "*********";
}
return "<null>";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public void initialize() {
config = getThing().getConfiguration().as(AcDeviceConfig.class);
logger.debug("A.C. device config: {}", config);

initializeBridge((getBridge() == null) ? null : getBridge().getHandler(),
(getBridge() == null) ? null : getBridge().getStatus());
initializeBridge(bridge.getHandler(), bridge.getStatus());
}

@Override
Expand All @@ -107,7 +106,10 @@ public void dispose() {
@Override
public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
logger.debug("bridgeStatusChanged {} for thing {}", bridgeStatusInfo, getThing().getUID());
initializeBridge((getBridge() == null) ? null : getBridge().getHandler(), bridgeStatusInfo.getStatus());
Bridge bridge = getBridge();
if (bridge != null) {
initializeBridge(bridge.getHandler(), bridgeStatusInfo.getStatus());
}

if (bridgeStatusInfo.getStatus() == ThingStatus.ONLINE) {
startAutomaticRefresh();
Expand Down Expand Up @@ -165,13 +167,13 @@ public void handleCommand(ChannelUID channelUID, Command command) {
case CHANNEL_SET_TEMPERATURE:
BigDecimal val = null;
if (command instanceof QuantityType) {
QuantityType<Temperature> quantity = ((QuantityType<Temperature>) command).toUnit(CELSIUS);
QuantityType<Temperature> quantity = new QuantityType<Temperature>(command.toString())
.toUnit(CELSIUS);
if (quantity != null) {
val = quantity.toBigDecimal().setScale(1, RoundingMode.HALF_UP);
}
} else {
val = new BigDecimal(command.toString()).setScale(1, RoundingMode.HALF_UP);

}
if (val != null) {
// round nearest .5
Expand Down Expand Up @@ -210,7 +212,6 @@ public void handleCommand(ChannelUID channelUID, Command command) {
} else {
logger.debug("Nothing to send");
}

}

private DeviceStatus getDeviceStatusCopy(DeviceStatus deviceStatus) {
Expand Down
2 changes: 1 addition & 1 deletion bundles/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
<module>org.openhab.binding.mail</module>
<module>org.openhab.binding.max</module>
<module>org.openhab.binding.mcp23017</module>
<module>org.openhab.binding.melcloud</module>
<module>org.openhab.binding.melcloud</module>
<module>org.openhab.binding.meteoblue</module>
<module>org.openhab.binding.meteostick</module>
<module>org.openhab.binding.miele</module>
Expand Down

0 comments on commit 1c1f395

Please sign in to comment.