Add platforms to intent handlers (#118328)

pull/118144/head^2
Michael Hansen 2024-05-28 15:46:08 -05:00 committed by GitHub
parent 5eb1d72691
commit 2dc49f0410
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 36 additions and 4 deletions

View File

@ -24,6 +24,7 @@ class GetTemperatureIntent(intent.IntentHandler):
intent_type = INTENT_GET_TEMPERATURE intent_type = INTENT_GET_TEMPERATURE
description = "Gets the current temperature of a climate device or entity" description = "Gets the current temperature of a climate device or entity"
slot_schema = {vol.Optional("area"): str, vol.Optional("name"): str} slot_schema = {vol.Optional("area"): str, vol.Optional("name"): str}
platforms = {DOMAIN}
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse: async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
"""Handle the intent.""" """Handle the intent."""

View File

@ -15,12 +15,20 @@ async def async_setup_intents(hass: HomeAssistant) -> None:
intent.async_register( intent.async_register(
hass, hass,
intent.ServiceIntentHandler( intent.ServiceIntentHandler(
INTENT_OPEN_COVER, DOMAIN, SERVICE_OPEN_COVER, "Opened {}" INTENT_OPEN_COVER,
DOMAIN,
SERVICE_OPEN_COVER,
"Opened {}",
platforms={DOMAIN},
), ),
) )
intent.async_register( intent.async_register(
hass, hass,
intent.ServiceIntentHandler( intent.ServiceIntentHandler(
INTENT_CLOSE_COVER, DOMAIN, SERVICE_CLOSE_COVER, "Closed {}" INTENT_CLOSE_COVER,
DOMAIN,
SERVICE_CLOSE_COVER,
"Closed {}",
platforms={DOMAIN},
), ),
) )

View File

@ -38,6 +38,7 @@ class HumidityHandler(intent.IntentHandler):
vol.Required("name"): cv.string, vol.Required("name"): cv.string,
vol.Required("humidity"): vol.All(vol.Coerce(int), vol.Range(0, 100)), vol.Required("humidity"): vol.All(vol.Coerce(int), vol.Range(0, 100)),
} }
platforms = {DOMAIN}
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse: async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
"""Handle the hass intent.""" """Handle the hass intent."""
@ -91,6 +92,7 @@ class SetModeHandler(intent.IntentHandler):
vol.Required("name"): cv.string, vol.Required("name"): cv.string,
vol.Required("mode"): cv.string, vol.Required("mode"): cv.string,
} }
platforms = {DOMAIN}
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse: async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
"""Handle the hass intent.""" """Handle the hass intent."""

View File

@ -352,6 +352,7 @@ class SetPositionIntentHandler(intent.DynamicServiceIntentHandler):
ATTR_POSITION: vol.All(vol.Coerce(int), vol.Range(min=0, max=100)) ATTR_POSITION: vol.All(vol.Coerce(int), vol.Range(min=0, max=100))
}, },
description="Sets the position of a device or entity", description="Sets the position of a device or entity",
platforms={COVER_DOMAIN, VALVE_DOMAIN},
) )
def get_domain_and_service( def get_domain_and_service(

View File

@ -34,5 +34,6 @@ async def async_setup_intents(hass: HomeAssistant) -> None:
), ),
}, },
description="Sets the brightness or color of a light", description="Sets the brightness or color of a light",
platforms={DOMAIN},
), ),
) )

View File

