Skip to content

Commit

Permalink
Add update_percentage and make in_progress a boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Hendrix committed Nov 25, 2024
1 parent 12d9df7 commit b871a69
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
25 changes: 18 additions & 7 deletions custom_components/tesla_custom/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,34 @@ def installed_version(self) -> str:
return version_str

@property
def in_progress(self):
def in_progress(self) -> bool:
"""Get Progress, if updating."""
update_status = None

if self._car.software_update:
update_status = self._car.software_update.get("status")
# If the update is scheduled, don't consider in-progress so the
# user can still install immediately if desired
if update_status == "scheduled":
return False
# If its actually installing, we can use the install_perc
if update_status == "installing":
progress = self._car.software_update.get("install_perc")
return progress
return True
# Otherwise, we're not updating, so return False
return False

@property
def update_percentage(self) -> int | None:
"""Get update percentate, if updating."""
update_status = None

if self._car.software_update:
update_status = self._car.software_update.get("status")

# If its actually installing, we can use the install_perc
if update_status == "installing":
install_perc = self._car.software_update.get("install_perc")
return install_perc

# Otherwise, we're not updating, so return None
return None

async def async_install(self, version, backup: bool, **kwargs: Any) -> None:
"""Install an Update."""
# Ask Tesla to start the update now.
Expand Down
8 changes: 7 additions & 1 deletion tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async def test_status_download_wait_wifi(hass: HomeAssistant) -> None:
assert state.attributes.get("latest_version") == "2022.36.20 (Waiting on Wi-Fi)"
assert state.attributes.get("installed_version") == "2022.8.10.1"
assert state.attributes.get("in_progress") is False
assert state.attributes.get("update_percentage") is None
assert (
state.attributes.get("release_url")
== "https://www.notateslaapp.com/software-updates/version/2022.36.20/release-notes"
Expand Down Expand Up @@ -67,6 +68,7 @@ async def test_status_downloading(hass: HomeAssistant) -> None:
assert state.attributes.get("latest_version") == "2022.36.20 (Downloading)"
assert state.attributes.get("installed_version") == "2022.8.10.1"
assert state.attributes.get("in_progress") is False
assert state.attributes.get("update_percentage") is None
assert (
state.attributes.get("release_url")
== "https://www.notateslaapp.com/software-updates/version/2022.36.20/release-notes"
Expand Down Expand Up @@ -96,6 +98,7 @@ async def test_status_available(hass: HomeAssistant) -> None:
assert state.attributes.get("latest_version") == "2022.36.20 (Available to install)"
assert state.attributes.get("installed_version") == "2022.8.10.1"
assert state.attributes.get("in_progress") is False
assert state.attributes.get("update_percentage") is None
assert (
state.attributes.get("release_url")
== "https://www.notateslaapp.com/software-updates/version/2022.36.20/release-notes"
Expand Down Expand Up @@ -132,6 +135,7 @@ async def test_status_scheduled(hass: HomeAssistant) -> None:
)
assert state.attributes.get("installed_version") == "2022.8.10.1"
assert state.attributes.get("in_progress") is False
assert state.attributes.get("update_percentage") is None
assert (
state.attributes.get("release_url")
== "https://www.notateslaapp.com/software-updates/version/2022.36.20/release-notes"
Expand Down Expand Up @@ -163,7 +167,8 @@ async def test_status_installing(hass: HomeAssistant) -> None:
assert state.state == STATE_ON
assert state.attributes.get("latest_version") == "2022.36.20 (Installing)"
assert state.attributes.get("installed_version") == "2022.8.10.1"
assert state.attributes.get("in_progress") == 30
assert state.attributes.get("in_progress") is True
assert state.attributes.get("update_percentage") == 30

Check failure on line 171 in tests/test_update.py

View workflow job for this annotation

GitHub Actions / Run tests

test_status_installing AssertionError: assert None == 30 + where None = <built-in method get of ReadOnlyDict object at 0x7f7498a91090>('update_percentage') + where <built-in method get of ReadOnlyDict object at 0x7f7498a91090> = {'auto_update': False, 'installed_version': '2022.8.10.1', 'in_progress': True, 'latest_version': '2022.36.20 (Install...stom/icon.png', 'friendly_name': 'My Model S Software update', 'supported_features': <UpdateEntityFeature.PROGRESS: 4>}.get + where {'auto_update': False, 'installed_version': '2022.8.10.1', 'in_progress': True, 'latest_version': '2022.36.20 (Install...stom/icon.png', 'friendly_name': 'My Model S Software update', 'supported_features': <UpdateEntityFeature.PROGRESS: 4>} = <state update.my_model_s_software_update=on; auto_update=False, installed_version=2022.8.10.1, in_progress=True, lates...sla_custom/icon.png, friendly_name=My Model S Software update, supported_features=4 @ 2024-11-25T08:17:22.572783-08:00>.attributes
assert (
state.attributes.get("release_url")
== "https://www.notateslaapp.com/software-updates/version/2022.36.20/release-notes"
Expand Down Expand Up @@ -193,6 +198,7 @@ async def test_status_none(hass: HomeAssistant) -> None:
assert state.attributes.get("latest_version") == "2022.8.10.1"
assert state.attributes.get("installed_version") == "2022.8.10.1"
assert state.attributes.get("in_progress") is False
assert state.attributes.get("update_percentage") is None
assert (
state.attributes.get("release_url")
== "https://www.notateslaapp.com/software-updates/version/2022.8.10.1/release-notes"
Expand Down

0 comments on commit b871a69

Please sign in to comment.