mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-14 19:34:29 +02:00
converted buttons
This commit is contained in:
parent
15bc156d74
commit
6caaa4e891
4 changed files with 33 additions and 27 deletions
|
@ -1,33 +1,36 @@
|
|||
"""Support for the Mikrotik Router buttons."""
|
||||
from __future__ import annotations
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
import logging
|
||||
from homeassistant.components.button import ButtonEntity
|
||||
from .entity import model_async_setup_entry, MikrotikEntity
|
||||
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
|
||||
from .button_types import (
|
||||
SENSOR_TYPES,
|
||||
SENSOR_SERVICES,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
_LOGGER = getLogger(__name__)
|
||||
|
||||
|
||||
# ---------------------------
|
||||
# async_setup_entry
|
||||
# ---------------------------
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
_async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""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,
|
||||
)
|
||||
await async_add_entities(hass, config_entry, dispatcher)
|
||||
|
||||
|
||||
# ---------------------------
|
||||
|
@ -51,5 +54,4 @@ class MikrotikScriptButton(MikrotikButton):
|
|||
|
||||
async def async_press(self) -> None:
|
||||
"""Process the button press."""
|
||||
self._ctrl.run_script(self._data["name"])
|
||||
await self._ctrl.force_update()
|
||||
self.coordinator.run_script(self._data["name"])
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
"""Definitions for Mikrotik Router button entities."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorEntityDescription,
|
||||
)
|
||||
from .const import DOMAIN
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
DEVICE_ATTRIBUTES_SCRIPT = [
|
||||
"last-started",
|
||||
|
@ -17,21 +20,21 @@ DEVICE_ATTRIBUTES_SCRIPT = [
|
|||
class MikrotikButtonEntityDescription(SensorEntityDescription):
|
||||
"""Class describing mikrotik entities."""
|
||||
|
||||
ha_group: str = ""
|
||||
ha_connection: str = ""
|
||||
ha_connection_value: str = ""
|
||||
data_path: str = ""
|
||||
data_attribute: str = ""
|
||||
data_name: str = ""
|
||||
ha_group: str | None = None
|
||||
ha_connection: str | None = None
|
||||
ha_connection_value: str | None = None
|
||||
data_path: str | None = None
|
||||
data_attribute: str | None = None
|
||||
data_name: str | None = None
|
||||
data_name_comment: bool = False
|
||||
data_uid: str = ""
|
||||
data_reference: str = ""
|
||||
data_uid: str | None = None
|
||||
data_reference: str | None = None
|
||||
data_attributes_list: List = field(default_factory=lambda: [])
|
||||
func: str = "MikrotikButton"
|
||||
|
||||
|
||||
SENSOR_TYPES = {
|
||||
"script": MikrotikButtonEntityDescription(
|
||||
SENSOR_TYPES: tuple[MikrotikButtonEntityDescription, ...] = (
|
||||
MikrotikButtonEntityDescription(
|
||||
key="script",
|
||||
name="",
|
||||
icon="mdi:script-text-outline",
|
||||
|
@ -47,6 +50,6 @@ SENSOR_TYPES = {
|
|||
data_attributes_list=DEVICE_ATTRIBUTES_SCRIPT,
|
||||
func="MikrotikScriptButton",
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
SENSOR_SERVICES = {}
|
||||
|
|
|
@ -6,7 +6,7 @@ PLATFORMS = [
|
|||
Platform.BINARY_SENSOR,
|
||||
# Platform.DEVICE_TRACKER,
|
||||
Platform.SWITCH,
|
||||
# Platform.BUTTON,
|
||||
Platform.BUTTON,
|
||||
Platform.UPDATE,
|
||||
]
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.const import (
|
|||
UnitOfElectricPotential,
|
||||
UnitOfPower,
|
||||
)
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
DEVICE_ATTRIBUTES_IFACE = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue