Add state invitation to list access sensor in Bring integration (#129960)

This commit is contained in:
Manu 2024-11-06 19:15:25 +01:00 committed by GitHub
parent d4adb1f298
commit b808c0c5eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 131 additions and 5 deletions

View File

@ -16,7 +16,8 @@
"list_access": { "list_access": {
"default": "mdi:account-lock", "default": "mdi:account-lock",
"state": { "state": {
"shared": "mdi:account-group" "shared": "mdi:account-group",
"invitation": "mdi:account-multiple-plus"
} }
} }
}, },

View File

@ -79,7 +79,7 @@ SENSOR_DESCRIPTIONS: tuple[BringSensorEntityDescription, ...] = (
translation_key=BringSensor.LIST_ACCESS, translation_key=BringSensor.LIST_ACCESS,
value_fn=lambda lst, _: lst["status"].lower(), value_fn=lambda lst, _: lst["status"].lower(),
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
options=["registered", "shared"], options=["registered", "shared", "invitation"],
device_class=SensorDeviceClass.ENUM, device_class=SensorDeviceClass.ENUM,
), ),
) )

View File

@ -66,7 +66,8 @@
"name": "List access", "name": "List access",
"state": { "state": {
"registered": "Private", "registered": "Private",
"shared": "Shared" "shared": "Shared",
"invitation": "Invitation pending"
} }
} }
} }

View File

@ -0,0 +1,44 @@
{
"uuid": "77a151f8-77c4-47a3-8295-c750a0e69d4f",
"status": "INVITATION",
"purchase": [
{
"uuid": "b5d0790b-5f32-4d5c-91da-e29066f167de",
"itemId": "Paprika",
"specification": "Rot",
"attributes": [
{
"type": "PURCHASE_CONDITIONS",
"content": {
"urgent": true,
"convenient": true,
"discounted": true
}
}
]
},
{
"uuid": "72d370ab-d8ca-4e41-b956-91df94795b4e",
"itemId": "Pouletbrüstli",
"specification": "Bio",
"attributes": [
{
"type": "PURCHASE_CONDITIONS",
"content": {
"urgent": true,
"convenient": true,
"discounted": true
}
}
]
}
],
"recently": [
{
"uuid": "fc8db30a-647e-4e6c-9d71-3b85d6a2d954",
"itemId": "Ananas",
"specification": "",
"attributes": []
}
]
}

View File

@ -0,0 +1,44 @@
{
"uuid": "77a151f8-77c4-47a3-8295-c750a0e69d4f",
"status": "SHARED",
"purchase": [
{
"uuid": "b5d0790b-5f32-4d5c-91da-e29066f167de",
"itemId": "Paprika",
"specification": "Rot",
"attributes": [
{
"type": "PURCHASE_CONDITIONS",
"content": {
"urgent": true,
"convenient": true,
"discounted": true
}
}
]
},
{
"uuid": "72d370ab-d8ca-4e41-b956-91df94795b4e",
"itemId": "Pouletbrüstli",
"specification": "Bio",
"attributes": [
{
"type": "PURCHASE_CONDITIONS",
"content": {
"urgent": true,
"convenient": true,
"discounted": true
}
}
]
}
],
"recently": [
{
"uuid": "fc8db30a-647e-4e6c-9d71-3b85d6a2d954",
"itemId": "Ananas",
"specification": "",
"attributes": []
}
]
}

View File

@ -55,6 +55,7 @@
'options': list([ 'options': list([
'registered', 'registered',
'shared', 'shared',
'invitation',
]), ]),
}), }),
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
@ -92,6 +93,7 @@
'options': list([ 'options': list([
'registered', 'registered',
'shared', 'shared',
'invitation',
]), ]),
}), }),
'context': <ANY>, 'context': <ANY>,
@ -344,6 +346,7 @@
'options': list([ 'options': list([
'registered', 'registered',
'shared', 'shared',
'invitation',
]), ]),
}), }),
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
@ -381,6 +384,7 @@
'options': list([ 'options': list([
'registered', 'registered',
'shared', 'shared',
'invitation',
]), ]),
}), }),
'context': <ANY>, 'context': <ANY>,

View File

@ -1,17 +1,18 @@
"""Test for sensor platform of the Bring! integration.""" """Test for sensor platform of the Bring! integration."""
from collections.abc import Generator from collections.abc import Generator
from unittest.mock import patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from syrupy.assertion import SnapshotAssertion from syrupy.assertion import SnapshotAssertion
from homeassistant.components.bring.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import Platform from homeassistant.const import Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry, snapshot_platform from tests.common import MockConfigEntry, load_json_object_fixture, snapshot_platform
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
@ -42,3 +43,34 @@ async def test_setup(
await snapshot_platform( await snapshot_platform(
hass, entity_registry, snapshot, bring_config_entry.entry_id hass, entity_registry, snapshot, bring_config_entry.entry_id
) )
@pytest.mark.parametrize(
("fixture", "entity_state"),
[
("items_invitation", "invitation"),
("items_shared", "shared"),
("items", "registered"),
],
)
async def test_list_access_states(
hass: HomeAssistant,
bring_config_entry: MockConfigEntry,
mock_bring_client: AsyncMock,
fixture: str,
entity_state: str,
) -> None:
"""Snapshot test states of list access sensor."""
mock_bring_client.get_list.return_value = load_json_object_fixture(
f"{fixture}.json", DOMAIN
)
bring_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(bring_config_entry.entry_id)
await hass.async_block_till_done()
assert bring_config_entry.state is ConfigEntryState.LOADED
assert (state := hass.states.get("sensor.einkauf_list_access"))
assert state.state == entity_state