diff --git a/.coveragerc b/.coveragerc index 0d79bb02a4a..9a3a52895c3 100644 --- a/.coveragerc +++ b/.coveragerc @@ -720,6 +720,7 @@ omit = homeassistant/components/mochad/* homeassistant/components/modbus/climate.py homeassistant/components/modbus/binary_sensor.py + homeassistant/components/modem_callerid/button.py homeassistant/components/modem_callerid/sensor.py homeassistant/components/moehlenhoff_alpha2/__init__.py homeassistant/components/moehlenhoff_alpha2/climate.py diff --git a/homeassistant/components/modem_callerid/__init__.py b/homeassistant/components/modem_callerid/__init__.py index d66be29f8b7..8f62cf4beb5 100644 --- a/homeassistant/components/modem_callerid/__init__.py +++ b/homeassistant/components/modem_callerid/__init__.py @@ -8,7 +8,7 @@ from homeassistant.exceptions import ConfigEntryNotReady from .const import DATA_KEY_API, DOMAIN, EXCEPTIONS -PLATFORMS = [Platform.SENSOR] +PLATFORMS = [Platform.BUTTON, Platform.SENSOR] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: diff --git a/homeassistant/components/modem_callerid/button.py b/homeassistant/components/modem_callerid/button.py new file mode 100644 index 00000000000..63a88a8a4e5 --- /dev/null +++ b/homeassistant/components/modem_callerid/button.py @@ -0,0 +1,47 @@ +"""Support for Phone Modem button.""" +from __future__ import annotations + +from phone_modem import PhoneModem + +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 import entity_platform + +from .const import DATA_KEY_API, DOMAIN + + +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: entity_platform.AddEntitiesCallback, +) -> None: + """Set up the Modem Caller ID sensor.""" + api = hass.data[DOMAIN][entry.entry_id][DATA_KEY_API] + async_add_entities( + [ + PhoneModemButton( + api, + entry.data[CONF_DEVICE], + entry.entry_id, + ) + ] + ) + + +class PhoneModemButton(ButtonEntity): + """Implementation of USB modem caller ID button.""" + + _attr_icon = "mdi:phone-hangup" + _attr_name = "Phone Modem Reject" + + 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 + + async def async_press(self) -> None: + """Press the button.""" + await self.api.reject_call(self.device) diff --git a/homeassistant/components/modem_callerid/sensor.py b/homeassistant/components/modem_callerid/sensor.py index 94c7c51ee80..3a1af4aa0a8 100644 --- a/homeassistant/components/modem_callerid/sensor.py +++ b/homeassistant/components/modem_callerid/sensor.py @@ -1,6 +1,8 @@ """A sensor for incoming calls using a USB modem that supports caller ID.""" from __future__ import annotations +import logging + from phone_modem import PhoneModem from homeassistant.components.sensor import SensorEntity @@ -11,6 +13,8 @@ from homeassistant.helpers import entity_platform from .const import CID, DATA_KEY_API, DOMAIN, ICON, SERVICE_REJECT_CALL +_LOGGER = logging.getLogger(__name__) + async def async_setup_entry( hass: HomeAssistant, @@ -42,6 +46,11 @@ async def async_setup_entry( platform = entity_platform.async_get_current_platform() platform.async_register_entity_service(SERVICE_REJECT_CALL, {}, "async_reject_call") + _LOGGER.warning( + "Calling reject_call service is deprecated and will be removed after 2022.4; " + "A new button entity is now available with the same function " + "and replaces the existing service" + ) class ModemCalleridSensor(SensorEntity):