diff --git a/homeassistant/components/alexa/capabilities.py b/homeassistant/components/alexa/capabilities.py index bc9b482109f..df32220895d 100644 --- a/homeassistant/components/alexa/capabilities.py +++ b/homeassistant/components/alexa/capabilities.py @@ -300,6 +300,10 @@ class Alexa(AlexaCapability): The API suggests you should explicitly include this interface. https://developer.amazon.com/docs/device-apis/alexa-interface.html + + To compare current supported locales in Home Assistant + with Alexa supported locales, run the following script: + python -m script.alexa_locales """ supported_locales = { diff --git a/script/alexa_locales.py b/script/alexa_locales.py new file mode 100644 index 00000000000..84bdac4133a --- /dev/null +++ b/script/alexa_locales.py @@ -0,0 +1,67 @@ +"""Check if upstream Alexa locales are subset of the core Alexa supported locales.""" + +from pprint import pprint +import re + +from bs4 import BeautifulSoup +import requests + +from homeassistant.components.alexa import capabilities + +SITE = ( + "https://developer.amazon.com/en-GB/docs/alexa/device-apis/list-of-interfaces.html" +) + + +def run_script() -> None: + """Run the script.""" + response = requests.get(SITE, timeout=10) + soup = BeautifulSoup(response.text, "html.parser") + + table = soup.find("table") + table_body = table.find_all("tbody")[-1] + rows = table_body.find_all("tr") + data = [[ele.text.strip() for ele in row.find_all("td") if ele] for row in rows] + upstream_locales_raw = {row[0]: row[3] for row in data} + language_pattern = re.compile(r"^[a-z]{2}-[A-Z]{2}$") + upstream_locales = { + upstream_interface: { + name + for word in upstream_locale.split(" ") + if (name := word.strip(",")) and language_pattern.match(name) is not None + } + for upstream_interface, upstream_locale in upstream_locales_raw.items() + if upstream_interface.count(".") == 1 # Skip sub-interfaces + } + + interfaces_missing = {} + interfaces_nok = {} + interfaces_ok = {} + + for upstream_interface, upstream_locale in upstream_locales.items(): + core_interface_name = upstream_interface.replace(".", "") + core_interface = getattr(capabilities, core_interface_name, None) + + if core_interface is None: + interfaces_missing[upstream_interface] = upstream_locale + continue + + core_locale = core_interface.supported_locales + + if not upstream_locale.issubset(core_locale): + interfaces_nok[core_interface_name] = core_locale + else: + interfaces_ok[core_interface_name] = core_locale + + print("Missing interfaces:") + pprint(list(interfaces_missing)) + print("\n") + print("Interfaces where upstream locales are not subsets of the core locales:") + pprint(list(interfaces_nok)) + print("\n") + print("Interfaces checked ok:") + pprint(list(interfaces_ok)) + + +if __name__ == "__main__": + run_script() diff --git a/tests/fixtures/non_packaged_scripts/alexa_locales.txt b/tests/fixtures/non_packaged_scripts/alexa_locales.txt new file mode 100644 index 00000000000..beb9c8dbc7e --- /dev/null +++ b/tests/fixtures/non_packaged_scripts/alexa_locales.txt @@ -0,0 +1,650 @@ +

List of Alexa Interfaces and Supported Languages

+ + +
+ + + + + +

Implement the Alexa interfaces to build automotive skills, music, radio, and podcast skills, smart home skills, and video skills. Alexa interfaces use the pre-built voice interaction model.

+ +

You can use these interfaces with Alexa Voice Service (AVS) Built-in and Alexa Connect Kit (ACK) enabled devices, also. For more details, see Smart Home Development Options.

+ +

Alexa interfaces

+ +

The following table shows the interfaces that you can implement in your Alexa skills. Follow the link to each interface for full details, including the supported capabilities and example customer utterances.

+ + + + +
Interface + Version + Primary skill type + Supported languages + +
+

