use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class DeviceHandler method onDeviceAdded.
@Override
public synchronized void onDeviceAdded(GeneralDeviceInformation device) {
if (device instanceof Device) {
this.device = (Device) device;
if (this.device.isPresent()) {
ThingStatusInfo statusInfo = this.dssBridgeHandler.getThing().getStatusInfo();
updateStatus(statusInfo.getStatus(), statusInfo.getStatusDetail(), statusInfo.getDescription());
logger.debug("Set status to {}", getThing().getStatus());
// load scene configurations persistently into the thing
for (Short i : this.device.getSavedScenes()) {
onSceneConfigAdded(i);
}
logger.debug("Load saved scene specification into device");
this.device.saveConfigSceneSpecificationIntoDevice(getThing().getProperties());
checkDeviceInfoProperties(this.device);
// load sensor priorities into the device and load sensor channels of the thing
if (!this.device.isShade()) {
loadSensorChannels();
// check and load output channel of the thing
checkOutputChannel();
} else if (this.device.isBlind()) {
// load channel for set the angle of jalousie devices
ApplicationGroup.Color color = ((Device) device).getFunctionalColorGroup() != null ? ((Device) device).getFunctionalColorGroup().getColor() : null;
String channelTypeID = DsChannelTypeProvider.getOutputChannelTypeID(color, ((Device) device).getOutputMode(), ((Device) device).getOutputChannels());
loadOutputChannel(new ChannelTypeUID(BINDING_ID, channelTypeID), DsChannelTypeProvider.getItemType(channelTypeID));
}
// load first channel values
onDeviceStateInitial(this.device);
return;
}
}
onDeviceRemoved(device);
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class LifxLightHandler method updateStatusIfChanged.
private void updateStatusIfChanged(ThingStatus status, ThingStatusDetail statusDetail) {
ThingStatusInfo newStatusInfo = new ThingStatusInfo(status, statusDetail, null);
Duration durationSinceLastUpdate = Duration.between(lastStatusInfoUpdate, LocalDateTime.now());
boolean intervalElapsed = MIN_STATUS_INFO_UPDATE_INTERVAL.minus(durationSinceLastUpdate).isNegative();
ThingStatusInfo oldStatusInfo = statusInfo;
if (oldStatusInfo == null || !oldStatusInfo.equals(newStatusInfo) || intervalElapsed) {
statusInfo = newStatusInfo;
lastStatusInfoUpdate = LocalDateTime.now();
updateStatus(status, statusDetail);
}
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class RFXComHandlerTest method verifyStatusUpdated.
private void verifyStatusUpdated(ThingStatus status, ThingStatusDetail thingStatusDetail) {
verify(callback).statusUpdated(eq(thing), thingStatusInfoCaptor.capture());
ThingStatusInfo tsi = thingStatusInfoCaptor.getValue();
assertEquals(status, tsi.getStatus());
assertEquals(thingStatusDetail, tsi.getStatusDetail());
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class ModbusDataHandlerTest method createTcpMock.
private Bridge createTcpMock() {
Bridge tcpBridge = ModbusPollerThingHandlerTest.createTcpThingBuilder("tcp1").build();
ModbusTcpThingHandler tcpThingHandler = Mockito.mock(ModbusTcpThingHandler.class);
tcpBridge.setStatusInfo(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, ""));
tcpBridge.setHandler(tcpThingHandler);
doReturn(comms).when(tcpThingHandler).getCommunicationInterface();
try {
doReturn(0).when(tcpThingHandler).getSlaveId();
} catch (EndpointNotInitializedException e) {
// not raised -- we are mocking return value only, not actually calling the method
throw new IllegalStateException();
}
tcpThingHandler.initialize();
assertThat(tcpBridge.getStatus(), is(equalTo(ThingStatus.ONLINE)));
return tcpBridge;
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class TeslaAccountHandler method authenticate.
private ThingStatusInfo authenticate() {
TokenResponse token = logonToken;
boolean hasExpired = true;
if (token != null) {
Instant tokenCreationInstant = Instant.ofEpochMilli(token.created_at * 1000);
logger.debug("Found a request token created at {}", dateFormatter.format(tokenCreationInstant));
Instant tokenExpiresInstant = Instant.ofEpochMilli(token.created_at * 1000 + 60 * token.expires_in);
if (tokenExpiresInstant.isBefore(Instant.now())) {
logger.debug("The token has expired at {}", dateFormatter.format(tokenExpiresInstant));
hasExpired = true;
} else {
hasExpired = false;
}
}
if (hasExpired) {
String username = (String) getConfig().get(CONFIG_USERNAME);
String password = (String) getConfig().get(CONFIG_PASSWORD);
String refreshToken = (String) getConfig().get(CONFIG_REFRESHTOKEN);
if (refreshToken == null || refreshToken.isEmpty()) {
if (username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
try {
refreshToken = ssoHandler.authenticate(username, password);
} catch (Exception e) {
logger.error("An exception occurred while obtaining refresh token with username/password: '{}'", e.getMessage());
}
if (refreshToken != null) {
// store refresh token from SSO endpoint in config, clear the password
Configuration cfg = editConfiguration();
cfg.put(TeslaBindingConstants.CONFIG_REFRESHTOKEN, refreshToken);
cfg.remove(TeslaBindingConstants.CONFIG_PASSWORD);
updateConfiguration(cfg);
} else {
return new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Failed to obtain refresh token with username/password.");
}
} else {
return new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Neither a refresh token nor credentials are provided.");
}
}
this.logonToken = ssoHandler.getAccessToken(refreshToken);
if (this.logonToken == null) {
return new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Failed to obtain access token for API.");
}
}
return new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
}
Aggregations