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

Set car sensors state appropriately if sensor registers with unit of measurement #3764

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class CarSensorManager :
onSensorUpdated(
context,
it,
context.getString(R.string.car_data_unavailable),
"unavailable",
it.statelessIcon,
mapOf()
)
Expand Down Expand Up @@ -257,19 +257,25 @@ class CarSensorManager :
onSensorUpdated(
context,
fuelLevel,
fuelStatus ?: data.fuelPercent.value!!,
if (fuelStatus == "success") data.fuelPercent.value!! else "unknown",
fuelLevel.statelessIcon,
mapOf()
mapOf(
"status" to fuelStatus
),
forceUpdate = true
)
}
val batteryStatus = carValueStatus(data.batteryPercent.status)
if (isEnabled(context, batteryLevel)) {
onSensorUpdated(
context,
batteryLevel,
batteryStatus ?: data.batteryPercent.value!!,
if (batteryStatus == "success") data.batteryPercent.value!! else "unknown",
batteryLevel.statelessIcon,
mapOf()
mapOf(
"status" to batteryStatus
),
forceUpdate = true
)
}
setListener(Listener.ENERGY, false)
Expand All @@ -282,12 +288,14 @@ class CarSensorManager :
onSensorUpdated(
context,
carName,
status ?: data.name.value!!,
if (status == "success") data.name.value!! else "unknown",
carName.statelessIcon,
mapOf(
"car_manufacturer" to data.manufacturer.value,
"car_manufactured_year" to data.year.value
)
"car_manufactured_year" to data.year.value,
"status" to status
),
forceUpdate = true
)
}
setListener(Listener.MODEL, false)
Expand All @@ -301,11 +309,13 @@ class CarSensorManager :
onSensorUpdated(
context,
carStatus,
status ?: (data.evChargePortConnected.value == true),
if (status == "success") (data.evChargePortConnected.value == true) else "unknown",
carStatus.statelessIcon,
mapOf(
"car_charge_port_open" to (data.evChargePortOpen.value == true)
)
"car_charge_port_open" to (data.evChargePortOpen.value == true),
"status" to status
),
forceUpdate = true
)
}
setListener(Listener.STATUS, false)
Expand All @@ -319,9 +329,12 @@ class CarSensorManager :
onSensorUpdated(
context,
odometerValue,
status ?: data.odometerMeters.value!!,
if (status == "success") data.odometerMeters.value!! else "unknown",
odometerValue.statelessIcon,
mapOf()
mapOf(
"status" to status
),
forceUpdate = true
)
}
setListener(Listener.MILEAGE, false)
Expand All @@ -335,29 +348,35 @@ class CarSensorManager :
onSensorUpdated(
context,
fuelType,
fuelTypeStatus ?: getFuelType(data.fuelTypes.value!!),
if (fuelTypeStatus == "success") getFuelType(data.fuelTypes.value!!) else "unknown",
fuelType.statelessIcon,
mapOf()
mapOf(
"status" to fuelTypeStatus
),
forceUpdate = true
)
}
if (isEnabled(context, evConnector)) {
onSensorUpdated(
context,
evConnector,
evConnectorTypeStatus ?: getEvConnectorType(data.evConnectorTypes.value!!),
if (evConnectorTypeStatus == "success") getEvConnectorType(data.evConnectorTypes.value!!) else "unknown",
evConnector.statelessIcon,
mapOf()
mapOf(
"status" to evConnectorTypeStatus
),
forceUpdate = true
)
}
}

private fun carValueStatus(value: Int): String? {
return when (value) {
CarValue.STATUS_SUCCESS -> null
CarValue.STATUS_SUCCESS -> "success"
CarValue.STATUS_UNAVAILABLE -> "unavailable"
CarValue.STATUS_UNKNOWN -> "unknown"
CarValue.STATUS_UNIMPLEMENTED -> "unimplemented"
else -> "unavailable"
else -> null
}
}

Expand Down
1 change: 0 additions & 1 deletion common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,6 @@
<string name="ha_assist">HA: Assist</string>
<string name="only_favorites">Only Show Favorites</string>
<string name="beacon_scanning">Beacon Monitor Scanning</string>
<string name="car_data_unavailable">Open Home Assistant app to activate the sensor</string>
<string name="basic_sensor_name_car_fuel_type">Car Fuel Type</string>
<string name="sensor_description_car_fuel_type">List of available fuel types for the connected car</string>
<string name="basic_sensor_name_car_ev_connector_type">Car EV Connector Type</string>
Expand Down