2022-01-08 21:05:50 +01:00
|
|
|
"""Support for the Mikrotik Router buttons."""
|
2023-08-09 09:59:50 +02:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from logging import getLogger
|
2022-01-08 21:05:50 +01:00
|
|
|
|
|
|
|
from homeassistant.components.button import ButtonEntity
|
2023-08-09 09:59:50 +02:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
|
|
|
|
from .entity import MikrotikEntity, async_add_entities
|
2022-03-27 03:29:36 +02:00
|
|
|
from .button_types import (
|
|
|
|
SENSOR_TYPES,
|
|
|
|
SENSOR_SERVICES,
|
|
|
|
)
|
2022-01-08 21:05:50 +01:00
|
|
|
|
2023-08-09 09:59:50 +02:00
|
|
|
_LOGGER = getLogger(__name__)
|
2022-01-08 21:05:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------
|
|
|
|
# async_setup_entry
|
|
|
|
# ---------------------------
|
2023-08-09 09:59:50 +02:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
_async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2022-03-27 03:29:36 +02:00
|
|
|
"""Set up entry for component"""
|
|
|
|
dispatcher = {
|
|
|
|
"MikrotikButton": MikrotikButton,
|
|
|
|
"MikrotikScriptButton": MikrotikScriptButton,
|
|
|
|
}
|
2023-08-09 09:59:50 +02:00
|
|
|
await async_add_entities(hass, config_entry, dispatcher)
|
2022-01-08 21:05:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------
|
2022-03-27 03:29:36 +02:00
|
|
|
# MikrotikButton
|
2022-01-08 21:05:50 +01:00
|
|
|
# ---------------------------
|
2022-03-27 03:29:36 +02:00
|
|
|
class MikrotikButton(MikrotikEntity, ButtonEntity):
|
2022-01-08 21:05:50 +01:00
|
|
|
"""Representation of a button."""
|
|
|
|
|
|
|
|
async def async_update(self):
|
|
|
|
"""Synchronize state with controller."""
|
|
|
|
|
|
|
|
async def async_press(self) -> None:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------
|
2022-03-27 03:29:36 +02:00
|
|
|
# MikrotikScriptButton
|
2022-01-08 21:05:50 +01:00
|
|
|
# ---------------------------
|
2022-03-27 03:29:36 +02:00
|
|
|
class MikrotikScriptButton(MikrotikButton):
|
2022-01-08 21:05:50 +01:00
|
|
|
"""Representation of a script button."""
|
|
|
|
|
|
|
|
async def async_press(self) -> None:
|
|
|
|
"""Process the button press."""
|
2023-08-09 09:59:50 +02:00
|
|
|
self.coordinator.run_script(self._data["name"])
|