Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate AVM FRITZ!Box Call monitor to has entity name #99752

Merged
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}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change would mean that none of the entities will have a phonebook name. Can one phone (which is what fritzbox_phonebook.fph.modelname is, I think) have more phonebooks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can, you have to add another device and chose another phonebook there:
image

I did not find any information how to append the phonebook name to the entity name, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we can't and there are some discussion on adding more variables to entity names. But I think with this change, you would get sensor.something_call_monitor and sensor.something_call_monitor_2 unless you rename the device.

Maybe @cdce8p has an idea for now without placeholders that would make this correct. Otherwise you might need to wait with this PR :(

Copy link
Contributor Author

@jrieger jrieger Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, second one is sensor.fritz_box_7590_call_monitor_2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use new translation placeholders.

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
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