1 """Base class for fritzbox_callmonitor entities."""
3 from __future__
import annotations
5 from contextlib
import suppress
6 from datetime
import timedelta
10 from fritzconnection.lib.fritzphonebook
import FritzPhonebook
14 from .const
import REGEX_NUMBER, UNKNOWN_NAME
16 _LOGGER = logging.getLogger(__name__)
23 """Connects to a FritzBox router and downloads its phone book."""
26 phonebook_dict: dict[str, list[str]]
27 number_dict: dict[str, str]
34 phonebook_id: int |
None =
None,
35 prefixes: list[str] |
None =
None,
37 """Initialize the class."""
45 """Establish a connection to the FRITZ!Box and check if phonebook_id is valid."""
46 self.
fphfph = FritzPhonebook(
47 address=self.
hosthost,
53 @Throttle(MIN_TIME_PHONEBOOK_UPDATE)
55 """Update the phone book dictionary."""
61 re.sub(REGEX_NUMBER,
"", nr): name
65 _LOGGER.debug(
"Fritz!Box phone book successfully updated")
68 """Return list of phonebook ids."""
69 return self.
fphfph.phonebook_ids
72 """Return a name for a given phone number."""
73 number = re.sub(REGEX_NUMBER,
"",
str(number))
75 with suppress(KeyError):
82 with suppress(KeyError):
84 with suppress(KeyError):
85 return self.
number_dictnumber_dict[prefix + number.lstrip(
"0")]
None update_phonebook(self)
None init_phonebook(self)
list[int] get_phonebook_ids(self)
None __init__(self, str host, str username, str password, int|None phonebook_id=None, list[str]|None prefixes=None)
str get_name(self, str number)