Use configured contacts address book
All checks were successful
Build And Test / publish (push) Successful in 47s

This commit is contained in:
2026-01-01 15:55:00 -08:00
parent 5a9ef0e48f
commit bd8e1412e4
6 changed files with 39 additions and 33 deletions

View File

@@ -351,7 +351,6 @@ class ContactsService:
def delete_contact(self, contact_id: str, addressbook_id: Optional[str] = None) -> OperationResult:
try:
client = self._get_client()
addressbook_id = self._resolve_addressbook_id(addressbook_id)
# Build URL
contact_url = self._build_url(contact_id)
@@ -375,7 +374,7 @@ class ContactsService:
return OperationResult(success=False, message=str(e))
def _parse_vcard(
self, vcard_data: str, addressbook_id: str, href: str
self, vcard_data: str, addressbook_id: Optional[str], href: str
) -> Optional[Contact]:
try:
vcard = vobject.readOne(vcard_data)
@@ -471,9 +470,10 @@ class ContactsService:
except Exception:
pass
resolved_addressbook_id = addressbook_id or self._derive_addressbook_id(href)
return Contact(
id=href,
addressbook_id=addressbook_id,
addressbook_id=resolved_addressbook_id,
first_name=first_name,
last_name=last_name,
display_name=display_name,
@@ -486,9 +486,15 @@ class ContactsService:
birthday=birthday,
)
def _derive_addressbook_id(self, contact_href: str) -> str:
if "/" not in contact_href:
return contact_href
base = contact_href.rsplit("/", 1)[0]
return f"{base}/"
def _resolve_addressbook_id(self, addressbook_id: Optional[str]) -> str:
if addressbook_id:
return addressbook_id
if self.settings.contacts_addressbook_id:
return self.settings.contacts_addressbook_id
raise ValueError("CONTACTS_ADDRESSBOOK_ID must be set to use contacts tools")
if self.settings.contacts_addressbook_url:
return self.settings.contacts_addressbook_url
raise ValueError("CONTACTS_ADDRESSBOOK_URL must be set to use contacts tools")