mirror of
https://github.com/home-assistant/core.git
synced 2025-11-13 13:00:11 +00:00
Add sensor platform to Bring integration (#126642)
* Add sensor platform to Bring integration * Add more tests * unignore typedef check * Update language sensor * update snapshot * changes * add entities Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * add units * lowercase * snapshot --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
40
homeassistant/components/bring/util.py
Normal file
40
homeassistant/components/bring/util.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""Utility functions for Bring."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from bring_api import BringUserSettingsResponse
|
||||
|
||||
from .coordinator import BringData
|
||||
|
||||
|
||||
def list_language(
|
||||
list_uuid: str,
|
||||
user_settings: BringUserSettingsResponse,
|
||||
) -> str | None:
|
||||
"""Get the lists language setting."""
|
||||
try:
|
||||
list_settings = next(
|
||||
filter(
|
||||
lambda x: x["listUuid"] == list_uuid,
|
||||
user_settings["userlistsettings"],
|
||||
)
|
||||
)
|
||||
|
||||
return next(
|
||||
filter(
|
||||
lambda x: x["key"] == "listArticleLanguage",
|
||||
list_settings["usersettings"],
|
||||
)
|
||||
)["value"]
|
||||
|
||||
except (StopIteration, KeyError):
|
||||
return None
|
||||
|
||||
|
||||
def sum_attributes(bring_list: BringData, attribute: str) -> int:
|
||||
"""Count items with given attribute set."""
|
||||
return sum(
|
||||
item["attributes"][0]["content"][attribute]
|
||||
for item in bring_list["purchase"]
|
||||
if len(item.get("attributes", []))
|
||||
)
|
||||
Reference in New Issue
Block a user