From c025244ac10639059926e19e93343af5e72bbcaa Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 22 Aug 2023 10:34:39 +0200 Subject: [PATCH] Add entity translations to Modem callerID (#98798) --- homeassistant/components/modem_callerid/button.py | 5 ++++- homeassistant/components/modem_callerid/sensor.py | 8 +++++--- homeassistant/components/modem_callerid/strings.json | 7 +++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/modem_callerid/button.py b/homeassistant/components/modem_callerid/button.py index 4b149deece3..5f9e4cf489c 100644 --- a/homeassistant/components/modem_callerid/button.py +++ b/homeassistant/components/modem_callerid/button.py @@ -7,6 +7,7 @@ from homeassistant.components.button import ButtonEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_DEVICE from homeassistant.core import HomeAssistant +from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DATA_KEY_API, DOMAIN @@ -32,13 +33,15 @@ class PhoneModemButton(ButtonEntity): """Implementation of USB modem caller ID button.""" _attr_icon = "mdi:phone-hangup" - _attr_name = "Phone Modem Reject" + _attr_translation_key = "phone_modem_reject" + _attr_has_entity_name = True def __init__(self, api: PhoneModem, device: str, server_unique_id: str) -> None: """Initialize the button.""" self.device = device self.api = api self._attr_unique_id = server_unique_id + self._attr_device_info = DeviceInfo(identifiers={(DOMAIN, server_unique_id)}) async def async_press(self) -> None: """Press the button.""" diff --git a/homeassistant/components/modem_callerid/sensor.py b/homeassistant/components/modem_callerid/sensor.py index 1cb1043a5e0..c7c4403300a 100644 --- a/homeassistant/components/modem_callerid/sensor.py +++ b/homeassistant/components/modem_callerid/sensor.py @@ -7,6 +7,7 @@ from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import EVENT_HOMEASSISTANT_STOP, STATE_IDLE from homeassistant.core import Event, HomeAssistant, callback +from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import CID, DATA_KEY_API, DOMAIN, ICON @@ -21,7 +22,6 @@ async def async_setup_entry( [ ModemCalleridSensor( api, - entry.title, entry.entry_id, ) ] @@ -42,11 +42,12 @@ class ModemCalleridSensor(SensorEntity): _attr_icon = ICON _attr_should_poll = False + _attr_has_entity_name = True + _attr_name = None - def __init__(self, api: PhoneModem, name: str, server_unique_id: str) -> None: + def __init__(self, api: PhoneModem, server_unique_id: str) -> None: """Initialize the sensor.""" self.api = api - self._attr_name = name self._attr_unique_id = server_unique_id self._attr_native_value = STATE_IDLE self._attr_extra_state_attributes = { @@ -54,6 +55,7 @@ class ModemCalleridSensor(SensorEntity): CID.CID_NUMBER: "", CID.CID_NAME: "", } + self._attr_device_info = DeviceInfo(identifiers={(DOMAIN, server_unique_id)}) async def async_added_to_hass(self) -> None: """Call when the modem sensor is added to Home Assistant.""" diff --git a/homeassistant/components/modem_callerid/strings.json b/homeassistant/components/modem_callerid/strings.json index 2e18ba3654f..dd0af40fac1 100644 --- a/homeassistant/components/modem_callerid/strings.json +++ b/homeassistant/components/modem_callerid/strings.json @@ -20,5 +20,12 @@ "already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]", "no_devices_found": "No remaining devices found" } + }, + "entity": { + "button": { + "phone_modem_reject": { + "name": "Phone modem reject" + } + } } }