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

Bmw dynamic channels #8

Open
wants to merge 7 commits into
base: 14065_fix_connected_v2_issues
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
8 changes: 5 additions & 3 deletions bundles/org.openhab.binding.mybmw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ In the right picture can see in *remoteServicesEnabled* e.g. the *Door Lock* and
This ensures channel group [Remote Services](#remote-services) is supporting door lock and unlock remote control.

In *Services Supported* the entry *ChargingHistory* is mentioned.
So it's valid to connect channel group [Charge Sessions](#charge-sessions) in order to display your last charging sessions.
So the channel group [Charge Sessions](#charge-sessions) will be available in order to display your last charging sessions.

| Property Key | Property Value | Supported Channel Groups |
|------------------------|---------------------|------------------------------|
Expand Down Expand Up @@ -134,14 +134,15 @@ There are many channels available for each vehicle.
For better overview they are clustered in different channel groups.
They differ for each vehicle type, build-in sensors and activated services.

Channels are only available when your vehicle supports the functionality.

### Thing Channel Groups

| Channel Group ID | Description | conv | phev | bev_rex | bev |
|----------------------------------|---------------------------------------------------|------|------|---------|-----|
| [status](#vehicle-status) | Overall vehicle status | X | X | X | X |
| [range](#range-data) | Provides mileage, range and charge / fuel levels | X | X | X | X |
| [doors](#doors-details) | Detials of all doors and windows | X | X | X | X |
| [doors](#doors-details) | Details of all doors and windows | X | X | X | X |
| [check](#check-control) | Shows current active CheckControl messages | X | X | X | X |
| [service](#services) | Future vehicle service schedules | X | X | X | X |
| [location](#location) | Coordinates and heading of the vehicle | X | X | X | X |
Expand All @@ -152,6 +153,7 @@ They differ for each vehicle type, build-in sensors and activated services.
| [tires](#tire-pressure) | Current and wanted pressure for all tires | X | X | X | X |
| [image](#image) | Provides an image of your vehicle | X | X | X | X |

Channel groups are only available when your vehicle supports channels in the group.

#### Vehicle Status

Expand Down Expand Up @@ -391,7 +393,7 @@ Charging options with date and time for preferred time windows and charging mode
* Channel Group ID is **profile**
* Available for electric and hybrid vehicles
* Read access for UI.
* There are 4 timers *T1, T2, T3 and T4* available. Replace *X* with number 1,2 or 3 to target the correct timer
* There are 4 timers *T1, T2, T3 and T4* available. Replace *X* with number 1,2, 3 or 4 to target the correct timer

| Channel Label | Channel ID | Type |
|----------------------------|---------------------------|----------|
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import org.openhab.binding.mybmw.internal.handler.MyBMWBridgeHandler;
import org.openhab.binding.mybmw.internal.handler.backend.MyBMWProxy;
import org.openhab.binding.mybmw.internal.handler.backend.NetworkException;
import org.openhab.binding.mybmw.internal.handler.enums.RemoteService;
import org.openhab.binding.mybmw.internal.utils.Constants;
import org.openhab.binding.mybmw.internal.utils.VehicleStatusUtils;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
Expand Down Expand Up @@ -114,7 +112,7 @@ public void discoverVehicles() {

/**
* this method is called by the bridgeHandler if the list of vehicles was retrieved successfully
*
*
* @param vehicleList
*/
private void processVehicles(List<Vehicle> vehicleList) {
Expand Down Expand Up @@ -186,42 +184,8 @@ private Map<String, String> generateProperties(Vehicle vehicle) {
vehicleCapabilities.getCapabilitiesAsString(VehicleCapabilities.ENABLED_SUFFIX, true));
properties.put("servicesDisabled",
vehicleCapabilities.getCapabilitiesAsString(VehicleCapabilities.ENABLED_SUFFIX, false));

// For RemoteServices we need to do it step-by-step
StringBuffer remoteServicesEnabled = new StringBuffer();
StringBuffer remoteServicesDisabled = new StringBuffer();
if (vehicleCapabilities.isLock()) {
remoteServicesEnabled.append(RemoteService.DOOR_LOCK.getLabel() + Constants.SEMICOLON);
} else {
remoteServicesDisabled.append(RemoteService.DOOR_LOCK.getLabel() + Constants.SEMICOLON);
}
if (vehicleCapabilities.isUnlock()) {
remoteServicesEnabled.append(RemoteService.DOOR_UNLOCK.getLabel() + Constants.SEMICOLON);
} else {
remoteServicesDisabled.append(RemoteService.DOOR_UNLOCK.getLabel() + Constants.SEMICOLON);
}
if (vehicleCapabilities.isLights()) {
remoteServicesEnabled.append(RemoteService.LIGHT_FLASH.getLabel() + Constants.SEMICOLON);
} else {
remoteServicesDisabled.append(RemoteService.LIGHT_FLASH.getLabel() + Constants.SEMICOLON);
}
if (vehicleCapabilities.isHorn()) {
remoteServicesEnabled.append(RemoteService.HORN_BLOW.getLabel() + Constants.SEMICOLON);
} else {
remoteServicesDisabled.append(RemoteService.HORN_BLOW.getLabel() + Constants.SEMICOLON);
}
if (vehicleCapabilities.isVehicleFinder()) {
remoteServicesEnabled.append(RemoteService.VEHICLE_FINDER.getLabel() + Constants.SEMICOLON);
} else {
remoteServicesDisabled.append(RemoteService.VEHICLE_FINDER.getLabel() + Constants.SEMICOLON);
}
if (vehicleCapabilities.isVehicleFinder()) {
remoteServicesEnabled.append(RemoteService.CLIMATE_NOW_START.getLabel() + Constants.SEMICOLON);
} else {
remoteServicesDisabled.append(RemoteService.CLIMATE_NOW_START.getLabel() + Constants.SEMICOLON);
}
properties.put("remoteServicesEnabled", remoteServicesEnabled.toString().trim());
properties.put("remoteServicesDisabled", remoteServicesDisabled.toString().trim());
properties.put("remoteServicesEnabled", vehicleCapabilities.getRemoteServicesAsString(true));
properties.put("remoteServicesDisabled", vehicleCapabilities.getRemoteServicesAsString(false));

return properties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.openhab.binding.mybmw.internal.dto.charge.RemoteChargingCommands;
import org.openhab.binding.mybmw.internal.handler.enums.RemoteService;
import org.openhab.binding.mybmw.internal.utils.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -152,7 +154,7 @@ public DigitalKey getDigitalKey() {

/*
* (non-Javadoc)
*
*
* @see java.lang.Object#toString()
*/

Expand Down Expand Up @@ -190,7 +192,7 @@ public String toString() {

/**
* returns a list of capabilities filtered by the provided suffix and the enabled requirement
*
*
* @param suffix
* @param enabled
* @return
Expand Down Expand Up @@ -230,4 +232,45 @@ private List<String> getCapabilitiesAsStringList(String suffix, boolean compare)

return l;
}

public List<RemoteService> getRemoteServices(boolean enabled) {
List<RemoteService> services = new ArrayList<>();
if ((enabled && isLock()) || (!enabled && !isLock())) {
services.add(RemoteService.DOOR_LOCK);
}
if ((enabled && isUnlock()) || (!enabled && !isUnlock())) {
services.add(RemoteService.DOOR_UNLOCK);
}
if ((enabled && isLights()) || (!enabled && !isLights())) {
services.add(RemoteService.LIGHT_FLASH);
}
if ((enabled && isHorn()) || (!enabled && !isHorn())) {
services.add(RemoteService.HORN_BLOW);
}
if ((enabled && isVehicleFinder()) || (!enabled && !isVehicleFinder())) {
services.add(RemoteService.VEHICLE_FINDER);
}
if ((enabled && isClimateNow()) || (!enabled && !isClimateNow())) {
services.add(RemoteService.CLIMATE_NOW_START);
}
if ((enabled && !remoteChargingCommands.getChargingControl().isEmpty())
|| (!enabled && remoteChargingCommands.getChargingControl().isEmpty())) {
services.add(RemoteService.CHARGE_NOW);
}
return services;
}

public String getRemoteServicesAsString(boolean enabled) {
StringBuffer remoteServicesAsString = new StringBuffer();
List<String> remoteServicesAsStringList = getRemoteServices(enabled).stream().map(RemoteService::getLabel)
.collect(Collectors.toUnmodifiableList());

for (String serviceEntry : remoteServicesAsStringList) {
if (remoteServicesAsString.length() > 0) {
remoteServicesAsString.append(Constants.SEMICOLON);
}
remoteServicesAsString.append(serviceEntry);
}
return remoteServicesAsString.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
package org.openhab.binding.mybmw.internal.dto.vehicle;

/**
*
*
* derived from the API responses
*
*
* @author Martin Grassl - initial contribution
*/
public class VehicleTireStates {
Expand Down Expand Up @@ -56,6 +56,20 @@ public void setRearRight(VehicleTireState rearRight) {
this.rearRight = rearRight;
}

public boolean isTireStateMeasured() {
return (getFrontLeft().getStatus().getTargetPressure() >= 0)
|| (getFrontRight().getStatus().getTargetPressure() >= 0)
|| (getRearLeft().getStatus().getTargetPressure() >= 0)
|| (getRearRight().getStatus().getTargetPressure() >= 0);
}

public boolean hasTireStateTarget() {
return (getFrontLeft().getStatus().getCurrentPressure() >= 0)
|| (getFrontRight().getStatus().getCurrentPressure() >= 0)
|| (getRearLeft().getStatus().getCurrentPressure() >= 0)
|| (getRearRight().getStatus().getCurrentPressure() >= 0);
}

@Override
public String toString() {
return "VehicleTireStates [frontLeft=" + frontLeft + ", frontRight=" + frontRight + ", rearLeft=" + rearLeft
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public void handleCommand(ChannelUID channelUID, Command command) {
@Override
public void initialize() {
logger.trace("xxxMyBMWBridgeHandler.initialize");
updateStatus(ThingStatus.UNKNOWN);
MyBMWBridgeConfiguration config = getConfigAs(MyBMWBridgeConfiguration.class);
if (config.language.equals(Constants.LANGUAGE_AUTODETECT)) {
config.language = localeLanguage;
Expand Down
Loading