EVMap icon indicating copy to clipboard operation
EVMap copied to clipboard

Matching availability data fails when a charge location has both type 2 sockets and type 2 plugs

Open robho opened this issue 3 months ago • 1 comments

When a charge location has both type 2 sockets and plugs, the availability matching fails -> there's no availability shown although availability data does exist.

~~A charge location showing this problem can be found at 56.52561,16.385619 when using Nobil data source. The charge location is named "ICA NÄRA SKANSEN" and has 6 x type 2 plugs and 2 x type 2 sockets.~~

A charge location showing this problem can be found at 56.190809,14.845957 when using Nobil data source. The charge location is named "Best western Karlshamn" and has 1 x type 2 plug and 5 x type 2 sockets.

The problem seems to be in function matchChargepoints. The found availability connectors are all TYPE_2_UNKNOWN and are merged into a single connector type, while the nobil connectors are TYPE_2_SOCKET and TYPE_2_PLUG and merged into two connector types. Since the number of connectors don't match the availability matching fails.

robho avatar Sep 28 '25 21:09 robho

I took a look at this problem and created this patch that shows more in detail what the problem is:

--- a/app/src/main/java/net/vonforst/evmap/api/availability/AvailabilityDetector.kt
+++ b/app/src/main/java/net/vonforst/evmap/api/availability/AvailabilityDetector.kt
@@ -79,6 +79,12 @@ abstract class BaseAvailabilityDetector(private val client: OkHttpClient) : Avai
                 geTypes = geTypes.filter { it != Chargepoint.SCHUKO }.toSet()
                 cpts = cpts.filter { it.type != Chargepoint.SCHUKO }
             }
+            if (!equivalentTypes.any { it == geTypes } && geTypes.contains(Chargepoint.TYPE_2_SOCKET) && geTypes.contains(
+                    Chargepoint.TYPE_2_PLUG
+                )) {
+                // Availability services may not distinguish between sockets and plugs
+                geTypes = geTypes.filter { it != Chargepoint.TYPE_2_PLUG }.toSet()
+            }
             if (!equivalentTypes.any { it == geTypes }) throw AvailabilityDetectorException("chargepoints do not match")
             return types.flatMap { type ->
                 // find connectors of this type
@@ -96,6 +102,21 @@ abstract class BaseAvailabilityDetector(private val client: OkHttpClient) : Avai
                         val chargepoint =
                             cpts.find { equivalentPlugTypes(it.type).any { it == type } && it.power == gePower }!!
                         val ids = connsOfType.filter { it.value.first == power }.keys
+
+                        if (chargepoint.count < ids.size && type == Chargepoint.TYPE_2_UNKNOWN) {
+                            // Try to merge equivalent type2 connectors
+                            val type2Chargepoints =
+                                    cpts.filter { equivalentPlugTypes(it.type).any { it == type } && it.power == gePower }!!
+                            if (type2Chargepoints.sumOf { it.count } == ids.size) {
+                                val allIds = ids.toList()
+                                var i = 0
+                                return@flatMap type2Chargepoints.map {
+                                    val ids = allIds.subList(i, i + it.count).toSet()
+                                    i += it.count
+                                    it to ids
+                                }
+                            }
+                        }
                         if (chargepoint.count != ids.size) {
                             throw AvailabilityDetectorException("chargepoints do not match")
                         }

I'm not sure this is a good fix. It does fix the problem described in this bug, but I don't know if it introduces any other problems and the fix is not very elegant..

(The charger I mentioned in the bug report is not a good example of this bug (realtime data doesn't match nobil data (7 vs 8 connectors)). Instead 'Best western Karlshamn' at position 56.190809,14.845957 is a better example.)

robho avatar Oct 26 '25 22:10 robho