forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to compare alexa locales with upstream (home-assistant#114247
) * Add script to compare alexa locales with upstream * Use a function in script * Add test base * Complete output assertion * Add type annotation * Add note to docstring * Update script call example Co-authored-by: Jan Bouwhuis <[email protected]> --------- Co-authored-by: Jan Bouwhuis <[email protected]>
- Loading branch information
1 parent
aee620b
commit 47f0d5e
Showing
6 changed files
with
813 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
Oops, something went wrong.