mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 12:21:04 -04:00
Move keymitt_ble service registration to services module (#184477)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
77bb4d8402
commit
4988d933ab
@@ -6,12 +6,25 @@ from homeassistant.components import bluetooth
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_ADDRESS, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import MicroBotConfigEntry, MicroBotDataUpdateCoordinator
|
||||
from .services import async_setup_services
|
||||
|
||||
PLATFORMS: list[str] = [Platform.SWITCH]
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Keymitt MicroBot Push integration."""
|
||||
async_setup_services(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: MicroBotConfigEntry) -> bool:
|
||||
"""Set up this integration using UI."""
|
||||
token: str = entry.data[CONF_ACCESS_TOKEN]
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
"""Services for the Keymitt MicroBot Push integration."""
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, service
|
||||
from homeassistant.helpers.typing import VolDictType
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
CALIBRATE = "calibrate"
|
||||
CALIBRATE_SCHEMA: VolDictType = {
|
||||
probatio.Required("depth"): cv.positive_int,
|
||||
probatio.Required("duration"): cv.positive_int,
|
||||
probatio.Required("mode"): probatio.In(["normal", "invert", "toggle"]),
|
||||
}
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up the services for the Keymitt MicroBot Push integration."""
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
CALIBRATE,
|
||||
entity_domain=SWITCH_DOMAIN,
|
||||
schema=CALIBRATE_SCHEMA,
|
||||
func="async_calibrate",
|
||||
)
|
||||
@@ -2,27 +2,13 @@
|
||||
|
||||
from typing import Any, override
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
AddConfigEntryEntitiesCallback,
|
||||
async_get_current_platform,
|
||||
)
|
||||
from homeassistant.helpers.typing import VolDictType
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .coordinator import MicroBotConfigEntry
|
||||
from .entity import MicroBotEntity
|
||||
|
||||
CALIBRATE = "calibrate"
|
||||
CALIBRATE_SCHEMA: VolDictType = {
|
||||
probatio.Required("depth"): cv.positive_int,
|
||||
probatio.Required("duration"): cv.positive_int,
|
||||
probatio.Required("mode"): probatio.In(["normal", "invert", "toggle"]),
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
@@ -31,12 +17,6 @@ async def async_setup_entry(
|
||||
) -> None:
|
||||
"""Set up MicroBot based on a config entry."""
|
||||
async_add_entities([MicroBotBinarySwitch(entry.runtime_data)])
|
||||
platform = async_get_current_platform()
|
||||
platform.async_register_entity_service(
|
||||
CALIBRATE,
|
||||
CALIBRATE_SCHEMA,
|
||||
"async_calibrate",
|
||||
)
|
||||
|
||||
|
||||
class MicroBotBinarySwitch(MicroBotEntity, SwitchEntity):
|
||||
|
||||
Reference in New Issue
Block a user