Skip to content
Merged
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
34 changes: 1 addition & 33 deletions custom_components/tesla_custom/teslamate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
logger = logging.getLogger(__name__)


CHARGING_STATE_CHARGING = "Charging"


def is_car_state_charging(car_state: str) -> bool:
"""Check if car_state is charging."""
return car_state == "charging"
Expand Down Expand Up @@ -78,29 +75,6 @@ def cast_speed(speed: int) -> int:
return int(speed_miles)


def cast_plugged_in(val: str, car: TeslaCar) -> str:
"""Casts new car plugged_in.

When receiving a new value here, we also need to check the
car state to see if it is charging or not before returning
a value to be set as 'charging_state'
"""
plugged_in = cast_bool(val)

logger.debug(
"Casting plugged_in. Current state: '%s', plugged_in: '%s'",
car.state,
plugged_in,
)

if plugged_in:
return (
CHARGING_STATE_CHARGING if is_car_state_charging(car.state) else "Stopped"
)

return "Disconnected"


MAP_DRIVE_STATE = {
"latitude": ("latitude", float),
"longitude": ("longitude", float),
Expand Down Expand Up @@ -144,6 +118,7 @@ def cast_plugged_in(val: str, car: TeslaCar) -> str:
"charge_port_door_open": ("charge_port_door_open", cast_bool),
"charge_current_request": ("charge_current_request", int),
"charge_current_request_max": ("charge_current_request_max", int),
"charging_state": ("charging_state", str),
}


Expand Down Expand Up @@ -358,15 +333,8 @@ async def async_handle_new_data(self, msg: ReceiveMessage):
attr, cast = MAP_CHARGE_STATE[mqtt_attr]
self.update_car_state(car, "charge_state", attr, cast(msg.payload))

elif mqtt_attr == "plugged_in":
self.update_charging_state(car, cast_plugged_in(msg.payload, car))

elif mqtt_attr == "state":
state = msg.payload

if is_car_state_charging(state):
self.update_charging_state(car, CHARGING_STATE_CHARGING)

self.update_car_state(car, None, "state", state)

else:
Expand Down