Skip to content

Commit

Permalink
Fix Litter-Robot 4 firmware versions reported while updating (#85710)
Browse files Browse the repository at this point in the history
  • Loading branch information
natekspencer authored and balloob committed Jan 12, 2023
1 parent 856f682 commit 2e9ea0c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/litterrobot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Litter-Robot",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/litterrobot",
"requirements": ["pylitterbot==2023.1.0"],
"requirements": ["pylitterbot==2023.1.1"],
"codeowners": ["@natekspencer", "@tkdrob"],
"dhcp": [{ "hostname": "litter-robot4" }],
"iot_class": "cloud_push",
Expand Down
15 changes: 8 additions & 7 deletions homeassistant/components/litterrobot/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,20 @@ def should_poll(self) -> bool:

async def async_update(self) -> None:
"""Update the entity."""
if await self.robot.has_firmware_update():
latest_version = await self.robot.get_latest_firmware()
else:
latest_version = self.installed_version

if self._attr_latest_version != self.installed_version:
# If the robot has a firmware update already in progress, checking for the
# latest firmware informs that an update has already been triggered, no
# firmware information is returned and we won't know the latest version.
if not self.robot.firmware_update_triggered:
latest_version = await self.robot.get_latest_firmware(True)
if not await self.robot.has_firmware_update():
latest_version = self.robot.firmware
self._attr_latest_version = latest_version

async def async_install(
self, version: str | None, backup: bool, **kwargs: Any
) -> None:
"""Install an update."""
if await self.robot.has_firmware_update():
if await self.robot.has_firmware_update(True):
if not await self.robot.update_firmware():
message = f"Unable to start firmware update on {self.robot.name}"
raise HomeAssistantError(message)
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,7 @@ pylibrespot-java==0.1.1
pylitejet==0.3.0

# homeassistant.components.litterrobot
pylitterbot==2023.1.0
pylitterbot==2023.1.1

# homeassistant.components.lutron_caseta
pylutron-caseta==0.17.1
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ pylibrespot-java==0.1.1
pylitejet==0.3.0

# homeassistant.components.litterrobot
pylitterbot==2023.1.0
pylitterbot==2023.1.1

# homeassistant.components.lutron_caseta
pylutron-caseta==0.17.1
Expand Down
33 changes: 32 additions & 1 deletion tests/components/litterrobot/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
SERVICE_INSTALL,
UpdateDeviceClass,
)
from homeassistant.const import ATTR_DEVICE_CLASS, ATTR_ENTITY_ID, STATE_OFF, STATE_ON
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_ENTITY_ID,
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError

Expand All @@ -28,6 +34,7 @@ async def test_robot_with_no_update(
"""Tests the update entity was set up."""
robot: LitterRobot4 = mock_account_with_litterrobot_4.robots[0]
robot.has_firmware_update = AsyncMock(return_value=False)
robot.get_latest_firmware = AsyncMock(return_value=None)

entry = await setup_integration(
hass, mock_account_with_litterrobot_4, PLATFORM_DOMAIN
Expand Down Expand Up @@ -79,3 +86,27 @@ async def test_robot_with_update(
)
await hass.async_block_till_done()
assert robot.update_firmware.call_count == 1


async def test_robot_with_update_already_in_progress(
hass: HomeAssistant, mock_account_with_litterrobot_4: MagicMock
):
"""Tests the update entity was set up."""
robot: LitterRobot4 = mock_account_with_litterrobot_4.robots[0]
robot._update_data( # pylint:disable=protected-access
{"isFirmwareUpdateTriggered": True}, partial=True
)

entry = await setup_integration(
hass, mock_account_with_litterrobot_4, PLATFORM_DOMAIN
)

state = hass.states.get(ENTITY_ID)
assert state
assert state.state == STATE_UNKNOWN
assert state.attributes[ATTR_DEVICE_CLASS] == UpdateDeviceClass.FIRMWARE
assert state.attributes[ATTR_INSTALLED_VERSION] == OLD_FIRMWARE
assert state.attributes[ATTR_LATEST_VERSION] is None

assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()

0 comments on commit 2e9ea0c

Please sign in to comment.