Alexa.ApplicationStateReporter

+
+

1.0

+
+

AVS

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.Audio.PlayQueue

+
+

1.0

+
+

Music, Radio, Podcast

+
+

en-US, es-US

+ +
+

Alexa.AuthorizationController

+
+

1.0

+
+

Automotive

+
+

en-CA, en-US, es-MX, es-US, fr-CA

+ +
+

Alexa.AutomationManagement

+
+

1.0

+
+

Smart Home Energy

+
+

en-US

+ +
+

Alexa.Automotive.VehicleData

+
+

1.0

+
+

Automotive

+
+

en-CA, en-US, es-MX, es-US, fr-CA

+ +
+

Alexa.BrightnessController

+
+

3

+
+

Smart Home

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX,es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.Camera.LiveViewController

+
+

1.7

+
+

AVS

+
+

en-US

+ +
+

Alexa.CameraStreamController

+
+

3

+
+

Smart Home Security

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.ChannelController

+
+

3

+
+

Smart Home Entertainment,
+Video

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.ColorController

+
+

3

+
+

Smart Home

+
+

de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.ColorTemperatureController

+
+

3

+
+

Smart Home

+
+

de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.Commissionable

+
+

1.0

+
+

Smart Home

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.ConsentManagement.ConsentRequiredReporter

+
+

1.0

+
+

Smart Home

+
+

ja-JP

+ +
+

Alexa.ContactSensor

+
+

3

+
+

Smart Home Security

+
+

de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.Cooking

+
+

3

+
+

Smart Home Cooking

+
+

en-US

+ +
+

Alexa.Cooking.FoodTemperatureController

+
+

3

+
+

Smart Home Cooking

+
+

en-US

+ +
+

Alexa.Cooking.FoodTemperatureSensor

+
+

3

+
+

Smart Home Cooking

+
+

en-US

+ +
+

Alexa.Cooking.PresetController

+
+

3

+
+

Smart Home Cooking

+
+

en-US

+ +
+

Alexa.Cooking.TemperatureController

+
+

3

+
+

Smart Home Cooking

+
+

en-US

+ +
+

Alexa.Cooking.TemperatureSensor

+
+

3

+
+

Smart Home Cooking

+
+

en-US

+ +
+

Alexa.Cooking.TimeController

+
+

3

+
+

Smart Home Cooking

+
+

en-US

+ +
+

Alexa.DataController

+
+

1.0

+
+

Smart Home

+
+

en-US

+ +
+

Alexa.DeviceUsage.Estimation

+
+

1.0

+
+

Smart Home Energy

+
+

en-US

+ +
+

Alexa.DeviceUsage.Meter

+
+

1.0

+
+

Smart Home Energy

+
+

en-US

+ +
+

Alexa.DoorbellEventSource

+
+

3

+
+

Smart Home Security

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.EndpointHealth

+
+

3.1

+
+

Smart Home

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.EqualizerController

+
+

3

+
+

Smart Home Entertainment

+
+

de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.InputController

+
+

3

+
+

Smart Home Entertainment,
+Video, AVS

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.InventoryLevelSensor

+
+

3

+
+

Smart Home

+
+

de-DE, en-CA, en-GB, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, it-IT, ja-JP

+ +
+

Alexa.InventoryLevelUsageSensor

+
+

3

+
+

Smart Home

+
+

de-DE, en-CA, en-GB, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, it-IT, ja-JP

+ +
+

Alexa.InventoryUsageSensor

+
+

3

+
+

Smart Home

+
+

de-DE, en-CA, en-GB, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, it-IT, ja-JP

+ +
+

Alexa.KeypadController

+
+

3

+
+

Video

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.Launcher

+
+

3

+
+

Video

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.LockController

+
+

3

+
+

Smart Home Security

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.Media.Playback

+
+

1.0

+
+

Music, Radio, Podcast

