mirror of
https://github.com/home-assistant/core.git
synced 2025-05-23 07:17:07 +00:00
Add Phone Modem call reject button (#66742)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
8befb3b905
commit
eb80abf89e
@ -720,6 +720,7 @@ omit =
|
|||||||
homeassistant/components/mochad/*
|
homeassistant/components/mochad/*
|
||||||
homeassistant/components/modbus/climate.py
|
homeassistant/components/modbus/climate.py
|
||||||
homeassistant/components/modbus/binary_sensor.py
|
homeassistant/components/modbus/binary_sensor.py
|
||||||
|
homeassistant/components/modem_callerid/button.py
|
||||||
homeassistant/components/modem_callerid/sensor.py
|
homeassistant/components/modem_callerid/sensor.py
|
||||||
homeassistant/components/moehlenhoff_alpha2/__init__.py
|
homeassistant/components/moehlenhoff_alpha2/__init__.py
|
||||||
homeassistant/components/moehlenhoff_alpha2/climate.py
|
homeassistant/components/moehlenhoff_alpha2/climate.py
|
||||||
|
@ -8,7 +8,7 @@ from homeassistant.exceptions import ConfigEntryNotReady
|
|||||||
|
|
||||||
from .const import DATA_KEY_API, DOMAIN, EXCEPTIONS
|
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:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
47
homeassistant/components/modem_callerid/button.py
Normal file
47
homeassistant/components/modem_callerid/button.py
Normal file
@ -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)
|
@ -1,6 +1,8 @@
|
|||||||
"""A sensor for incoming calls using a USB modem that supports caller ID."""
|
"""A sensor for incoming calls using a USB modem that supports caller ID."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from phone_modem import PhoneModem
|
from phone_modem import PhoneModem
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
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
|
from .const import CID, DATA_KEY_API, DOMAIN, ICON, SERVICE_REJECT_CALL
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -42,6 +46,11 @@ async def async_setup_entry(
|
|||||||
platform = entity_platform.async_get_current_platform()
|
platform = entity_platform.async_get_current_platform()
|
||||||
|
|
||||||
platform.async_register_entity_service(SERVICE_REJECT_CALL, {}, "async_reject_call")
|
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):
|
class ModemCalleridSensor(SensorEntity):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user