Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Michels <markus7017@gmail.com>
  • Loading branch information
markus7017 committed May 24, 2024
1 parent 625088b commit 850e03e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static org.openhab.binding.shelly.internal.ShellyBindingConstants.*;
import static org.openhab.binding.shelly.internal.api1.Shelly1ApiJsonDTO.*;
import static org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.*;
import static org.openhab.binding.shelly.internal.discovery.ShellyThingCreator.THING_TYPE_SHELLYPRO2_RELAY_STR;
import static org.openhab.binding.shelly.internal.discovery.ShellyThingCreator.*;
import static org.openhab.binding.shelly.internal.util.ShellyUtils.*;

import java.io.BufferedReader;
Expand Down Expand Up @@ -259,6 +259,8 @@ public ShellyDeviceProfile getDeviceProfile(String thingType, @Nullable ShellySe
// Mini PM has 1 meter, but no relay
if (thingType.equals(THING_TYPE_SHELLYPRO2_RELAY_STR)) {
profile.numMeters = 0;
} else if (thingType.equals(THING_TYPE_SHELLYPRO3EM_STR)) {
profile.numMeters = 3;
} else if (dc.pm10 != null) {
profile.numMeters = 1;
} else if (dc.em0 != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,6 @@ public static boolean updateRelay(ShellyBaseHandler thingHandler, ShellySettings
getOpenClosed(getInteger(status.extSwitch.input0.input) == 1));
}
}
if (status.extTemperature != null) {
// Shelly 1/1PM support up to 3 external sensors
// for whatever reason those are not represented as an array, but 3 elements
updated |= updateTempChannel(status.extTemperature.sensor1, thingHandler, CHANNEL_ESENSOR_TEMP1);
updated |= updateTempChannel(status.extTemperature.sensor2, thingHandler, CHANNEL_ESENSOR_TEMP2);
updated |= updateTempChannel(status.extTemperature.sensor3, thingHandler, CHANNEL_ESENSOR_TEMP3);
updated |= updateTempChannel(status.extTemperature.sensor4, thingHandler, CHANNEL_ESENSOR_TEMP4);
updated |= updateTempChannel(status.extTemperature.sensor5, thingHandler, CHANNEL_ESENSOR_TEMP5);
}
if ((status.extHumidity != null) && (status.extHumidity.sensor1 != null)) {
updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_HUMIDITY,
toQuantityType(getDouble(status.extHumidity.sensor1.hum), DIGITS_PERCENT, Units.PERCENT));
}
if ((status.extVoltage != null) && (status.extVoltage.sensor1 != null)) {
updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_VOLTAGE,
toQuantityType(getDouble(status.extVoltage.sensor1.voltage), 4, Units.VOLT));
}
if ((status.extDigitalInput != null) && (status.extDigitalInput.sensor1 != null)) {
updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_DIGITALINPUT,
getOnOff(status.extDigitalInput.sensor1.state));
}
if ((status.extAnalogInput != null) && (status.extAnalogInput.sensor1 != null)) {
updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_ANALOGINPUT, toQuantityType(
getDouble(status.extAnalogInput.sensor1.percent), DIGITS_PERCENT, Units.PERCENT));
}

// Update Auto-ON/OFF timer
updated |= thingHandler.updateChannel(groupName, CHANNEL_TIMER_AUTOON,
Expand Down Expand Up @@ -556,6 +531,34 @@ public static boolean updateSensors(ShellyThingInterface thingHandler, ShellySet
thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_LAST_UPDATE, getTimestamp());
}
}

// Update Add-On channeös
if (status.extTemperature != null) {
// Shelly 1/1PM support up to 3 external sensors
// for whatever reason those are not represented as an array, but 3 elements
updated |= updateTempChannel(status.extTemperature.sensor1, thingHandler, CHANNEL_ESENSOR_TEMP1);
updated |= updateTempChannel(status.extTemperature.sensor2, thingHandler, CHANNEL_ESENSOR_TEMP2);
updated |= updateTempChannel(status.extTemperature.sensor3, thingHandler, CHANNEL_ESENSOR_TEMP3);
updated |= updateTempChannel(status.extTemperature.sensor4, thingHandler, CHANNEL_ESENSOR_TEMP4);
updated |= updateTempChannel(status.extTemperature.sensor5, thingHandler, CHANNEL_ESENSOR_TEMP5);
}
if ((status.extHumidity != null) && (status.extHumidity.sensor1 != null)) {
updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_HUMIDITY,
toQuantityType(getDouble(status.extHumidity.sensor1.hum), DIGITS_PERCENT, Units.PERCENT));
}
if ((status.extVoltage != null) && (status.extVoltage.sensor1 != null)) {
updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_VOLTAGE,
toQuantityType(getDouble(status.extVoltage.sensor1.voltage), 4, Units.VOLT));
}
if ((status.extDigitalInput != null) && (status.extDigitalInput.sensor1 != null)) {
updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_DIGITALINPUT,
getOnOff(status.extDigitalInput.sensor1.state));
}
if ((status.extAnalogInput != null) && (status.extAnalogInput.sensor1 != null)) {
updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_ANALOGINPUT,
toQuantityType(getDouble(status.extAnalogInput.sensor1.percent), DIGITS_PERCENT, Units.PERCENT));
}

return updated;
}

Expand Down

0 comments on commit 850e03e

Please sign in to comment.