+
+

en-US, es-US

+ +
+

Alexa.Media.PlayQueue

+
+

1.0

+
+

Music, Radio, Podcast

+
+

en-US, es-US

+ +
+

Alexa.Media.Search

+
+

1.0

+
+

Music, Radio, Podcast

+
+

en-US, es-US

+ +
+

Alexa.ModeController

+
+

3

+
+

Smart Home, AVS

+
+

de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.MotionSensor

+
+

3

+
+

Smart Home Security

+
+

de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.PercentageController

+
+

3

+
+

Smart Home

+
+

de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.PlaybackController

+
+

3

+
+

Smart Home Entertainment,
+Video

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.PlaybackStateReporter

+
+

3

+
+

Smart Home Entertainment,
+Video

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.PowerController

+
+

3

+
+

Smart Home,
+Video, AVS

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.PowerLevelController

+
+

3

+
+

Smart Home

+
+

de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, fr-CA, fr-FR, it-IT, ja-JP

+ +
+

Alexa.ProactiveNotificationSource

+
+

3.0

+
+

Smart Home

+
+

Notifications for device state: de-DE, en-CA, en-GB, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, it-IT
+Notifications for cooking: en-US

+ +
+

Alexa.RangeController

+
+

3

+
+

Smart Home, AVS

+
+

de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.RecordController

+
+

3

+
+

Video

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.RemoteVideoPlayer

+
+

3.1

+
+

Video

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.RTCSessionController

+
+

3

+
+

Smart Home Security

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-US, es-ES, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.SceneController

+
+

3

+
+

Smart Home

+
+

de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.SecurityPanelController

+
+

3

+
+

Smart Home Security

+
+

de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, it-IT, ja-JP, pt-BR

+ +
+

Alexa.SecurityPanelController.Alert

+
+

1.1

+
+

Smart Home Security

+
+

de-DE, en-CA, en-GB, en-US, es-US, fr-CA, fr-FR

+ +
+

Alexa.SeekController

+
+

3

+
+

Video

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.SimpleEventSource

+
+

1.0

+
+

Smart Home

+
+

en-US

+ +
+

Alexa.SmartVision.ObjectDetectionSensor

+
+

1.0

+
+

Smart Home Security

+
+

en-US

+ +
+

Alexa.Speaker

+
+

3

+
+

Smart Home Entertainment,
+Video

+
+

de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, it-IT, ja-JP

+ +
+

Alexa.StepSpeaker

+
+

3

+
+

Smart Home Entertainment,
+Video

+
+

de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, it-IT

+ +
+

Alexa.TemperatureSensor

+
+

3

+
+

Smart Home

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.ThermostatController

+
+

3.1

+
+

Smart Home

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.ThermostatController.Configuration

+
+

3

+
+

Smart Home

+
+

en-US

+ +
+

Alexa.ThermostatController.HVAC.Components

+
+

1.0

+
+

Smart Home Energy

+
+

en-US

+ +
+

Alexa.ThermostatController.Schedule

+
+

3.2

+
+

Smart Home

+
+

en-US

+ +
+

Alexa.TimeHoldController

+
+

3

+
+

Smart Home Cooking

+
+

en-US

+ +
+

Alexa.ToggleController

+
+

3

+
+

Smart Home, AVS

+
+

de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.UIController

+
+

3.0

+
+

Video

+
+

en-US

+ +
+

Alexa.UserPreference

+
+

2.0

+
+

Music, Radio, Podcast

+
+

en-US, es-US

+ +
+

Alexa.VideoRecorder

+
+

3

+
+

Video

+
+

ar-SA, de-DE, en-AU, en-CA, en-GB, en-IN, en-US, es-ES, es-MX, es-US, fr-CA, fr-FR, hi-IN, it-IT, ja-JP, pt-BR

+ +
+

Alexa.WakeOnLANController

+
+

3

+
+

Smart Home Entertainment

