Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: memorize unique id #534

Merged
merged 2 commits into from
Mar 14, 2023
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
11 changes: 9 additions & 2 deletions custom_components/tesla_custom/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(
self._enabled_by_default: bool = True
self.hass = hass
self.type = None
self._memorized_unique_id = None

def refresh(self) -> None:
"""Refresh the device data.
Expand Down Expand Up @@ -106,7 +107,9 @@ def vehicle_name(self) -> str:
@property
def unique_id(self) -> str:
"""Return unique id for car entity."""
return slugify(f"{self._car.vin} {self.type}")
if not self._memorized_unique_id:
self._memorized_unique_id = slugify(f"{self._car.vin} {self.type}")
return self._memorized_unique_id

@property
def device_info(self) -> DeviceInfo:
Expand Down Expand Up @@ -145,7 +148,11 @@ def __init__(
@property
def unique_id(self) -> str:
"""Return unique id for energy site device."""
return slugify(f"{self._energysite.energysite_id} {self.type}")
if not self._memorized_unique_id:
self._memorized_unique_id = slugify(
f"{self._energysite.energysite_id} {self.type}"
)
return self._memorized_unique_id

@property
def sw_version(self) -> bool:
Expand Down