Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nikohomecontrol] Prepare for translation #11319

Merged
merged 8 commits into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class NikoHomeControlBindingConstants {

public static final String BINDING_ID = "nikohomecontrol";

// Listener threadname prefix
public static final String THREAD_NAME_PREFIX = "OH-binding-";

// List of all Thing Type UIDs

// bridge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public NikoHomeControlActionHandler(Thing thing) {
public void handleCommand(ChannelUID channelUID, Command command) {
NikoHomeControlCommunication nhcComm = getCommunication();
if (nhcComm == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Bridge communication not initialized when trying to execute action command " + actionId);
updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED,
mherwege marked this conversation as resolved.
Show resolved Hide resolved
"@text/offline.bridge-unitialized");
return;
}

Expand Down Expand Up @@ -107,15 +107,10 @@ private void handleCommandSelection(ChannelUID channelUID, Command command) {
handleBrightnessCommand(command);
updateStatus(ThingStatus.ONLINE);
break;

case CHANNEL_ROLLERSHUTTER:
handleRollershutterCommand(command);
updateStatus(ThingStatus.ONLINE);
break;

default:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Channel unknown " + channelUID.getId());
mherwege marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -217,23 +212,21 @@ public void initialize() {

NikoHomeControlCommunication nhcComm = getCommunication();
if (nhcComm == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Connection with controller not started yet, could not initialize action " + actionId);
mherwege marked this conversation as resolved.
Show resolved Hide resolved
return;
}

// We need to do this in a separate thread because we may have to wait for the communication to become active
scheduler.submit(() -> {
if (!nhcComm.communicationActive()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"No connection with controller, could not initialize action " + actionId);
"@text/offline.communication-error");
return;
}

NhcAction nhcAction = nhcComm.getActions().get(actionId);
if (nhcAction == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Action " + actionId + " does not match an action in the controller");
"@text/offline.configuration-error.actionId");
return;
}

Expand Down Expand Up @@ -313,7 +306,7 @@ public void actionEvent(int actionState) {
break;
default:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Unknown action type " + actionType);
"@text/offline.configuration-error.actionType " + actionType);
mherwege marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -328,7 +321,7 @@ public void actionInitialized() {
@Override
public void actionRemoved() {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Action " + actionId + " has been removed from the controller");
"@text/offline.configuration-error.actionRemoved");
}

private void restartCommunication(NikoHomeControlCommunication nhcComm) {
Expand All @@ -337,7 +330,8 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) {
nhcComm.restartCommunication();
// If still not active, take thing offline and return.
if (!nhcComm.communicationActive()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Communication error");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"@text/offline.communication-error");
return;
}
// Also put the bridge back online
Expand All @@ -351,7 +345,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) {
NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler();
if (nhcBridgeHandler == null) {
updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED,
mherwege marked this conversation as resolved.
Show resolved Hide resolved
"No bridge initialized for action " + actionId);
"@text/offline.bridge-unitialized");
return null;
}
NikoHomeControlCommunication nhcComm = nhcBridgeHandler.getCommunication();
Expand All @@ -362,7 +356,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) {
Bridge nhcBridge = getBridge();
if (nhcBridge == null) {
updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED,
mherwege marked this conversation as resolved.
Show resolved Hide resolved
"No bridge initialized for action " + actionId);
"@text/offline.bridge-unitialized");
return null;
}
NikoHomeControlBridgeHandler nhcBridgeHandler = (NikoHomeControlBridgeHandler) nhcBridge.getHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void setupRefreshTimer(int refreshInterval) {
*/
protected void bridgeOffline() {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR,
"Error with bridge connection");
"@text/offline.communication-error");
}

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

import static org.openhab.binding.nikohomecontrol.internal.NikoHomeControlBindingConstants.THREAD_NAME_PREFIX;

import java.net.InetAddress;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -50,11 +52,12 @@ public void initialize() {
logger.debug("bridge handler host {}, port {}", addr, port);

if (addr != null) {
nhcComm = new NikoHomeControlCommunication1(this, scheduler);
String eventThreadName = THREAD_NAME_PREFIX + thing.getUID().getAsString();
nhcComm = new NikoHomeControlCommunication1(this, scheduler, eventThreadName);
mherwege marked this conversation as resolved.
Show resolved Hide resolved
startCommunication();
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR,
"Cannot resolve bridge IP with hostname " + config.addr);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR,
"@text/offline.configuration-error.ip");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ public void initialize() {
// advanced configuration, skipping token validation.
// This behavior would allow the same logic to be used (with profile UUID) as before token validation
// was introduced.
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, "Token is empty");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR,
"@text/offline.configuration-error.tokenEmpty");
return;
}
} else {
Date now = new Date();
if (expiryDate.before(now)) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR,
"Hobby api token has expired");
"@text/offline.configuration-error.tokenExpired");
return;
}
}
Expand All @@ -90,7 +91,7 @@ public void initialize() {
} catch (CertificateException e) {
// this should not happen unless there is a programming error
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR,
"Not able to set SSL context");
"@text/offline.communication-error");
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
return;
}