+
+

de-DE, en-AU, en-IN, en-US, es-ES, it-IT, ja-JP

+ +
+ + + + diff --git a/tests/non_packaged_scripts/__init__.py b/tests/non_packaged_scripts/__init__.py new file mode 100644 index 00000000000..852c52a8293 --- /dev/null +++ b/tests/non_packaged_scripts/__init__.py @@ -0,0 +1 @@ +"""Tests for the non-packaged scripts in the script directory.""" diff --git a/tests/non_packaged_scripts/snapshots/test_alexa_locales.ambr b/tests/non_packaged_scripts/snapshots/test_alexa_locales.ambr new file mode 100644 index 00000000000..bad47eedf53 --- /dev/null +++ b/tests/non_packaged_scripts/snapshots/test_alexa_locales.ambr @@ -0,0 +1,62 @@ +# serializer version: 1 +# name: test_alexa_locales + ''' + Missing interfaces: + ['Alexa.ApplicationStateReporter', + 'Alexa.AuthorizationController', + 'Alexa.AutomationManagement', + 'Alexa.Commissionable', + 'Alexa.Cooking', + 'Alexa.DataController', + 'Alexa.InventoryLevelSensor', + 'Alexa.InventoryLevelUsageSensor', + 'Alexa.InventoryUsageSensor', + 'Alexa.KeypadController', + 'Alexa.Launcher', + 'Alexa.PercentageController', + 'Alexa.ProactiveNotificationSource', + 'Alexa.RecordController', + 'Alexa.RemoteVideoPlayer', + 'Alexa.RTCSessionController', + 'Alexa.SimpleEventSource', + 'Alexa.UIController', + 'Alexa.UserPreference', + 'Alexa.VideoRecorder', + 'Alexa.WakeOnLANController'] + + + Interfaces where upstream locales are not subsets of the core locales: + [] + + + Interfaces checked ok: + ['AlexaBrightnessController', + 'AlexaCameraStreamController', + 'AlexaChannelController', + 'AlexaColorController', + 'AlexaColorTemperatureController', + 'AlexaContactSensor', + 'AlexaDoorbellEventSource', + 'AlexaEndpointHealth', + 'AlexaEqualizerController', + 'AlexaInputController', + 'AlexaLockController', + 'AlexaModeController', + 'AlexaMotionSensor', + 'AlexaPlaybackController', + 'AlexaPlaybackStateReporter', + 'AlexaPowerController', + 'AlexaPowerLevelController', + 'AlexaRangeController', + 'AlexaSceneController', + 'AlexaSecurityPanelController', + 'AlexaSeekController', + 'AlexaSpeaker', + 'AlexaStepSpeaker', + 'AlexaTemperatureSensor', + 'AlexaThermostatController', + 'AlexaTimeHoldController', + 'AlexaToggleController'] + + ''' +# --- diff --git a/tests/non_packaged_scripts/test_alexa_locales.py b/tests/non_packaged_scripts/test_alexa_locales.py new file mode 100644 index 00000000000..ea139f7de8e --- /dev/null +++ b/tests/non_packaged_scripts/test_alexa_locales.py @@ -0,0 +1,29 @@ +"""Test the alexa_locales script.""" + +from pathlib import Path + +import pytest +import requests_mock +from syrupy import SnapshotAssertion + +from script.alexa_locales import SITE, run_script + + +def test_alexa_locales( + capsys: pytest.CaptureFixture[str], + requests_mock: requests_mock.Mocker, + snapshot: SnapshotAssertion, +) -> None: + """Test alexa_locales script.""" + fixture_file = ( + Path(__file__).parent.parent / "fixtures/non_packaged_scripts/alexa_locales.txt" + ) + requests_mock.get( + SITE, + text=fixture_file.read_text(encoding="utf-8"), + ) + + run_script() + + captured = capsys.readouterr() + assert captured.out == snapshot