tomaae.homeassistant-mikrot.../custom_components/mikrotik_router/button.py

56 lines
1.4 KiB
Python
Raw Normal View History

2022-01-08 21:05:50 +01:00
"""Support for the Mikrotik Router buttons."""
import logging
from homeassistant.components.button import ButtonEntity
from .model import model_async_setup_entry, MikrotikEntity
from .button_types import (
SENSOR_TYPES,
SENSOR_SERVICES,
)
2022-01-08 21:05:50 +01:00
_LOGGER = logging.getLogger(__name__)
# ---------------------------
# async_setup_entry
# ---------------------------
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up entry for component"""
dispatcher = {
"MikrotikButton": MikrotikButton,
"MikrotikScriptButton": MikrotikScriptButton,
}
await model_async_setup_entry(
hass,
config_entry,
async_add_entities,
SENSOR_SERVICES,
SENSOR_TYPES,
dispatcher,
2022-01-08 21:05:50 +01:00
)
# ---------------------------
# MikrotikButton
2022-01-08 21:05:50 +01: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
# ---------------------------
# MikrotikScriptButton
2022-01-08 21:05:50 +01: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."""
self._ctrl.run_script(self._data["name"])
await self._ctrl.force_update()