Skip to content

Commit

Permalink
re-add PredictionRepository so that Tesla congestion data is displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
johan12345 committed Aug 12, 2024
1 parent 41be3e0 commit efacd46
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package net.vonforst.evmap.api.fronyx

import android.content.Context
import com.squareup.moshi.JsonDataException
import net.vonforst.evmap.R
import net.vonforst.evmap.api.availability.AvailabilityDetectorException
import net.vonforst.evmap.api.availability.AvailabilityRepository
import net.vonforst.evmap.api.availability.ChargeLocationStatus
import net.vonforst.evmap.api.equivalentPlugTypes
import net.vonforst.evmap.api.nameForPlugType
Expand All @@ -13,8 +10,6 @@ import net.vonforst.evmap.model.ChargeLocation
import net.vonforst.evmap.model.Chargepoint
import net.vonforst.evmap.storage.PreferenceDataSource
import net.vonforst.evmap.viewmodel.Resource
import retrofit2.HttpException
import java.io.IOException
import java.time.LocalDate
import java.time.LocalTime
import java.time.ZoneId
Expand Down Expand Up @@ -55,9 +50,9 @@ class PredictionRepository(private val context: Context) {
evseIds: Map<Chargepoint, List<String>>,
filteredConnectors: Set<String>?
): Resource<List<FronyxEvseIdResponse>> {
if (!prefs.predictionEnabled) return Resource.success(null)
return Resource.success(null)

val allEvseIds =
/*val allEvseIds =
evseIds.filterKeys {
FronyxApi.isChargepointSupported(charger, it) &&
filteredConnectors?.let { filtered ->
Expand Down Expand Up @@ -89,7 +84,7 @@ class PredictionRepository(private val context: Context) {
// malformed JSON response from fronyx API
e.printStackTrace()
return Resource.error(e.message, null)
}
}*/
}

private fun buildPredictionGraph(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import net.vonforst.evmap.api.availability.tesla.Pricing
import net.vonforst.evmap.api.chargeprice.ChargepriceApi
import net.vonforst.evmap.api.createApi
import net.vonforst.evmap.api.fronyx.PredictionData
import net.vonforst.evmap.api.fronyx.PredictionRepository
import net.vonforst.evmap.model.ChargeLocation
import net.vonforst.evmap.model.Cost
import net.vonforst.evmap.model.FaultReport
Expand Down Expand Up @@ -81,7 +82,7 @@ class ChargerDetailScreen(ctx: CarContext, val chargerSparse: ChargeLocation) :
ChargeLocationsRepository(createApi(prefs.dataSource, ctx), lifecycleScope, db, prefs)
private val availabilityRepo = AvailabilityRepository(ctx)

//private val predictionRepo = PredictionRepository(ctx)
private val predictionRepo = PredictionRepository(ctx)
private val timeFormat = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)

private val imageSize = 128 // images should be 128dp according to docs
Expand Down Expand Up @@ -559,7 +560,7 @@ class ChargerDetailScreen(ctx: CarContext, val chargerSparse: ChargeLocation) :

invalidate()

//prediction = predictionRepo.getPredictionData(charger, availability)
prediction = predictionRepo.getPredictionData(charger, availability)

invalidate()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import net.vonforst.evmap.api.availability.ChargeLocationStatus
import net.vonforst.evmap.api.availability.tesla.Pricing
import net.vonforst.evmap.api.createApi
import net.vonforst.evmap.api.fronyx.PredictionData
import net.vonforst.evmap.api.fronyx.PredictionRepository
import net.vonforst.evmap.api.goingelectric.GEChargepoint
import net.vonforst.evmap.api.openchargemap.OCMConnection
import net.vonforst.evmap.api.openchargemap.OCMReferenceData
Expand Down Expand Up @@ -265,14 +266,13 @@ class MapViewModel(application: Application, private val state: SavedStateHandle
it.data?.extraData as? Pricing
}

//private val predictionRepository = PredictionRepository(application)
private val predictionRepository = PredictionRepository(application)

val predictionData: LiveData<PredictionData> = availability.switchMap { av ->
/*liveData {
liveData {
val charger = charger.value?.data ?: return@liveData
emit(predictionRepository.getPredictionData(charger, av.data, filteredConnectors.value))
}*/
MutableLiveData()
}
}

val myLocationEnabled: MutableLiveData<Boolean> by lazy {
Expand Down

0 comments on commit efacd46

Please sign in to comment.