Move rflink service registration to services module (#184460)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
epenet
2026-10-06 15:53:28 +02:00
committed by GitHub
co-authored by Claude Opus 5.5
parent b3405a01ca
commit fb28ba7702
4 changed files with 58 additions and 44 deletions
+4 -43
View File
@@ -9,22 +9,13 @@ from rflink.protocol import create_rflink_connection
from serial import SerialException
from homeassistant.const import (
CONF_COMMAND,
CONF_DEVICE_ID,
CONF_HOST,
CONF_PORT,
EVENT_HOMEASSISTANT_STOP,
EVENT_LOGGING_CHANGED,
Platform,
)
from homeassistant.core import (
CoreState,
Event,
HassJob,
HomeAssistant,
ServiceCall,
callback,
)
from homeassistant.core import CoreState, Event, HassJob, HomeAssistant, callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.dispatcher import (
@@ -44,6 +35,7 @@ from .const import (
EVENT_KEY_ID,
EVENT_KEY_SENSOR,
SIGNAL_AVAILABILITY,
SIGNAL_EVENT,
SIGNAL_HANDLE_EVENT,
TMP_ENTITY,
)
@@ -51,6 +43,7 @@ from .cover import RFLINK_PLATFORM as COVER_PLATFORM
from .entity import RflinkCommand
from .light import RFLINK_PLATFORM as LIGHT_PLATFORM
from .sensor import RFLINK_PLATFORM as SENSOR_PLATFORM
from .services import async_setup_services
from .switch import RFLINK_PLATFORM as SWITCH_PLATFORM
from .utils import identify_event_type
@@ -68,10 +61,6 @@ CONNECTION_TIMEOUT = 10
RFLINK_GROUP_COMMANDS = ["allon", "alloff"]
SERVICE_SEND_COMMAND = "send_command"
SIGNAL_EVENT = "rflink_event"
BINARY_SENSOR_PS = probatio.Schema(
BINARY_SENSOR_PLATFORM,
extra=probatio.ALLOW_EXTRA,
@@ -124,13 +113,6 @@ CONFIG_SCHEMA = probatio.Schema(
extra=probatio.ALLOW_EXTRA,
)
SEND_COMMAND_SCHEMA = probatio.Schema(
{
probatio.Required(CONF_DEVICE_ID): cv.string,
probatio.Required(CONF_COMMAND): cv.string,
}
)
ALLOWED_PLATFORMS = [
Platform.BINARY_SENSOR.value,
Platform.COVER.value,
@@ -153,28 +135,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
# Allow platform to specify function to register new unknown devices
hass.data[DATA_DEVICE_REGISTER] = {}
async def async_send_command(call: ServiceCall) -> None:
"""Send Rflink command."""
_LOGGER.debug("Rflink command for %s", str(call.data))
if not (
await RflinkCommand.send_command(
call.data.get(CONF_DEVICE_ID), call.data.get(CONF_COMMAND)
)
):
_LOGGER.error("Failed Rflink command for %s", str(call.data))
else:
async_dispatcher_send(
hass,
SIGNAL_EVENT,
{
EVENT_KEY_ID: call.data.get(CONF_DEVICE_ID),
EVENT_KEY_COMMAND: call.data.get(CONF_COMMAND),
},
)
hass.services.async_register(
DOMAIN, SERVICE_SEND_COMMAND, async_send_command, schema=SEND_COMMAND_SCHEMA
)
async_setup_services(hass)
@callback
def event_callback(event):
+1
View File
@@ -26,6 +26,7 @@ EVENT_KEY_SENSOR = "sensor"
EVENT_KEY_UNIT = "unit"
SIGNAL_AVAILABILITY = "rflink_device_available"
SIGNAL_EVENT = "rflink_event"
SIGNAL_HANDLE_EVENT = "rflink_handle_event_{}"
TMP_ENTITY = "tmp.{}"
@@ -0,0 +1,52 @@
"""Services for the Rflink integration."""
import logging
import probatio
from homeassistant.const import CONF_COMMAND, CONF_DEVICE_ID
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_send
from .const import DOMAIN, EVENT_KEY_COMMAND, EVENT_KEY_ID, SIGNAL_EVENT
from .entity import RflinkCommand
_LOGGER = logging.getLogger(__name__)
SERVICE_SEND_COMMAND = "send_command"
SEND_COMMAND_SCHEMA = probatio.Schema(
{
probatio.Required(CONF_DEVICE_ID): cv.string,
probatio.Required(CONF_COMMAND): cv.string,
}
)
async def _async_send_command(call: ServiceCall) -> None:
"""Send Rflink command."""
_LOGGER.debug("Rflink command for %s", str(call.data))
if not (
await RflinkCommand.send_command(
call.data.get(CONF_DEVICE_ID), call.data.get(CONF_COMMAND)
)
):
_LOGGER.error("Failed Rflink command for %s", str(call.data))
else:
async_dispatcher_send(
call.hass,
SIGNAL_EVENT,
{
EVENT_KEY_ID: call.data.get(CONF_DEVICE_ID),
EVENT_KEY_COMMAND: call.data.get(CONF_COMMAND),
},
)
@callback
def async_setup_services(hass: HomeAssistant) -> None:
"""Set up the services for the Rflink integration."""
hass.services.async_register(
DOMAIN, SERVICE_SEND_COMMAND, _async_send_command, schema=SEND_COMMAND_SCHEMA
)
+1 -1
View File
@@ -14,10 +14,10 @@ from homeassistant.components.rflink import (
DOMAIN,
EVENT_KEY_COMMAND,
EVENT_KEY_SENSOR,
SERVICE_SEND_COMMAND,
TMP_ENTITY,
RflinkCommand,
)
from homeassistant.components.rflink.services import SERVICE_SEND_COMMAND
from homeassistant.const import (
ATTR_ENTITY_ID,
CONF_HOST,