Skip to content

Commit

Permalink
Decode model from VIN
Browse files Browse the repository at this point in the history
TeslaFi may not report `.car_type`. But we can still
decode the model from the VIN.
  • Loading branch information
jhansche committed Nov 25, 2023
1 parent e9837a1 commit 52141f1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion custom_components/teslafi/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ def name(self) -> str | None:
@property
def car_type(self) -> str | None:
"""Car type (model). E.g. 'model3', etc."""
return self.get("car_type", None)
car_type = self.get("car_type", None)
if not car_type and self.vin:
# Decode model from VIN
dig = self.vin[3]
if dig in ["S", "3", "X", "Y"]:
car_type = "model%s" % dig
return car_type

@property
def vin(self) -> str:
Expand Down

0 comments on commit 52141f1

Please sign in to comment.