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

sensors for TA trip statistics #283

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@
{"name": "API Backend status", "domain": "sensor", "id": "api_backend_status", "icon": "alert"},
{"name": "Update Interval", "domain": "number", "id": "update_interval", "unit": "seconds", "icon": "timer", "min": -1, "max": 600, "mode": "box"},
{"name": "Warnings", "domain": "sensor", "id": "warnings", "icon": "alert", "url": WARNINGS_URL}
,{"name": "Trip Fuel Consumption", "domain": "sensor", "id": "trip_fuel_consumption", "unit": VOLUME_LITERS, "icon": "fuel", "url": STATISTICS_URL}
,{"name": "Trip distance", "domain": "sensor", "id": "trip_distance", "unit": LENGTH_KILOMETERS if not units.get(settings["babelLocale"]) else units[settings["babelLocale"]]["trip_distance"]["unit"], "icon": "counter", "url": STATISTICS_URL, "state_class":"measurement"}
,{"name": "Trip Energy Consumption", "domain": "sensor", "id": "trip_energy_consumption", "unit": ENERGY_KILO_WATT_HOUR, "icon": "car-electric", "url": STATISTICS_URL}
,{"name": "Trip Speed", "domain": "sensor", "id": "trip_speed", "unit": SPEED_KILOMETERS_PER_HOUR if not units.get(settings["babelLocale"]) else units[settings["babelLocale"]]["trip_speed"]["unit"], "icon": "speedometer", "url": STATISTICS_URL, "state_class": "measurement"}
]

old_entity_ids = ["months_to_service", "service_warning_trigger", "distance_to_empty"]
Expand Down
25 changes: 25 additions & 0 deletions src/volvo.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,31 @@ def parse_api_data(data, sensor_id=None):
cleaned_data[key] = dicts["value"]

return cleaned_data if warnings > 0 else None
elif sensor_id == "trip_fuel_consumption":
trip_fuel_con = 0
if util.keys_exists(data, "averageFuelConsumptionAutomatic"):
trip_fuel_con = float(data["averageFuelConsumptionAutomatic"]["value"])
if trip_fuel_con > 0:
return trip_fuel_con
return None
elif sensor_id == "trip_distance":
return util.convert_metric_values(int(data["tripMeterAutomatic"]["value"])) \
if util.keys_exists(data, "tripMeterAutomatic") else None
elif sensor_id == "trip_energy_consumption":
trip_energy_con = 0
if util.keys_exists(data, "averageEnergyConsumptionAutomatic"):
trip_energy_con = data["averageEnergyConsumptionAutomatic"]["value"]
if trip_energy_con != 0:
return trip_energy_con
return None
elif sensor_id == "trip_speed":
trip_speed = 0
if util.keys_exists(data, "averageSpeedAutomatic"):
trip_speed = float(data["averageSpeedAutomatic"]["value"])
if trip_speed != 0:
return util.convert_metric_values(trip_speed)
return None

else:
return None

Expand Down