2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.digitalstrom.internal.lib.sensorjobexecutor.sensorjob.impl;
15 import org.openhab.binding.digitalstrom.internal.lib.sensorjobexecutor.sensorjob.SensorJob;
16 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.DsAPI;
17 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.Device;
18 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.DeviceConstants;
19 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.DeviceStateUpdate;
20 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DSID;
21 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * The {@link DeviceOutputValueSensorJob} is the implementation of a {@link SensorJob}
27 * for reading out the current device output value of a digitalSTROM-Device and update the {@link Device}.
29 * @author Michael Ochel - Initial contribution
30 * @author Matthias Siegele - Initial contribution
32 public class DeviceOutputValueSensorJob implements SensorJob {
34 private final Logger logger = LoggerFactory.getLogger(DeviceOutputValueSensorJob.class);
35 private final Device device;
36 private short index = 0;
37 private final DSID meterDSID;
38 private long initalisationTime = 0;
41 * Creates a new {@link DeviceOutputValueSensorJob} for the given {@link Device}.
43 * @param device to update
45 public DeviceOutputValueSensorJob(Device device) {
47 if (device.isShade()) {
48 this.index = DeviceConstants.DEVICE_SENSOR_SLAT_POSITION_OUTPUT;
50 this.index = DeviceConstants.DEVICE_SENSOR_OUTPUT;
52 this.meterDSID = device.getMeterDSID();
53 this.initalisationTime = System.currentTimeMillis();
57 public void execute(DsAPI digitalSTROM, String token) {
58 int value = digitalSTROM.getDeviceOutputValue(token, this.device.getDSID(), null, null, index);
59 logger.debug("Device output value on Demand : {}, dSID: {}", value, this.device.getDSID().getValue());
64 this.device.updateInternalDeviceState(new DeviceStateUpdateImpl(DeviceStateUpdate.OUTPUT, value));
67 this.device.updateInternalDeviceState(
68 new DeviceStateUpdateImpl(DeviceStateUpdate.SLATPOSITION, value));
69 if (device.isBlind()) {
70 value = digitalSTROM.getDeviceOutputValue(token, this.device.getDSID(), null, null,
71 DeviceConstants.DEVICE_SENSOR_SLAT_ANGLE_OUTPUT);
72 logger.debug("Device angle output value on Demand : {}, dSID: {}", value,
73 this.device.getDSID().getValue());
75 this.device.updateInternalDeviceState(
76 new DeviceStateUpdateImpl(DeviceStateUpdate.SLAT_ANGLE, value));
87 public boolean equals(Object obj) {
88 if (obj instanceof DeviceOutputValueSensorJob other) {
89 String key = this.device.getDSID().getValue() + this.index;
90 return key.equals((other.device.getDSID().getValue() + other.index));
96 public int hashCode() {
97 return new String(this.device.getDSID().getValue() + this.index).hashCode();
101 public DSID getDSID() {
102 return device.getDSID();
106 public DSID getMeterDSID() {
107 return this.meterDSID;
111 public long getInitalisationTime() {
112 return this.initalisationTime;
116 public void setInitalisationTime(long time) {
117 this.initalisationTime = time;
121 public String toString() {
122 return "DeviceOutputValueSensorJob [deviceDSID : " + device.getDSID().getValue() + ", meterDSID=" + meterDSID
123 + ", initalisationTime=" + initalisationTime + "]";
127 public String getID() {
128 return getID(device);
132 * Returns the id for a {@link DeviceOutputValueSensorJob} with the given {@link Device}.
134 * @param device to update
137 public static String getID(Device device) {
138 return DeviceOutputValueSensorJob.class.getSimpleName() + "-" + device.getDSID().getValue();