if (command == REFRESH) {
if (REFRESH.equals(command)) {
mherwege marked this conversation as resolved.
Show resolved Hide resolved
energyMeterEvent(nhcEnergyMeter.getPower());
}
}
Expand All @@ -77,8 +77,6 @@ public void initialize() {

NikoHomeControlCommunication nhcComm = getCommunication();
if (nhcComm == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Connection with controller not started yet, could not initialize energy meter " + energyMeterId);
mherwege marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand All @@ -87,14 +85,14 @@ public void initialize() {
scheduler.submit(() -> {
if (!nhcComm.communicationActive()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"No connection with controller, could not initialize energy meter " + energyMeterId);
"@text/offline.communication-error");
return;
}

NhcEnergyMeter nhcEnergyMeter = nhcComm.getEnergyMeters().get(energyMeterId);
if (nhcEnergyMeter == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Energy meter " + energyMeterId + " does not match a energy meter in the controller");
"@text/offline.configuration-error.energyMeterId");
return;
}

Expand Down Expand Up @@ -163,7 +161,7 @@ public void energyMeterInitialized() {
@Override
public void energyMeterRemoved() {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Energy meter " + energyMeterId + " has been removed from the controller");
"@text/offline.configuration-error.energyMeterRemoved");
}

@Override
Expand All @@ -172,8 +170,8 @@ public void energyMeterRemoved() {
public void channelLinked(ChannelUID channelUID) {
NikoHomeControlCommunication nhcComm = getCommunication();
if (nhcComm == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Bridge communication not initialized when trying to start energy meter " + energyMeterId);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"@text/offline.communication-error");
mherwege marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand All @@ -194,8 +192,8 @@ public void channelLinked(ChannelUID channelUID) {
public void channelUnlinked(ChannelUID channelUID) {
NikoHomeControlCommunication nhcComm = getCommunication();
if (nhcComm == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Bridge communication not initialized when trying to stop energy meter " + energyMeterId);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"@text/offline.communication-error");
mherwege marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand All @@ -220,7 +218,8 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) {
nhcComm.restartCommunication();
// If still not active, take thing offline and return.
if (!nhcComm.communicationActive()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Communication error");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"@text/offline.communication-error");
return;
}
// Also put the bridge back online
Expand All @@ -234,7 +233,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) {
NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler();
if (nhcBridgeHandler == null) {
updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED,
mherwege marked this conversation as resolved.
Show resolved Hide resolved
"No bridge initialized for energy meter " + energyMeterId);
"@text/offline.bridge-unitialized");
return null;
}
NikoHomeControlCommunication nhcComm = nhcBridgeHandler.getCommunication();
Expand All @@ -245,7 +244,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) {
Bridge nhcBridge = getBridge();
if (nhcBridge == null) {
updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED,
mherwege marked this conversation as resolved.
Show resolved Hide resolved
"No bridge initialized for energy meter " + energyMeterId);
"@text/offline.bridge-unitialized");
return null;
}
NikoHomeControlBridgeHandler nhcBridgeHandler = (NikoHomeControlBridgeHandler) nhcBridge.getHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ public NikoHomeControlThermostatHandler(Thing thing) {
public void handleCommand(ChannelUID channelUID, Command command) {
NikoHomeControlCommunication nhcComm = getCommunication();
if (nhcComm == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Bridge communication not initialized when trying to execute thermostat command on "
+ thermostatId);
updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED,
"@text/offline.bridge-unitialized");
mherwege marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand Down Expand Up @@ -143,10 +142,6 @@ private void handleCommandSelection(ChannelUID channelUID, Command command) {
}
updateStatus(ThingStatus.ONLINE);
break;

default:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Channel unknown " + channelUID.getId());
}
}

Expand All @@ -159,8 +154,6 @@ public void initialize() {

NikoHomeControlCommunication nhcComm = getCommunication();
if (nhcComm == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Connection with controller not started yet, could not initialize thermostat " + thermostatId);
mherwege marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand All @@ -169,14 +162,14 @@ public void initialize() {
scheduler.submit(() -> {
if (!nhcComm.communicationActive()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"No connection with controller, could not initialize thermostat " + thermostatId);
"@text/offline.communication-error");
return;
}

NhcThermostat nhcThermostat = nhcComm.getThermostats().get(thermostatId);
if (nhcThermostat == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Thermostat " + thermostatId + " does not match a thermostat in the controller");
"@text/offline.configuration-error.thermostatId");
return;
}

Expand Down Expand Up @@ -288,7 +281,7 @@ public void thermostatInitialized() {
@Override
public void thermostatRemoved() {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Thermostat " + thermostatId + " has been removed from the controller");
"@text/offline.configuration-error.thermostatRemoved");
}

private void restartCommunication(NikoHomeControlCommunication nhcComm) {
Expand All @@ -297,7 +290,8 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) {
nhcComm.restartCommunication();
// If still not active, take thing offline and return.
if (!nhcComm.communicationActive()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Communication error");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"@text/offline.communication-error");
return;
}
// Also put the bridge back online
Expand All @@ -311,7 +305,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) {
NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler();
if (nhcBridgeHandler == null) {
updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED,
mherwege marked this conversation as resolved.
Show resolved Hide resolved
"No bridge initialized for thermostat " + thermostatId);
"@text/offline.bridge-unitialized");
return null;
}
NikoHomeControlCommunication nhcComm = nhcBridgeHandler.getCommunication();
Expand All @@ -322,7 +316,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) {
Bridge nhcBridge = getBridge();
if (nhcBridge == null) {
updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED,
mherwege marked this conversation as resolved.
Show resolved Hide resolved
"No bridge initialized for thermostat " + thermostatId);
"@text/offline.bridge-unitialized");
return null;
}
NikoHomeControlBridgeHandler nhcBridgeHandler = (NikoHomeControlBridgeHandler) nhcBridge.getHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ public String getNhcBridgeId() {
*/
private boolean isNhc(DatagramPacket packet) {
byte[] packetData = packet.getData();
if ((packet.getLength() > 2) && (packetData[0] == 0x44)) {
return true;
}
return false;
return ((packet.getLength() > 2) && (packetData[0] == 0x44));
}

/**
Expand Down
Loading