@ -66,6 +66,7 @@ async def async_setup_intents(hass: HomeAssistant) -> None:
required_features=MediaPlayerEntityFeature.NEXT_TRACK, required_features=MediaPlayerEntityFeature.NEXT_TRACK,
required_states={MediaPlayerState.PLAYING}, required_states={MediaPlayerState.PLAYING},
description="Skips a media player to the next item", description="Skips a media player to the next item",
platforms={DOMAIN},
), ),
) )
intent.async_register( intent.async_register(
@ -83,6 +84,7 @@ async def async_setup_intents(hass: HomeAssistant) -> None:
) )
}, },
description="Sets the volume of a media player", description="Sets the volume of a media player",
platforms={DOMAIN},
), ),
) )
@ -90,6 +92,8 @@ async def async_setup_intents(hass: HomeAssistant) -> None:
class MediaPauseHandler(intent.ServiceIntentHandler): class MediaPauseHandler(intent.ServiceIntentHandler):
"""Handler for pause intent. Records last paused media players.""" """Handler for pause intent. Records last paused media players."""
platforms = {DOMAIN}
def __init__(self, last_paused: LastPaused) -> None: def __init__(self, last_paused: LastPaused) -> None:
"""Initialize handler.""" """Initialize handler."""
super().__init__( super().__init__(
@ -125,6 +129,8 @@ class MediaPauseHandler(intent.ServiceIntentHandler):
class MediaUnpauseHandler(intent.ServiceIntentHandler): class MediaUnpauseHandler(intent.ServiceIntentHandler):
"""Handler for unpause/resume intent. Uses last paused media players.""" """Handler for unpause/resume intent. Uses last paused media players."""
platforms = {DOMAIN}
def __init__(self, last_paused: LastPaused) -> None: def __init__(self, last_paused: LastPaused) -> None:
"""Initialize handler.""" """Initialize handler."""
super().__init__( super().__init__(

View File

@ -24,6 +24,7 @@ class AddItemIntent(intent.IntentHandler):
intent_type = INTENT_ADD_ITEM intent_type = INTENT_ADD_ITEM
description = "Adds an item to the shopping list" description = "Adds an item to the shopping list"
slot_schema = {"item": cv.string} slot_schema = {"item": cv.string}
platforms = {DOMAIN}
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse: async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
"""Handle the intent.""" """Handle the intent."""
@ -42,6 +43,7 @@ class ListTopItemsIntent(intent.IntentHandler):
intent_type = INTENT_LAST_ITEMS intent_type = INTENT_LAST_ITEMS
description = "List the top five items on the shopping list" description = "List the top five items on the shopping list"
slot_schema = {"item": cv.string} slot_schema = {"item": cv.string}
platforms = {DOMAIN}
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse: async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
"""Handle the intent.""" """Handle the intent."""

View File

@ -23,6 +23,7 @@ class ListAddItemIntent(intent.IntentHandler):
intent_type = INTENT_LIST_ADD_ITEM intent_type = INTENT_LIST_ADD_ITEM
description = "Add item to a todo list" description = "Add item to a todo list"
slot_schema = {"item": cv.string, "name": cv.string} slot_schema = {"item": cv.string, "name": cv.string}
platforms = {DOMAIN}
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse: async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
"""Handle the intent.""" """Handle the intent."""

View File

@ -14,7 +14,11 @@ async def async_setup_intents(hass: HomeAssistant) -> None:
intent.async_register( intent.async_register(
hass, hass,
intent.ServiceIntentHandler( intent.ServiceIntentHandler(
INTENT_VACUUM_START, DOMAIN, SERVICE_START, description="Starts a vacuum" INTENT_VACUUM_START,
DOMAIN,
SERVICE_START,
description="Starts a vacuum",
platforms={DOMAIN},
), ),
) )
intent.async_register( intent.async_register(
@ -24,5 +28,6 @@ async def async_setup_intents(hass: HomeAssistant) -> None:
DOMAIN, DOMAIN,
SERVICE_RETURN_TO_BASE, SERVICE_RETURN_TO_BASE,
description="Returns a vacuum to base", description="Returns a vacuum to base",
platforms={DOMAIN},
), ),
) )

View File

@ -25,6 +25,7 @@ class GetWeatherIntent(intent.IntentHandler):
intent_type = INTENT_GET_WEATHER intent_type = INTENT_GET_WEATHER
description = "Gets the current weather" description = "Gets the current weather"
slot_schema = {vol.Optional("name"): cv.string} slot_schema = {vol.Optional("name"): cv.string}
platforms = {DOMAIN}
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse: async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
"""Handle the intent.""" """Handle the intent."""

View File

@ -737,7 +737,7 @@ class IntentHandler:
"""Intent handler registration.""" """Intent handler registration."""
intent_type: str intent_type: str
platforms: Iterable[str] | None = [] platforms: set[str] | None = None
description: str | None = None description: str | None = None
@property @property
@ -808,6 +808,7 @@ class DynamicServiceIntentHandler(IntentHandler):
required_features: int | None = None, required_features: int | None = None,
required_states: set[str] | None = None, required_states: set[str] | None = None,
description: str | None = None, description: str | None = None,
platforms: set[str] | None = None,
) -> None: ) -> None:
"""Create Service Intent Handler.""" """Create Service Intent Handler."""
self.intent_type = intent_type self.intent_type = intent_type
@ -816,6 +817,7 @@ class DynamicServiceIntentHandler(IntentHandler):
self.required_features = required_features self.required_features = required_features
self.required_states = required_states self.required_states = required_states
self.description = description self.description = description
self.platforms = platforms
self.required_slots: dict[tuple[str, str], vol.Schema] = {} self.required_slots: dict[tuple[str, str], vol.Schema] = {}
if required_slots: if required_slots:
@ -1106,6 +1108,7 @@ class ServiceIntentHandler(DynamicServiceIntentHandler):
required_features: int | None = None, required_features: int | None = None,
required_states: set[str] | None = None, required_states: set[str] | None = None,
description: str | None = None, description: str | None = None,
platforms: set[str] | None = None,
) -> None: ) -> None:
"""Create service handler.""" """Create service handler."""
super().__init__( super().__init__(
@ -1117,6 +1120,7 @@ class ServiceIntentHandler(DynamicServiceIntentHandler):
required_features=required_features, required_features=required_features,
required_states=required_states, required_states=required_states,
description=description, description=description,
platforms=platforms,
) )
self.domain = domain self.domain = domain
self.service = service self.service = service