use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit in project smarthome by eclipse.
the class DeviceStatusManagerImpl method unregisterDeviceListener.
@Override
public void unregisterDeviceListener(DeviceStatusListener deviceListener) {
if (deviceListener != null) {
String id = deviceListener.getDeviceStatusListenerID();
logger.debug("unregister DeviceListener with id: {}", id);
if (id.equals(DeviceStatusListener.DEVICE_DISCOVERY)) {
this.deviceDiscovery = null;
} else {
Device intDevice = strucMan.getDeviceByDSID(deviceListener.getDeviceStatusListenerID());
if (intDevice != null) {
intDevice.unregisterDeviceStatusListener();
} else {
Circuit intCircuit = strucMan.getCircuitByDSID(new DSID(deviceListener.getDeviceStatusListenerID()));
if (intCircuit != null) {
intCircuit.unregisterDeviceStatusListener();
if (deviceDiscovery != null) {
deviceDiscovery.onDeviceAdded(intCircuit);
}
}
}
}
}
}
use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit in project smarthome by eclipse.
the class DeviceStatusManagerImpl method registerDeviceListener.
@Override
public void registerDeviceListener(DeviceStatusListener deviceListener) {
if (deviceListener != null) {
String id = deviceListener.getDeviceStatusListenerID();
if (id.equals(DeviceStatusListener.DEVICE_DISCOVERY)) {
this.deviceDiscovery = deviceListener;
logger.debug("register Device-Discovery ");
for (Device device : strucMan.getDeviceMap().values()) {
deviceDiscovery.onDeviceAdded(device);
}
for (Circuit circuit : strucMan.getCircuitMap().values()) {
deviceDiscovery.onDeviceAdded(circuit);
}
} else {
Device intDevice = strucMan.getDeviceByDSID(deviceListener.getDeviceStatusListenerID());
if (intDevice != null) {
logger.debug("register DeviceListener with id: {} to Device ", id);
intDevice.registerDeviceStatusListener(deviceListener);
} else {
Circuit intCircuit = strucMan.getCircuitByDSID(new DSID(deviceListener.getDeviceStatusListenerID()));
if (intCircuit != null) {
logger.debug("register DeviceListener with id: {} to Circuit ", id);
intCircuit.registerDeviceStatusListener(deviceListener);
} else {
deviceListener.onDeviceRemoved(null);
}
}
}
}
}
use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit in project smarthome by eclipse.
the class CircuitHandler method onDeviceAdded.
@Override
public void onDeviceAdded(GeneralDeviceInformation device) {
if (device instanceof Circuit) {
this.circuit = (Circuit) device;
if (this.circuit.isPresent()) {
ThingStatusInfo statusInfo = this.dssBridgeHandler.getThing().getStatusInfo();
updateStatus(statusInfo.getStatus(), statusInfo.getStatusDetail(), statusInfo.getDescription());
logger.debug("Set status to {}", getThing().getStatus());
checkCircuitInfoProperties(this.circuit);
// load first channel values
onCircuitStateInitial(this.circuit);
return;
}
}
onDeviceRemoved(device);
}
use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit in project smarthome by eclipse.
the class DeviceDiscoveryService method onDeviceAddedInternal.
private void onDeviceAddedInternal(GeneralDeviceInformation device) {
boolean isSupported = false;
if (device instanceof Device) {
Device tempDevice = (Device) device;
if ((tempDevice.isSensorDevice() && deviceType.equals(tempDevice.getHWinfo().replaceAll("-", ""))) || (deviceType.equals(tempDevice.getHWinfo().substring(0, 2)) && (tempDevice.isDeviceWithOutput() || tempDevice.isBinaryInputDevice()) && tempDevice.isPresent())) {
isSupported = true;
}
} else if (device instanceof Circuit && DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString().equals(deviceType)) {
isSupported = true;
}
if (isSupported) {
ThingUID thingUID = getThingUID(device);
if (thingUID != null) {
Map<String, Object> properties = new HashMap<>(1);
properties.put(DigitalSTROMBindingConstants.DEVICE_DSID, device.getDSID().getValue());
String deviceName = null;
if (StringUtils.isNotBlank(device.getName())) {
deviceName = device.getName();
} else {
// if no name is set, the dSID will be used as name
deviceName = device.getDSID().getValue();
}
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties).withBridge(bridgeUID).withLabel(deviceName).build();
thingDiscovered(discoveryResult);
} else {
if (device instanceof Device) {
logger.debug("Discovered unsupported device hardware type '{}' with uid {}", ((Device) device).getHWinfo(), device.getDSUID());
}
}
} else {
if (device instanceof Device) {
logger.debug("Discovered device with disabled or no output mode. Device was not added to inbox. " + "Device information: hardware info: {}, dSUID: {}, device-name: {}, output value: {}", ((Device) device).getHWinfo(), device.getDSUID(), device.getName(), ((Device) device).getOutputMode());
}
}
}
use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit in project smarthome by eclipse.
the class DsAPIImpl method getApartmentCircuits.
@Override
public List<Circuit> getApartmentCircuits(String sessionToken) {
String response = transport.execute(SimpleRequestBuilder.buildNewJsonRequest(ClassKeys.APARTMENT).addFunction(FunctionKeys.GET_CIRCUITS).addParameter(ParameterKeys.TOKEN, sessionToken).buildRequestString());
JsonObject responseObj = JSONResponseHandler.toJsonObject(response);
if (JSONResponseHandler.checkResponse(responseObj)) {
responseObj = JSONResponseHandler.getResultJsonObject(responseObj);
if (responseObj.get(JSONApiResponseKeysEnum.CIRCUITS.getKey()).isJsonArray()) {
JsonArray array = responseObj.get(JSONApiResponseKeysEnum.CIRCUITS.getKey()).getAsJsonArray();
List<Circuit> circuitList = new LinkedList<Circuit>();
for (int i = 0; i < array.size(); i++) {
if (array.get(i).isJsonObject()) {
circuitList.add(new CircuitImpl(array.get(i).getAsJsonObject()));
}
}
return circuitList;
}
}
return new LinkedList<Circuit>();
}
Aggregations