Skip to content

Commit

Permalink
Migrate AVM FRITZ!Box Call monitor to has entity name (#99752)
Browse files Browse the repository at this point in the history
* Migrate AVM FRITZ!Box Call monitor to has entity name

* Update homeassistant/components/fritzbox_callmonitor/strings.json

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update homeassistant/components/fritzbox_callmonitor/strings.json

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update sensor.py

* Update sensor.py

* Update strings.json

* Use translation placeholders

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
  • Loading branch information
jrieger and joostlek committed Jan 4, 2024
1 parent bf229be commit f2514c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
9 changes: 4 additions & 5 deletions homeassistant/components/fritzbox_callmonitor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,16 @@ async def async_setup_entry(
FRITZBOX_PHONEBOOK
]

phonebook_name: str = config_entry.title
phonebook_id: int = config_entry.data[CONF_PHONEBOOK]
prefixes: list[str] | None = config_entry.options.get(CONF_PREFIXES)
serial_number: str = config_entry.data[SERIAL_NUMBER]
host: str = config_entry.data[CONF_HOST]
port: int = config_entry.data[CONF_PORT]

name = f"{fritzbox_phonebook.fph.modelname} Call Monitor {phonebook_name}"
unique_id = f"{serial_number}-{phonebook_id}"

sensor = FritzBoxCallSensor(
name=name,
phonebook_name=config_entry.title,
unique_id=unique_id,
fritzbox_phonebook=fritzbox_phonebook,
prefixes=prefixes,
Expand All @@ -82,13 +80,14 @@ class FritzBoxCallSensor(SensorEntity):
"""Implementation of a Fritz!Box call monitor."""

_attr_icon = ICON_PHONE
_attr_has_entity_name = True
_attr_translation_key = DOMAIN
_attr_device_class = SensorDeviceClass.ENUM
_attr_options = list(CallState)

def __init__(
self,
name: str,
phonebook_name: str,
unique_id: str,
fritzbox_phonebook: FritzBoxPhonebook,
prefixes: list[str] | None,
Expand All @@ -103,7 +102,7 @@ def __init__(
self._monitor: FritzBoxCallMonitor | None = None
self._attributes: dict[str, str | list[str]] = {}

self._attr_name = name.title()
self._attr_translation_placeholders = {"phonebook_name": phonebook_name}
self._attr_unique_id = unique_id
self._attr_native_value = CallState.IDLE
self._attr_device_info = DeviceInfo(
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/fritzbox_callmonitor/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"entity": {
"sensor": {
"fritzbox_callmonitor": {
"name": "Call monitor {phonebook_name}",
"state": {
"ringing": "Ringing",
"dialing": "Dialing",
Expand Down

0 comments on commit f2514c0

Please sign in to comment.