From ca481c3a32854bc6b0faba67bd101f64d069d91d Mon Sep 17 00:00:00 2001 From: Joe Hansche Date: Fri, 24 Nov 2023 19:26:33 -0500 Subject: [PATCH] Decode model from VIN TeslaFi may not report `.car_type`. But we can still decode the model from the VIN. --- custom_components/teslafi/model.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/custom_components/teslafi/model.py b/custom_components/teslafi/model.py index bfa79e6..877f6bb 100644 --- a/custom_components/teslafi/model.py +++ b/custom_components/teslafi/model.py @@ -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: