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