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.DeviceSceneSpec;
19 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DSID;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * The {@link SceneConfigReadingJob} is the implementation of a {@link SensorJob}
25 * for reading out a scene output value of a digitalSTROM-Device and store it into the {@link Device}.
27 * @author Michael Ochel - Initial contribution
28 * @author Matthias Siegele - Initial contribution
30 public class SceneConfigReadingJob implements SensorJob {
32 private final Logger logger = LoggerFactory.getLogger(SceneConfigReadingJob.class);
34 private final Device device;
35 private short sceneID = 0;
36 private final DSID meterDSID;
37 private long initalisationTime = 0;
40 * Creates a new {@link SceneConfigReadingJob} for the given {@link Device} and the given sceneID.
42 * @param device to update
43 * @param sceneID to update
45 public SceneConfigReadingJob(Device device, short sceneID) {
47 this.sceneID = sceneID;
48 this.meterDSID = device.getMeterDSID();
49 this.initalisationTime = System.currentTimeMillis();
53 public void execute(DsAPI digitalSTROM, String token) {
54 DeviceSceneSpec sceneConfig = digitalSTROM.getDeviceSceneMode(token, device.getDSID(), null, null, sceneID);
56 if (sceneConfig != null) {
57 device.addSceneConfig(sceneID, sceneConfig);
58 logger.debug("UPDATED scene configuration for dSID: {}, sceneID: {}, configuration: {}",
59 this.device.getDSID(), sceneID, sceneConfig);
64 public boolean equals(Object obj) {
65 if (obj instanceof SceneConfigReadingJob other) {
66 String str = other.device.getDSID().getValue() + "-" + other.sceneID;
67 return (this.device.getDSID().getValue() + "-" + this.sceneID).equals(str);
73 public int hashCode() {
74 return new String(this.device.getDSID().getValue() + this.sceneID).hashCode();
78 public DSID getDSID() {
79 return device.getDSID();
83 public DSID getMeterDSID() {
84 return this.meterDSID;
88 public long getInitalisationTime() {
89 return this.initalisationTime;
93 public void setInitalisationTime(long time) {
94 this.initalisationTime = time;
98 public String toString() {
99 return "SceneConfigReadingJob [sceneID: " + sceneID + ", deviceDSID : " + device.getDSID().getValue()
100 + ", meterDSID=" + meterDSID + ", initalisationTime=" + initalisationTime + "]";
104 public String getID() {
105 return getID(device, sceneID);
109 * Returns the id for a {@link SceneConfigReadingJob} with the given {@link Device} and sceneID.
111 * @param device to update
112 * @param sceneID to update
115 public static String getID(Device device, Short sceneID) {
116 return SceneConfigReadingJob.class.getSimpleName() + "-" + device.getDSID().getValue() + "-" + sceneID;