Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mercedesme] AdBlue channel for combustion vehicles #17748

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions bundles/org.openhab.binding.mercedesme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,22 +444,23 @@ Group name: `range`

All channels read-only.

| Channel | Type | Description | bev | hybrid | combustion |
|------------------|----------------------|------------------------------|-----|--------|------------|
| mileage | Number:Length | Total Mileage | X | X | X |
| home-distance | Number:Length | Distance to Home | X | X | X |
| soc | Number:Dimensionless | Battery State of Charge | X | X | |
| charged | Number:Energy | Charged Battery Energy | X | X | |
| uncharged | Number:Energy | Uncharged Battery Energy | X | X | |
| range-electric | Number:Length | Electric Range | X | X | |
| radius-electric | Number:Length | Electric Radius for Map | X | X | |
| fuel-level | Number:Dimensionless | Fuel Level in Percent | | X | X |
| fuel-remain | Number:Volume | Remaining Fuel | | X | X |
| fuel-open | Number:Volume | Open Fuel Capacity | | X | X |
| range-fuel | Number:Length | Fuel Range | | X | X |
| radius-fuel | Number:Length | Fuel Radius for Map | | X | X |
| range-hybrid | Number:Length | Hybrid Range | | X | |
| radius-hybrid | Number:Length | Hybrid Radius for Map | | X | |
| Channel | Type | Description | bev | hybrid | combustion |
|------------------|----------------------|---------------------------------|-----|--------|------------|
| mileage | Number:Length | Total Mileage | X | X | X |
| home-distance | Number:Length | Distance to Home | X | X | X |
| soc | Number:Dimensionless | Battery State of Charge | X | X | |
| charged | Number:Energy | Charged Battery Energy | X | X | |
| uncharged | Number:Energy | Uncharged Battery Energy | X | X | |
| range-electric | Number:Length | Electric Range | X | X | |
| radius-electric | Number:Length | Electric Radius for Map | X | X | |
| fuel-level | Number:Dimensionless | Fuel Level in Percent | | X | X |
| fuel-remain | Number:Volume | Remaining Fuel | | X | X |
| fuel-open | Number:Volume | Open Fuel Capacity | | X | X |
| range-fuel | Number:Length | Fuel Range | | X | X |
| radius-fuel | Number:Length | Fuel Radius for Map | | X | X |
| range-hybrid | Number:Length | Hybrid Range | | X | |
| radius-hybrid | Number:Length | Hybrid Radius for Map | | X | |
| adblue-level | Number:Dimensionless | AdBlue tank level in percent | | | X |

