Skip to content

Commit

Permalink
feat: sync more Teslamate items (#698)
Browse files Browse the repository at this point in the history
* Improve a couple of things in MQTT sync from Teslamate

- parse boolean strings for is_climate_on, locked, sentry_mode
- add sync for plugged_in
- add sync for charge_port_door_open
- add sync for trunk_open
- add sync for frunk_open
- add sync for is_user_present
- add sync for is_preconditioning

* style: auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix lint issues

* style: auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
cguedel and pre-commit-ci[bot] authored Aug 28, 2023
1 parent dbb2929 commit 08305ed
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions custom_components/tesla_custom/teslamate.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ def cast_odometer(odometer: float) -> float:
return odometer_miles


def cast_plugged_in(val: str) -> str:
"""Convert boolean string for plugged_in value."""
return "Connected" if cast_bool(val) else "Disconnected"


def cast_bool(val: str) -> bool:
"""Convert bool string to actual bool."""
return val.lower() in ["true", "True"]


def cast_trunk_open(val: str) -> int:
"""Convert bool string to trunk/frunk open/close value."""
return 255 if cast_bool(str) else 0


def cast_speed(speed: int) -> int:
"""Convert KM to Miles.
Expand All @@ -70,19 +85,23 @@ def cast_speed(speed: int) -> int:
}

MAP_CLIMATE_STATE = {
"is_climate_on": ("is_climate_on", bool),
"is_climate_on": ("is_climate_on", cast_bool),
"inside_temp": ("inside_temp", float),
"outside_temp": ("outside_temp", float),
"is_preconditioning": ("is_preconditioning", cast_bool),
}

MAP_VEHICLE_STATE = {
"tpms_pressure_fl": ("tpms_pressure_fl", float),
"tpms_pressure_fr": ("tpms_pressure_fr", float),
"tpms_pressure_rl": ("tpms_pressure_rl", float),
"tpms_pressure_rr": ("tpms_pressure_rr", float),
"locked": ("locked", bool),
"sentry_mode": ("sentry_mode", bool),
"locked": ("locked", cast_bool),
"sentry_mode": ("sentry_mode", cast_bool),
"odometer": ("odometer", cast_odometer),
"trunk_open": ("rt", cast_trunk_open),
"frunk_open": ("ft", cast_trunk_open),
"is_user_present": ("is_user_present", cast_bool),
}

MAP_CHARGE_STATE = {
Expand All @@ -94,6 +113,8 @@ def cast_speed(speed: int) -> int:
"charger_voltage": ("charger_voltage", int),
"time_to_full_charge": ("time_to_full_charge", float),
"charge_limit_soc": ("charge_limit_soc", int),
"plugged_in": ("charging_state", cast_plugged_in),
"charge_port_door_open": ("charge_port_door_open", cast_bool),
}


Expand Down

0 comments on commit 08305ed

Please sign in to comment.