Add entity translations to Modem callerID (#98798)

This commit is contained in:
Joost Lekkerkerker 2023-08-22 10:34:39 +02:00 committed by GitHub
parent b885dfa5a8
commit c025244ac1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View File

@ -7,6 +7,7 @@ from homeassistant.components.button import ButtonEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_DEVICE from homeassistant.const import CONF_DEVICE
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DATA_KEY_API, DOMAIN from .const import DATA_KEY_API, DOMAIN
@ -32,13 +33,15 @@ class PhoneModemButton(ButtonEntity):
"""Implementation of USB modem caller ID button.""" """Implementation of USB modem caller ID button."""
_attr_icon = "mdi:phone-hangup" _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: def __init__(self, api: PhoneModem, device: str, server_unique_id: str) -> None:
"""Initialize the button.""" """Initialize the button."""
self.device = device self.device = device
self.api = api self.api = api
self._attr_unique_id = server_unique_id self._attr_unique_id = server_unique_id
self._attr_device_info = DeviceInfo(identifiers={(DOMAIN, server_unique_id)})
async def async_press(self) -> None: async def async_press(self) -> None:
"""Press the button.""" """Press the button."""

View File

@ -7,6 +7,7 @@ from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, STATE_IDLE from homeassistant.const import EVENT_HOMEASSISTANT_STOP, STATE_IDLE
from homeassistant.core import Event, HomeAssistant, callback from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import CID, DATA_KEY_API, DOMAIN, ICON from .const import CID, DATA_KEY_API, DOMAIN, ICON
@ -21,7 +22,6 @@ async def async_setup_entry(
[ [
ModemCalleridSensor( ModemCalleridSensor(
api, api,
entry.title,
entry.entry_id, entry.entry_id,
) )
] ]
@ -42,11 +42,12 @@ class ModemCalleridSensor(SensorEntity):
_attr_icon = ICON _attr_icon = ICON
_attr_should_poll = False _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.""" """Initialize the sensor."""
self.api = api self.api = api
self._attr_name = name
self._attr_unique_id = server_unique_id self._attr_unique_id = server_unique_id
self._attr_native_value = STATE_IDLE self._attr_native_value = STATE_IDLE
self._attr_extra_state_attributes = { self._attr_extra_state_attributes = {
@ -54,6 +55,7 @@ class ModemCalleridSensor(SensorEntity):
CID.CID_NUMBER: "", CID.CID_NUMBER: "",
CID.CID_NAME: "", CID.CID_NAME: "",
} }
self._attr_device_info = DeviceInfo(identifiers={(DOMAIN, server_unique_id)})
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Call when the modem sensor is added to Home Assistant.""" """Call when the modem sensor is added to Home Assistant."""

View File

@ -20,5 +20,12 @@
"already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]", "already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]",
"no_devices_found": "No remaining devices found" "no_devices_found": "No remaining devices found"
} }
},
"entity": {
"button": {
"phone_modem_reject": {
"name": "Phone modem reject"
}
}
} }
} }