Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4b6dd0e

Browse files
Add optional language to Mastodon post action (home-assistant#151072)
1 parent b7db87b commit 4b6dd0e

File tree

5 files changed

+231
-0
lines changed

5 files changed

+231
-0
lines changed

‎homeassistant/components/mastodon/const.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
ATTR_MEDIA_WARNING = "media_warning"
1919
ATTR_MEDIA = "media"
2020
ATTR_MEDIA_DESCRIPTION = "media_description"
21+
ATTR_LANGUAGE = "language"

‎homeassistant/components/mastodon/services.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from .const import (
1717
ATTR_CONTENT_WARNING,
18+
ATTR_LANGUAGE,
1819
ATTR_MEDIA,
1920
ATTR_MEDIA_DESCRIPTION,
2021
ATTR_MEDIA_WARNING,
@@ -42,6 +43,7 @@ class StatusVisibility(StrEnum):
4243
vol.Required(ATTR_STATUS): str,
4344
vol.Optional(ATTR_VISIBILITY): vol.In([x.lower() for x in StatusVisibility]),
4445
vol.Optional(ATTR_CONTENT_WARNING): str,
46+
vol.Optional(ATTR_LANGUAGE): str,
4547
vol.Optional(ATTR_MEDIA): str,
4648
vol.Optional(ATTR_MEDIA_DESCRIPTION): str,
4749
vol.Optional(ATTR_MEDIA_WARNING): bool,
@@ -82,6 +84,7 @@ async def async_post(call: ServiceCall) -> ServiceResponse:
8284
else None
8385
)
8486
spoiler_text: str | None = call.data.get(ATTR_CONTENT_WARNING)
87+
language: str | None = call.data.get(ATTR_LANGUAGE)
8588
media_path: str | None = call.data.get(ATTR_MEDIA)
8689
media_description: str | None = call.data.get(ATTR_MEDIA_DESCRIPTION)
8790
media_warning: str | None = call.data.get(ATTR_MEDIA_WARNING)
@@ -93,6 +96,7 @@ async def async_post(call: ServiceCall) -> ServiceResponse:
9396
status=status,
9497
visibility=visibility,
9598
spoiler_text=spoiler_text,
99+
language=language,
96100
media_path=media_path,
97101
media_description=media_description,
98102
sensitive=media_warning,

‎homeassistant/components/mastodon/services.yaml‎

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,209 @@ post:
2121
content_warning:
2222
selector:
2323
text:
24+
language:
25+
required: false
26+
selector:
27+
language:
28+
languages:
29+
- "aa"
30+
- "ab"
31+
- "ae"
32+
- "af"
33+
- "ak"
34+
- "am"
35+
- "an"
36+
- "ar"
37+
- "as"
38+
- "ast"
39+
- "av"
40+
- "ay"
41+
- "az"
42+
- "ba"
43+
- "be"
44+
- "bg"
45+
- "bi"
46+
- "bm"
47+
- "bn"
48+
- "bo"
49+
- "br"
50+
- "bs"
51+
- "ca"
52+
- "ce"
53+
- "ch"
54+
- "chr"
55+
- "ckb"
56+
- "cnr"
57+
- "co"
58+
- "cr"
59+
- "cs"
60+
- "cu"
61+
- "cv"
62+
- "cy"
63+
- "da"
64+
- "de"
65+
- "dv"
66+
- "dz"
67+
- "ee"
68+
- "el"
69+
- "en"
70+
- "eo"
71+
- "es"
72+
- "et"
73+
- "eu"
74+
- "fa"
75+
- "ff"
76+
- "fi"
77+
- "fj"
78+
- "fo" # codespell:ignore fo
79+
- "fr"
80+
- "fy"
81+
- "ga"
82+
- "gd"
83+
- "gl"
84+
- "gu"
85+
- "gv"
86+
- "ha"
87+
- "he"
88+
- "hi"
89+
- "ho"
90+
- "hr"
91+
- "ht"
92+
- "hu"
93+
- "hy"
94+
- "hz"
95+
- "ia"
96+
- "id"
97+
- "ie"
98+
- "ig"
99+
- "ii"
100+
- "ik"
101+
- "io"
102+
- "is"
103+
- "it"
104+
- "iu"
105+
- "ja"
106+
- "jbo"
107+
- "jv"
108+
- "ka"
109+
- "kab"
110+
- "kg"
111+
- "ki"
112+
- "kj"
113+
- "kk"
114+
- "kl"
115+
- "km"
116+
- "kn"
117+
- "ko"
118+
- "kr"
119+
- "ks"
120+
- "ku"
121+
- "kv"
122+
- "kw"
123+
- "ky"
124+
- "la"
125+
- "lb"
126+
- "lfn"
127+
- "lg"
128+
- "li"
129+
- "ln"
130+
- "lo"
131+
- "lt"
132+
- "lu"
133+
- "lv"
134+
- "mg"
135+
- "mh"
136+
- "mi"
137+
- "mk"
138+
- "ml"
139+
- "mn"
140+
- "mr"
141+
- "ms"
142+
- "mt"
143+
- "my"
144+
- "na"
145+
- "nb"
146+
- "nd" # codespell:ignore nd
147+
- "ne"
148+
- "ng"
149+
- "nl"
150+
- "nn"
151+
- "no"
152+
- "nr"
153+
- "nv"
154+
- "ny"
155+
- "oc"
156+
- "oj"
157+
- "om"
158+
- "or"
159+
- "os"
160+
- "pa"
161+
- "pi"
162+
- "pl"
163+
- "ps"
164+
- "pt"
165+
- "qu"
166+
- "rm"
167+
- "rn"
168+
- "ro"
169+
- "ru"
170+
- "rw"
171+
- "sa"
172+
- "sc"
173+
- "sco"
174+
- "sd"
175+
- "se"
176+
- "sg"
177+
- "si"
178+
- "sk"
179+
- "sl"
180+
- "sma"
181+
- "smj"
182+
- "sn"
183+
- "so"
184+
- "sq"
185+
- "sr"
186+
- "ss"
187+
- "st"
188+
- "su"
189+
- "sv"
190+
- "sw"
191+
- "szl"
192+
- "ta"
193+
- "te" # codespell:ignore te
194+
- "tg"
195+
- "th"
196+
- "ti"
197+
- "tk"
198+
- "tl"
199+
- "tn"
200+
- "to"
201+
- "tok"
202+
- "tr"
203+
- "ts"
204+
- "tt"
205+
- "tw"
206+
- "ty"
207+
- "ug"
208+
- "uk"
209+
- "ur"
210+
- "uz"
211+
- "ve"
212+
- "vi"
213+
- "vo"
214+
- "wa"
215+
- "wo"
216+
- "xal"
217+
- "xh"
218+
- "yi"
219+
- "yo"
220+
- "za"
221+
- "zgh"
222+
- "zh"
223+
- "zh-CN"
224+
- "zh-HK"
225+
- "zh-TW"
226+
- "zu"
24227
media:
25228
selector:
26229
text:

‎homeassistant/components/mastodon/strings.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979
"name": "Content warning",
8080
"description": "A content warning will be shown before the status text is shown (default: no content warning)."
8181
},
82+
"language": {
83+
"name": "Language",
84+
"description": "The language of the post (default: Mastodon account preference)."
85+
},
8286
"media": {
8387
"name": "Media",
8488
"description": "Attach an image or video to the post."

‎tests/components/mastodon/test_services.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from homeassistant.components.mastodon.const import (
99
ATTR_CONTENT_WARNING,
10+
ATTR_LANGUAGE,
1011
ATTR_MEDIA,
1112
ATTR_MEDIA_DESCRIPTION,
1213
ATTR_STATUS,
@@ -34,6 +35,7 @@
3435
"status": "test toot",
3536
"spoiler_text": None,
3637
"visibility": None,
38+
"language": None,
3739
"media_ids": None,
3840
"sensitive": None,
3941
},
@@ -44,6 +46,7 @@
4446
"status": "test toot",
4547
"spoiler_text": None,
4648
"visibility": "private",
49+
"language": None,
4750
"media_ids": None,
4851
"sensitive": None,
4952
},
@@ -58,6 +61,7 @@
5861
"status": "test toot",
5962
"spoiler_text": "Spoiler",
6063
"visibility": "private",
64+
"language": None,
6165
"media_ids": None,
6266
"sensitive": None,
6367
},
@@ -66,12 +70,14 @@
6670
{
6771
ATTR_STATUS: "test toot",
6872
ATTR_CONTENT_WARNING: "Spoiler",
73+
ATTR_LANGUAGE: "nl",
6974
ATTR_MEDIA: "/image.jpg",
7075
},
7176
{
7277
"status": "test toot",
7378
"spoiler_text": "Spoiler",
7479
"visibility": None,
80+
"language": "nl",
7581
"media_ids": "1",
7682
"sensitive": None,
7783
},
@@ -80,17 +86,30 @@
8086
{
8187
ATTR_STATUS: "test toot",
8288
ATTR_CONTENT_WARNING: "Spoiler",
89+
ATTR_LANGUAGE: "en",
8390
ATTR_MEDIA: "/image.jpg",
8491
ATTR_MEDIA_DESCRIPTION: "A test image",
8592
},
8693
{
8794
"status": "test toot",
8895
"spoiler_text": "Spoiler",
8996
"visibility": None,
97+
"language": "en",
9098
"media_ids": "1",
9199
"sensitive": None,
92100
},
93101
),
102+
(
103+
{ATTR_STATUS: "test toot", ATTR_LANGUAGE: "invalid-lang"},
104+
{
105+
"status": "test toot",
106+
"language": "invalid-lang",
107+
"spoiler_text": None,
108+
"visibility": None,
109+
"media_ids": None,
110+
"sensitive": None,
111+
},
112+
),
94113
],
95114
)
96115
async def test_service_post(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /