@@ -3,7 +3,13 @@ package net.vonforst.evmap.api.openstreetmap
33import com.squareup.moshi.Json
44import com.squareup.moshi.JsonClass
55import kotlinx.parcelize.Parcelize
6- import net.vonforst.evmap.model.*
6+ import net.vonforst.evmap.model.Address
7+ import net.vonforst.evmap.model.ChargeLocation
8+ import net.vonforst.evmap.model.Chargepoint
9+ import net.vonforst.evmap.model.ChargerPhoto
10+ import net.vonforst.evmap.model.Coordinate
11+ import net.vonforst.evmap.model.Cost
12+ import net.vonforst.evmap.model.OpeningHours
713import okhttp3.internal.immutableListOf
814import java.time.Instant
915import java.time.ZonedDateTime
@@ -239,10 +245,24 @@ data class OSMChargingStation(
239245 if (rawOutput == null ) {
240246 return null
241247 }
242- val pattern = Regex (" ([0-9.,]+)\\ s*(kW|kVA)" , setOf (RegexOption .IGNORE_CASE ))
243- val matchResult = pattern.matchEntire(rawOutput) ? : return null
244- val numberString = matchResult.groupValues[1 ].replace(' ,' , ' .' )
245- return numberString.toDoubleOrNull()
248+ val kwPattern = Regex (" ([0-9.,]+)\\ s*(kW|kVA)" , setOf (RegexOption .IGNORE_CASE ))
249+ kwPattern.matchEntire(rawOutput)?.let { matchResult ->
250+ val numberString = matchResult.groupValues[1 ].replace(' ,' , ' .' )
251+ return numberString.toDoubleOrNull()
252+ }
253+
254+ val numberPattern = Regex (" ([0-9.,]+)" )
255+ numberPattern.matchEntire(rawOutput)?.let { matchResult ->
256+ // just a number is mapped without unit
257+ val numberString = matchResult.groupValues[1 ].replace(' ,' , ' .' )
258+ val number = numberString.toDoubleOrNull()
259+ return number?.let {
260+ // assume kW if the number is < 1000, otherwise assume W and convert to kW
261+ if (number < 1000 ) number else number / 1000
262+ }
263+ }
264+
265+ return null
246266 }
247267 }
248268}
0 commit comments