From 6176bb954c4aa68b33c9db487dbb5712059f4b38 Mon Sep 17 00:00:00 2001 From: Regev Brody Date: Wed, 19 Jan 2022 17:35:20 +0200 Subject: [PATCH] fix: 17track package summary status is not updated when there are no more packages in that summary (#64421) * 17track package status is not updated when there are no packages * 17track package status is not updated when there are no packages * 17track package status is not updated when there are no packages --- .../components/seventeentrack/sensor.py | 5 +-- .../components/seventeentrack/test_sensor.py | 34 ++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/seventeentrack/sensor.py b/homeassistant/components/seventeentrack/sensor.py index 688f4e7e2df..36fabaa7337 100644 --- a/homeassistant/components/seventeentrack/sensor.py +++ b/homeassistant/components/seventeentrack/sensor.py @@ -150,8 +150,9 @@ class SeventeenTrackSummarySensor(SensorEntity): } ) - if package_data: - self._attr_extra_state_attributes[ATTR_PACKAGES] = package_data + self._attr_extra_state_attributes[ATTR_PACKAGES] = ( + package_data if package_data else None + ) self._state = self._data.summary.get(self._status) diff --git a/tests/components/seventeentrack/test_sensor.py b/tests/components/seventeentrack/test_sensor.py index d8d75f827f7..98e64a8c778 100644 --- a/tests/components/seventeentrack/test_sensor.py +++ b/tests/components/seventeentrack/test_sensor.py @@ -379,12 +379,37 @@ async def test_becomes_delivered_not_shown_notification(hass): async def test_summary_correctly_updated(hass): """Ensure summary entities are not duplicated.""" + package = Package( + tracking_number="456", + destination_country=206, + friendly_name="friendly name 1", + info_text="info text 1", + location="location 1", + timestamp="2020-08-10 10:32", + origin_country=206, + package_type=2, + status=30, + ) + ProfileMock.package_list = [package] + await _setup_seventeentrack(hass, summary_data=DEFAULT_SUMMARY) - assert len(hass.states.async_entity_ids()) == 7 + assert len(hass.states.async_entity_ids()) == 8 for state in hass.states.async_all(): + if state.entity_id == "sensor.seventeentrack_package_456": + break assert state.state == "0" + assert ( + len( + hass.states.get( + "sensor.seventeentrack_packages_ready_to_be_picked_up" + ).attributes["packages"] + ) + == 1 + ) + + ProfileMock.package_list = [] ProfileMock.summary_data = NEW_SUMMARY_DATA await _goto_future(hass) @@ -393,6 +418,13 @@ async def test_summary_correctly_updated(hass): for state in hass.states.async_all(): assert state.state == "1" + assert ( + hass.states.get( + "sensor.seventeentrack_packages_ready_to_be_picked_up" + ).attributes["packages"] + is None + ) + async def test_utc_timestamp(hass): """Ensure package timestamp is converted correctly from HA-defined time zone to UTC."""