Skip to content

Commit

Permalink
Add state invitation to list access sensor in Bring integration (home…
Browse files Browse the repository at this point in the history
  • Loading branch information
tr4nt0r authored and frenck committed Nov 6, 2024
1 parent 7824175 commit e84d5fb
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 5 deletions.
3 changes: 2 additions & 1 deletion homeassistant/components/bring/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"list_access": {
"default": "mdi:account-lock",
"state": {
"shared": "mdi:account-group"
"shared": "mdi:account-group",
"invitation": "mdi:account-multiple-plus"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/bring/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BringSensor(StrEnum):
translation_key=BringSensor.LIST_ACCESS,
value_fn=lambda lst, _: lst["status"].lower(),
entity_category=EntityCategory.DIAGNOSTIC,
options=["registered", "shared"],
options=["registered", "shared", "invitation"],
device_class=SensorDeviceClass.ENUM,
),
)
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/bring/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"name": "List access",
"state": {
"registered": "Private",
"shared": "Shared"
"shared": "Shared",
"invitation": "Invitation pending"
}
}
}
Expand Down
44 changes: 44 additions & 0 deletions tests/components/bring/fixtures/items_invitation.json
Original file line number Diff line number Diff line change
@@ -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": []
}
]
}
44 changes: 44 additions & 0 deletions tests/components/bring/fixtures/items_shared.json
Original file line number Diff line number Diff line change
@@ -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": []
}
]
}
4 changes: 4 additions & 0 deletions tests/components/bring/snapshots/test_sensor.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
'options': list([
'registered',
'shared',
'invitation',
]),
}),
'config_entry_id': <ANY>,
Expand Down Expand Up @@ -92,6 +93,7 @@
'options': list([
'registered',
'shared',
'invitation',
]),
}),
'context': <ANY>,
Expand Down Expand Up @@ -344,6 +346,7 @@
'options': list([
'registered',
'shared',
'invitation',
]),
}),
'config_entry_id': <ANY>,
Expand Down Expand Up @@ -381,6 +384,7 @@
'options': list([
'registered',
'shared',
'invitation',
]),
}),
'context': <ANY>,
Expand Down
36 changes: 34 additions & 2 deletions tests/components/bring/test_sensor.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
"""Test for sensor platform of the Bring! integration."""

from collections.abc import Generator
from unittest.mock import patch
from unittest.mock import AsyncMock, patch

import pytest
from syrupy.assertion import SnapshotAssertion

from homeassistant.components.bring.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
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)
Expand Down Expand Up @@ -42,3 +43,34 @@ async def test_setup(
await snapshot_platform(
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

0 comments on commit e84d5fb

Please sign in to comment.