Esempio n. 1
0
def _format_cbs_report(report: ConditionBasedServiceReport,
                       unit_system: UnitSystem) -> dict[str, Any]:
    result: dict[str, Any] = {}
    service_type = report.service_type.lower().replace("_", " ")
    result[f"{service_type} status"] = report.state.value
    if report.due_date is not None:
        result[f"{service_type} date"] = report.due_date.strftime("%Y-%m-%d")
    if report.due_distance is not None:
        distance = round(
            unit_system.length(report.due_distance, LENGTH_KILOMETERS))
        result[
            f"{service_type} distance"] = f"{distance} {unit_system.length_unit}"
    return result
Esempio n. 2
0
def _format_cbs_report(
    report: ConditionBasedService, unit_system: UnitSystem
) -> dict[str, Any]:
    result: dict[str, Any] = {}
    service_type = report.service_type.lower()
    result[service_type] = report.state.value
    if report.due_date is not None:
        result[f"{service_type}_date"] = report.due_date.strftime("%Y-%m-%d")
    if report.due_distance.value and report.due_distance.unit:
        distance = round(
            unit_system.length(
                report.due_distance.value,
                UNIT_MAP.get(report.due_distance.unit, report.due_distance.unit),
            )
        )
        result[f"{service_type}_distance"] = f"{distance} {unit_system.length_unit}"
    return result