use EnBW AvailabilityDetector only for supported countries

This commit is contained in:
Johan von Forstner
2022-06-05 17:17:26 +02:00
parent 8b8ba26a9f
commit c35ca24906
4 changed files with 44 additions and 2 deletions

View File

@@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit
interface AvailabilityDetector {
suspend fun getAvailability(location: ChargeLocation): ChargeLocationStatus
fun isCountrySupported(country: String, dataSource: String): Boolean
}
abstract class BaseAvailabilityDetector(private val client: OkHttpClient) : AvailabilityDetector {
@@ -157,8 +158,8 @@ private val okhttp = OkHttpClient.Builder()
.cookieJar(JavaNetCookieJar(cookieManager))
.build()
val availabilityDetectors = listOf(
NewMotionAvailabilityDetector(okhttp),
EnBwAvailabilityDetector(okhttp)
EnBwAvailabilityDetector(okhttp),
NewMotionAvailabilityDetector(okhttp)
/*ChargecloudAvailabilityDetector(
okhttp,
"606a0da0dfdd338ee4134605653d4fd8"
@@ -171,8 +172,12 @@ val availabilityDetectors = listOf(
suspend fun getAvailability(charger: ChargeLocation): Resource<ChargeLocationStatus> {
var value: Resource<ChargeLocationStatus>? = null
val country = charger.chargepriceData?.country
?: charger.address?.country
?: return Resource.error(null, null)
withContext(Dispatchers.IO) {
for (ad in availabilityDetectors) {
if (!ad.isCountrySupported(country, charger.dataSource)) continue
try {
value = Resource.success(ad.getAvailability(charger))
break

View File

@@ -80,6 +80,10 @@ class ChargecloudAvailabilityDetector(
}
}
override fun isCountrySupported(country: String, dataSource: String): Boolean {
TODO("Not yet implemented")
}
private fun getType(string: String): String {
return when (string) {
"IEC_62196_T2" -> Chargepoint.TYPE_2_UNKNOWN

View File

@@ -194,4 +194,32 @@ class EnBwAvailabilityDetector(client: OkHttpClient, baseUrl: String? = null) :
)
}
override fun isCountrySupported(country: String, dataSource: String): Boolean =
when (dataSource) {
// list of countries as of 2021/06/30, according to
// https://www.electrive.net/2021/06/30/enbw-expandiert-mit-ladenetz-in-drei-weitere-laender/
"goingelectric" -> country in listOf(
"Deutschland",
"Österreich",
"Schweiz",
"Frankreich",
"Belgien",
"Niederlande",
"Luxemburg",
"Liechtenstein",
"Italien",
)
"openchargemap" -> country in listOf(
"DE",
"AT",
"CH",
"FR",
"BE",
"NE",
"LU",
"LI",
"IT"
)
else -> false
}
}

View File

@@ -173,4 +173,9 @@ class NewMotionAvailabilityDetector(client: OkHttpClient, baseUrl: String? = nul
)
}
override fun isCountrySupported(country: String, dataSource: String): Boolean {
// NewMotion is our fallback
return true
}
}