[danfossairunit] Add filter period channel (#11371)

* Add filter period channel.

Fixes #11310

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

* Round remaining filter life percentage to one decimal.

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

* Improve and extend example configuration.

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

* Mark filter period channel as advanced due to Link CC/Air Dial conflicts.

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

* Add comment about value getting overwritten.

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

* Remove redundant parentheses.

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

* Fix SCA report: First javadoc author should have 'Initial contribution' contribution description.

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

* Fix SCA issue: NoEmptyLineSeparatorCheck

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
jlaur
2021-10-22 20:10:41 +02:00
committed by GitHub
parent 5eb004e378
commit d4c9d6ef77
8 changed files with 79 additions and 18 deletions

View File

@@ -59,7 +59,9 @@ public enum Channel {
// service channels
CHANNEL_BATTERY_LIFE("battery_life", ChannelGroup.SERVICE, DanfossAirUnit::getBatteryLife),
CHANNEL_FILTER_LIFE("filter_life", ChannelGroup.SERVICE, DanfossAirUnit::getFilterLife);
CHANNEL_FILTER_LIFE("filter_life", ChannelGroup.SERVICE, DanfossAirUnit::getFilterLife),
CHANNEL_FILTER_PERIOD("filter_period", ChannelGroup.SERVICE, DanfossAirUnit::getFilterPeriod,
DanfossAirUnit::setFilterPeriod);
private final String channelName;
private final ChannelGroup group;

View File

@@ -57,6 +57,7 @@ public class Commands {
public static byte[] EXHAUST_TEMPERATURE = { 0x14, 0x75 };
public static byte[] BATTERY_LIFE = { 0x03, 0x0f };
public static byte[] FILTER_LIFE = { 0x14, 0x6a };
public static byte[] FILTER_PERIOD = { 0x14, 0x69 };
public static byte[] CURRENT_TIME = { 0x15, (byte) 0xe0 };
public static byte[] AWAY_TO = { 0x15, 0x20 };
public static byte[] AWAY_FROM = { 0x15, 0x21 };

View File

@@ -19,7 +19,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* This interface defines a communication controller that can be used to send requests to the Danfoss Air Unit.
*
* @author Jacob Laursen - Refactoring, bugfixes and enhancements
* @author Jacob Laursen - Initial contribution
*/
@NonNullByDefault
public interface CommunicationController {

View File

@@ -213,7 +213,16 @@ public class DanfossAirUnit {
}
public DecimalType getFilterLife() throws IOException {
return new DecimalType(BigDecimal.valueOf(asPercentByte(getByte(REGISTER_1_READ, FILTER_LIFE))));
BigDecimal value = BigDecimal.valueOf(asPercentByte(getByte(REGISTER_1_READ, FILTER_LIFE)));
return new DecimalType(value.setScale(1, RoundingMode.HALF_UP));
}
public DecimalType getFilterPeriod() throws IOException {
return new DecimalType(BigDecimal.valueOf(getByte(REGISTER_1_READ, FILTER_PERIOD)));
}
public DecimalType setFilterPeriod(Command cmd) throws IOException {
return setNumberTypeRegister(cmd, FILTER_PERIOD);
}
public DateTimeType getCurrentTime() throws IOException, UnexpectedResponseValueException {
@@ -225,6 +234,14 @@ public class DanfossAirUnit {
return setPercentTypeRegister(cmd, MANUAL_FAN_SPEED_STEP);
}
private DecimalType setNumberTypeRegister(Command cmd, byte[] register) throws IOException {
if (cmd instanceof DecimalType) {
byte value = (byte) ((DecimalType) cmd).intValue();
set(REGISTER_1_WRITE, register, value);
}
return new DecimalType(BigDecimal.valueOf(getByte(REGISTER_1_READ, register)));
}
private PercentType setPercentTypeRegister(Command cmd, byte[] register) throws IOException {
if (cmd instanceof PercentType) {
byte value = (byte) ((((PercentType) cmd).intValue() + 5) / 10);

View File

@@ -80,7 +80,6 @@ public class DanfossAirUnitDiscoveryService extends AbstractDiscoveryService {
logger.debug("Try to discover all Danfoss Air CCM devices");
try (DatagramSocket socket = new DatagramSocket()) {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface networkInterface = interfaces.nextElement();
@@ -96,7 +95,6 @@ public class DanfossAirUnitDiscoveryService extends AbstractDiscoveryService {
sendBroadcastToDiscoverThing(socket, interfaceAddress.getBroadcast());
}
}
} catch (IOException e) {
logger.debug("No Danfoss Air CCM device found. Diagnostic: {}", e.getMessage());
}

View File

@@ -124,6 +124,7 @@
<label>Remaining Filter Life</label>
<description>Remaining life of filter until exchange is necessary</description>
</channel>
<channel id="filter_period" typeId="filterPeriod"/>
</channels>
</channel-group-type>
@@ -190,6 +191,12 @@
<category>Fan</category>
<state step="10" min="0" max="100" readOnly="true"/>
</channel-type>
<channel-type id="filterPeriod" advanced="true">
<item-type>Number</item-type>
<label>Filter Period</label>
<description>Number of months between filter replacements</description>
<state pattern="%d" min="3" max="12"/>
</channel-type>
<channel-type id="percentage">
<item-type>Number</item-type>
<label>Percentage</label>

View File

@@ -23,6 +23,7 @@ import java.time.ZonedDateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.library.types.QuantityType;
@@ -31,7 +32,7 @@ import org.openhab.core.test.java.JavaTest;
/**
* This class provides test cases for {@link DanfossAirUnit}
*
* @author Jacob Laursen - Refactoring, bugfixes and enhancements
* @author Jacob Laursen - Initial contribution
*/
public class DanfossAirUnitTest extends JavaTest {
@@ -153,4 +154,12 @@ public class DanfossAirUnitTest extends JavaTest {
var airUnit = new DanfossAirUnit(communicationController);
assertThrows(UnexpectedResponseValueException.class, () -> airUnit.getManualFanStep());
}
@Test
public void getFilterLifeWhenNearestNeighborIsBelowRoundsDown() throws IOException {
byte[] response = new byte[] { (byte) 0xf0 };
when(this.communicationController.sendRobustRequest(REGISTER_1_READ, FILTER_LIFE)).thenReturn(response);
var airUnit = new DanfossAirUnit(communicationController);
assertEquals(new DecimalType("94.1"), airUnit.getFilterLife());
}
}