Skip to content

Commit

Permalink
Merge pull request #720 from alandtse/dev
Browse files Browse the repository at this point in the history
chore: release 2023-09-29
  • Loading branch information
alandtse authored Sep 29, 2023
2 parents e2e0880 + 76cc5c7 commit 5b6c88f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
19 changes: 9 additions & 10 deletions custom_components/tesla_custom/teslamate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,18 @@
logger = logging.getLogger(__name__)


def cast_odometer(odometer: float) -> float:
def cast_km_to_miles(km_to_convert: float) -> float:
"""Convert KM to Miles.
The Tesla API natively returns the Odometer in Miles.
TeslaMate returns the Odometer in KMs.
We need to convert to Miles so the Odometer sensor calculates
The Tesla API natively returns properties in Miles.
TeslaMate returns some properties in KMs.
We need to convert to Miles so the home assistant sensor calculates
properly.
"""
odometer_km = float(odometer)
odometer_miles = DistanceConverter.convert(
odometer_km, UnitOfLength.KILOMETERS, UnitOfLength.MILES
)
km = float(km_to_convert)
miles = DistanceConverter.convert(km, UnitOfLength.KILOMETERS, UnitOfLength.MILES)

return odometer_miles
return miles


def cast_plugged_in(val: str) -> str:
Expand Down Expand Up @@ -98,14 +96,15 @@ def cast_speed(speed: int) -> int:
"tpms_pressure_rr": ("tpms_pressure_rr", float),
"locked": ("locked", cast_bool),
"sentry_mode": ("sentry_mode", cast_bool),
"odometer": ("odometer", cast_odometer),
"odometer": ("odometer", cast_km_to_miles),
"trunk_open": ("rt", cast_trunk_open),
"frunk_open": ("ft", cast_trunk_open),
"is_user_present": ("is_user_present", cast_bool),
}

MAP_CHARGE_STATE = {
"battery_level": ("battery_level", float),
"est_battery_range_km": ("battery_range", cast_km_to_miles),
"usable_battery_level": ("usable_battery_level", float),
"charge_energy_added": ("charge_energy_added", float),
"charger_actual_current": ("charger_actual_current", int),
Expand Down
38 changes: 38 additions & 0 deletions custom_components/tesla_custom/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,43 @@
}
}
}
},
"services": {
"api": {
"name": "Run API Command",
"description": "Run an API command using controller.api",
"fields": {
"email": {
"name": "Email address",
"description": "Email address (optional if only one account)"
},
"command": {
"name": "Command",
"description": "Command to run. See https://github.com/zabuldon/teslajsonpy/blob/master/teslajsonpy/endpoints.json"
},
"parameters": {
"name": "Parameters",
"description": "Parameters in a dictionary. `path_vars` replace variables in endpoints.json path. All others are passed directly to controller.api. For command parameters see https://tesla-api.timdorr.com/vehicle/commands."
}
}
},
"polling_interval": {
"name": "Set Polling Interval",
"description": "Set the polling interval for the Tesla API",
"fields": {
"scan_interval": {
"name": "Interval (seconds)",
"description": "Number of seconds between each poll. See https://github.com/alandtse/tesla/wiki/Polling-policy more information."
},
"email": {
"name": "Email address",
"description": "Email address (optional if only one account)"
},
"vin": {
"name": "Vehicle VIN",
"description": "Vehicle VIN (if not provided then default polling interval will be updated)"
}
}
}
}
}

0 comments on commit 5b6c88f

Please sign in to comment.