diff --git a/homeassistant/components/keymitt_ble/__init__.py b/homeassistant/components/keymitt_ble/__init__.py index 6ccd9d09a8e7..9a31d6e75e49 100644 --- a/homeassistant/components/keymitt_ble/__init__.py +++ b/homeassistant/components/keymitt_ble/__init__.py @@ -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] diff --git a/homeassistant/components/keymitt_ble/services.py b/homeassistant/components/keymitt_ble/services.py new file mode 100644 index 000000000000..39146fc8251c --- /dev/null +++ b/homeassistant/components/keymitt_ble/services.py @@ -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", + ) diff --git a/homeassistant/components/keymitt_ble/switch.py b/homeassistant/components/keymitt_ble/switch.py index fde512266a7b..5c80c5795faa 100644 --- a/homeassistant/components/keymitt_ble/switch.py +++ b/homeassistant/components/keymitt_ble/switch.py @@ -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):