use of org.openhab.core.thing.ThingStatusDetail in project openhab-addons by openhab.
the class HyperionHandler method updateOnlineStatus.
private void updateOnlineStatus(ThingStatus status, ThingStatusDetail detail, String message) {
ThingStatus current = thing.getStatus();
ThingStatusDetail currentDetail = thing.getStatusInfo().getStatusDetail();
if (!current.equals(status) || !currentDetail.equals(detail)) {
updateStatus(status, detail, message);
}
}
use of org.openhab.core.thing.ThingStatusDetail in project openhab-addons by openhab.
the class HyperionNgHandler method updateOnlineStatus.
private void updateOnlineStatus(ThingStatus status, ThingStatusDetail detail, String message) {
ThingStatusInfo currentStatusInfo = thing.getStatusInfo();
ThingStatus currentStatus = currentStatusInfo.getStatus();
ThingStatusDetail currentDetail = currentStatusInfo.getStatusDetail();
if (!currentStatus.equals(status) || !currentDetail.equals(detail)) {
updateStatus(status, detail, message);
}
}
use of org.openhab.core.thing.ThingStatusDetail in project openhab-addons by openhab.
the class HomematicThingHandler method updateStatus.
/**
* Updates the thing status based on device status.
*/
private void updateStatus(HmDevice device) throws GatewayNotAvailableException, IOException {
loadHomematicChannelValues(device.getChannel(0));
ThingStatus oldStatus = thing.getStatus();
if (oldStatus == ThingStatus.UNINITIALIZED) {
return;
}
ThingStatus newStatus = ThingStatus.ONLINE;
ThingStatusDetail newDetail = ThingStatusDetail.NONE;
if ((getBridge() != null) && (getBridge().getStatus() == ThingStatus.OFFLINE)) {
newStatus = ThingStatus.OFFLINE;
newDetail = ThingStatusDetail.BRIDGE_OFFLINE;
} else if (device.isFirmwareUpdating()) {
newStatus = ThingStatus.OFFLINE;
newDetail = ThingStatusDetail.FIRMWARE_UPDATING;
} else if (device.isUnreach()) {
newStatus = ThingStatus.OFFLINE;
newDetail = ThingStatusDetail.COMMUNICATION_ERROR;
} else if (device.isConfigPending() || device.isUpdatePending()) {
newDetail = ThingStatusDetail.CONFIGURATION_PENDING;
}
if (thing.getStatus() != newStatus || thing.getStatusInfo().getStatusDetail() != newDetail) {
updateStatus(newStatus, newDetail);
}
if (oldStatus == ThingStatus.OFFLINE && newStatus == ThingStatus.ONLINE) {
initialize();
}
}
use of org.openhab.core.thing.ThingStatusDetail in project openhab-addons by openhab.
the class NeeoDeviceHandler method initializeTask.
/**
* Initializes the task be creating the {@link NeeoDeviceProtocol}, going online and then scheduling the refresh
* task.
*/
private void initializeTask() {
final NeeoDeviceConfig config = getConfigAs(NeeoDeviceConfig.class);
final String roomKey = getRoomKey();
if (roomKey == null || roomKey.isEmpty()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Room key (from the parent room bridge) was not found");
return;
}
final String deviceKey = config.getDeviceKey();
if (deviceKey == null || deviceKey.isEmpty()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Device key was not found or empty");
return;
}
try {
NeeoUtil.checkInterrupt();
final NeeoBrainApi brainApi = getNeeoBrainApi();
if (brainApi == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, "Cannot find the NEEO Brain API");
return;
}
final NeeoRoom room = brainApi.getRoom(roomKey);
final NeeoDevice device = room.getDevices().getDevice(deviceKey);
if (device == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Device (" + config.getDeviceKey() + ") was not found in room (" + roomKey + ")");
return;
}
final ThingUID thingUid = getThing().getUID();
final Map<String, String> properties = new HashMap<>();
final NeeoDeviceDetails details = device.getDetails();
if (details != null) {
/**
* The following properties have matches in org.openhab.io.neeo.OpenHabToDeviceConverter.java
*/
addProperty(properties, "Source Name", details.getSourceName());
addProperty(properties, "Adapter Name", details.getAdapterName());
addProperty(properties, "Type", details.getType());
addProperty(properties, "Manufacturer", details.getManufacturer());
addProperty(properties, "Name", details.getName());
final NeeoDeviceDetailsTiming timing = details.getTiming();
if (timing != null) {
properties.put("Standby Command Delay", toString(timing.getStandbyCommandDelay()));
properties.put("Source Switch Delay", toString(timing.getSourceSwitchDelay()));
properties.put("Shutdown Delay", toString(timing.getShutdownDelay()));
}
properties.put("Device Capabilities", Arrays.stream(details.getDeviceCapabilities()).collect(Collectors.joining(",")));
}
final ThingBuilder thingBuilder = editThing();
thingBuilder.withLabel(device.getName() + " (NEEO " + brainApi.getBrain().getKey() + ")").withProperties(properties).withChannels(ChannelUtils.generateChannels(thingUid, device));
updateThing(thingBuilder.build());
NeeoUtil.checkInterrupt();
final NeeoDeviceProtocol protocol = new NeeoDeviceProtocol(new NeeoHandlerCallback() {
@Override
public void statusChanged(ThingStatus status, ThingStatusDetail detail, String msg) {
updateStatus(status, detail, msg);
}
@Override
public void stateChanged(String channelId, State state) {
updateState(channelId, state);
}
@Override
public void setProperty(String propertyName, String propertyValue) {
getThing().setProperty(propertyName, propertyValue);
}
@Override
public void scheduleTask(Runnable task, long milliSeconds) {
scheduler.schedule(task, milliSeconds, TimeUnit.MILLISECONDS);
}
@Override
public void triggerEvent(String channelID, String event) {
triggerChannel(channelID, event);
}
@Nullable
@Override
public NeeoBrainApi getApi() {
return getNeeoBrainApi();
}
}, roomKey, deviceKey);
deviceProtocol.getAndSet(protocol);
NeeoUtil.checkInterrupt();
updateStatus(ThingStatus.ONLINE);
} catch (IOException e) {
logger.debug("IOException during initialization", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Room " + roomKey + " couldn't be found");
} catch (InterruptedException e) {
logger.debug("Initialization was interrupted", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR, "Initialization was interrupted");
}
}
use of org.openhab.core.thing.ThingStatusDetail in project openhab-addons by openhab.
the class NeeoRoomHandler method initializeTask.
/**
* Initializes the task be creating the {@link NeeoRoomProtocol}, going online and then scheduling the refresh task.
*/
private void initializeTask() {
final NeeoRoomConfig config = getConfigAs(NeeoRoomConfig.class);
final String roomKey = config.getRoomKey();
if (roomKey == null || roomKey.isEmpty()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Room key (from the parent room bridge) was not found");
return;
}
try {
NeeoUtil.checkInterrupt();
final NeeoBrainApi brainApi = getNeeoBrainApi();
if (brainApi == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, "Cannot find the NEEO Brain API");
return;
}
final NeeoRoom room = brainApi.getRoom(roomKey);
final ThingUID thingUid = getThing().getUID();
final Map<String, String> properties = new HashMap<>();
properties.put("Key", roomKey);
final ThingBuilder thingBuilder = editThing();
thingBuilder.withLabel(room.getName() + " (NEEO " + brainApi.getBrain().getKey() + ")").withProperties(properties).withChannels(ChannelUtils.generateChannels(thingUid, room));
updateThing(thingBuilder.build());
NeeoUtil.checkInterrupt();
final NeeoRoomProtocol protocol = new NeeoRoomProtocol(new NeeoHandlerCallback() {
@Override
public void statusChanged(ThingStatus status, ThingStatusDetail detail, String msg) {
updateStatus(status, detail, msg);
}
@Override
public void stateChanged(String channelId, State state) {
updateState(channelId, state);
}
@Override
public void setProperty(String propertyName, String propertyValue) {
getThing().setProperty(propertyName, propertyValue);
}
@Override
public void scheduleTask(Runnable task, long milliSeconds) {
scheduler.schedule(task, milliSeconds, TimeUnit.MILLISECONDS);
}
@Override
public void triggerEvent(String channelID, String event) {
triggerChannel(channelID, event);
}
@Nullable
@Override
public NeeoBrainApi getApi() {
return getNeeoBrainApi();
}
}, roomKey);
roomProtocol.getAndSet(protocol);
NeeoUtil.checkInterrupt();
updateStatus(ThingStatus.ONLINE);
if (config.getRefreshPolling() > 0) {
NeeoUtil.checkInterrupt();
NeeoUtil.cancel(refreshTask.getAndSet(scheduler.scheduleWithFixedDelay(() -> {
try {
refreshState();
} catch (InterruptedException e) {
logger.debug("Refresh State was interrupted", e);
}
}, 0, config.getRefreshPolling(), TimeUnit.SECONDS)));
}
} catch (IOException e) {
logger.debug("IOException during initialization", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Room " + config.getRoomKey() + " couldn't be found");
} catch (InterruptedException e) {
logger.debug("Initialization was interrupted", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR, "Initialization was interrupted");
}
}
Aggregations