diff --git a/custom_components/tesla_custom/teslamate.py b/custom_components/tesla_custom/teslamate.py index ccb82f06..f835d813 100644 --- a/custom_components/tesla_custom/teslamate.py +++ b/custom_components/tesla_custom/teslamate.py @@ -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: @@ -98,7 +96,7 @@ 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), @@ -106,6 +104,7 @@ def cast_speed(speed: int) -> int: 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), diff --git a/custom_components/tesla_custom/translations/en.json b/custom_components/tesla_custom/translations/en.json index da991e0a..9f326c06 100644 --- a/custom_components/tesla_custom/translations/en.json +++ b/custom_components/tesla_custom/translations/en.json @@ -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)" + } + } + } } }