Channels with `radius` are just giving a _guess_ which radius can be reached in a map display.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public class Constants {
public static final String MB_KEY_DOORSTATUSFRONTLEFT = "doorstatusfrontleft";
public static final String MB_KEY_DOORSTATUSFRONTRIGHT = "doorstatusfrontright";
public static final String MB_KEY_TANKLEVELPERCENT = "tanklevelpercent";
public static final String MB_KEY_ADBLUELEVELPERCENT = "tankLevelAdBlue";
public static final String MB_KEY_SOC = "soc";
public static final String MB_KEY_TIRE_PRESS_MEAS_TIMESTAMP = "tirePressMeasTimestamp";
public static final String MB_KEY_ENDOFCHARGETIME = "endofchargetime";
Expand Down Expand Up @@ -201,6 +202,7 @@ public class Constants {
public static final String OH_CHANNEL_COUPLER_AC = "coupler-ac";
public static final String OH_CHANNEL_CHARGE_FLAP = "charge-flap";
public static final String OH_CHANNEL_FUEL_LEVEL = "fuel-level";
public static final String OH_CHANNEL_ADBLUE_LEVEL = "adblue-level";
public static final String OH_CHANNEL_RANGE_HYBRID = "range-hybrid";
public static final String OH_CHANNEL_RANGE_FUEL = "range-fuel";
public static final String OH_CHANNEL_RANGE_ELECTRIC = "range-electric";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
*
* @author Bernd Weymann - Initial contribution
* @author Bernd Weymann - Bugfix https://github.com/openhab/openhab-addons/issues/16932
* @author Bernd Weymann - Added adblue-channel https://community.openhab.org/t/mercedes-me-binding/136852/239
*/
@NonNullByDefault
public class VehicleHandler extends BaseThingHandler {
Expand Down Expand Up @@ -709,6 +710,11 @@ public void distributeContent(VEPUpdate data) {
block = true;
}
break;
case OH_CHANNEL_ADBLUE_LEVEL:
if (!Constants.COMBUSTION.equals(vehicleType)) {
block = true;
}
break;
case OH_CHANNEL_COOLANT_FLUID:
case OH_CHANNEL_ENGINE:
case OH_CHANNEL_GAS_FLAP:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public static ChannelStateMap getChannelStateMap(String key, VehicleAttributeSta
// Percentages
case MB_KEY_SOC:
case MB_KEY_TANKLEVELPERCENT:
case MB_KEY_ADBLUELEVELPERCENT:
case MB_KEY_ECOSCORE_ACCEL:
case MB_KEY_ECOSCORE_CONSTANT:
case MB_KEY_ECOSCORE_COASTING:
Expand Down Expand Up @@ -404,6 +405,7 @@ private static void init() {
CHANNELS.put(MB_KEY_RANGELIQUID, new String[] { OH_CHANNEL_RANGE_FUEL, GROUP_RANGE });
CHANNELS.put(MB_KEY_OVERALL_RANGE, new String[] { OH_CHANNEL_RANGE_HYBRID, GROUP_RANGE });
CHANNELS.put(MB_KEY_TANKLEVELPERCENT, new String[] { OH_CHANNEL_FUEL_LEVEL, GROUP_RANGE });
CHANNELS.put(MB_KEY_ADBLUELEVELPERCENT, new String[] { OH_CHANNEL_ADBLUE_LEVEL, GROUP_RANGE });

CHANNELS.put(MB_KEY_CHARGE_FLAP_DC_STATUS, new String[] { OH_CHANNEL_CHARGE_FLAP, GROUP_CHARGE });
CHANNELS.put(MB_KEY_CHARGE_COUPLER_AC_STATUS, new String[] { OH_CHANNEL_COUPLER_AC, GROUP_CHARGE });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ channel-type.mercedesme.accel.description = Score for smooth acceleration
channel-type.mercedesme.active-hvac.label = AC Precondition Control
channel-type.mercedesme.active-hvac.description = Switch on/off precondition air conditioning
channel-type.mercedesme.active.label = Charge Active
channel-type.mercedesme.adblue-level.label = AdBlue Level
channel-type.mercedesme.adblue-level.description = AdBlue tank level in percent
channel-type.mercedesme.auto-unlock.label = Coupler Auto Unlock
channel-type.mercedesme.auto-unlock.description = Auto unlock coupler after charging
channel-type.mercedesme.aux-heat.label = Auxiliary Heating Control
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
<label>Fuel Level</label>
<state pattern="%d %%" readOnly="true"/>
</channel-type>
<channel-type id="adblue-level">
<item-type>Number:Dimensionless</item-type>
<label>AdBlue Level</label>
<description>AdBlue tank level in percent </description>
<state pattern="%d %%" readOnly="true"/>
</channel-type>
<channel-type id="fuel-remain">
<item-type>Number:Volume</item-type>
<label>Remaining Fuel</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<channel id="fuel-level" typeId="fuel-level"/>
<channel id="fuel-remain" typeId="fuel-remain"/>
<channel id="fuel-open" typeId="fuel-open"/>
<channel id="adblue-level" typeId="adblue-level"/>
</channels>
</channel-group-type>
</thing:thing-descriptions>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</channel-groups>

<properties>
<property name="thingTypeVersion">2</property>
<property name="thingTypeVersion">3</property>
</properties>

<config-description-ref uri="thing-type:mercedesme:conv"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@
<label>Status Positioning</label>
</add-channel>
</instruction-set>
<instruction-set targetVersion="3">
<add-channel id="adblue-level" groupIds="range">
<type>mercedesme:adblue-level</type>
<label>AdBlue Level</label>
<description>AdBlue tank level in percent </description>
</add-channel>
</instruction-set>
</thing-type>

</update:update-descriptions>
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ public static Map<String, Object> createBEV() {
return instances;
}

public static Map<String, Object> createCombustion() {
Thing thingMock = mock(Thing.class);
when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_COMB);
when(thingMock.getUID()).thenReturn(new ThingUID("test", Constants.COMBUSTION));
AccountHandlerMock ahm = new AccountHandlerMock();
VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(),
mock(MercedesMeCommandOptionProvider.class), mock(MercedesMeStateOptionProvider.class));
vh.accountHandler = Optional.of(ahm);
VehicleConfiguration vehicleConfig = new VehicleConfiguration();
vh.config = Optional.of(vehicleConfig);
ThingCallbackListener updateListener = new ThingCallbackListener();
vh.setCallback(updateListener);
Map<String, Object> instances = new HashMap<>();
instances.put(ThingCallbackListener.class.getCanonicalName(), updateListener);
instances.put(VehicleHandler.class.getCanonicalName(), vh);
instances.put(AccountHandlerMock.class.getCanonicalName(), ahm);
return instances;
}

@Test
public void testBEVFullUpdateNoCapacities() {
Thing thingMock = mock(Thing.class);
Expand Down Expand Up @@ -616,4 +635,21 @@ public void testEcoScore() {
assertEquals("10.2 km", updateListener.getResponse("test::bev:eco#bonus").toFullString(), "Eco Bonus");
assertEquals(ECOSCORE_UPDATE_COUNT, updateListener.getUpdatesForGroup("eco"), "ECO Update Count");
}

@Test
public void testAdBlue() {
Map<String, Object> instances = createCombustion();
ThingCallbackListener updateListener = (ThingCallbackListener) instances
.get(ThingCallbackListener.class.getCanonicalName());
VehicleHandler vHandler = (VehicleHandler) instances.get(VehicleHandler.class.getCanonicalName());
assertNotNull(updateListener);
assertNotNull(vHandler);

String json = FileReader.readFileInString("src/test/resources/proto-json/MB-Combustion.json");
VEPUpdate update = ProtoConverter.json2Proto(json, true);
vHandler.distributeContent(update);

assertEquals("29 %", updateListener.getResponse("test::combustion:range#adblue-level").toFullString(),
"AdBlue Tank Level");
}
}
Loading