1 """Alexa Resources and Assets."""
7 """The Global Alexa catalog.
9 https://developer.amazon.com/docs/device-apis/resources-and-assets.html#global-alexa-catalog
11 You can use the global Alexa catalog for pre-defined names of devices, settings,
14 This catalog is localized into all the languages that Alexa supports.
15 You can reference the following catalog of pre-defined friendly names.
17 Each item in the following list is an asset identifier followed by its
18 supported friendly names. The first friendly name for each identifier is
19 the one displayed in the Alexa mobile app.
23 DEVICE_NAME_AIR_PURIFIER =
"Alexa.DeviceName.AirPurifier"
26 DEVICE_NAME_FAN =
"Alexa.DeviceName.Fan"
29 DEVICE_NAME_ROUTER =
"Alexa.DeviceName.Router"
33 DEVICE_NAME_SHADE =
"Alexa.DeviceName.Shade"
36 DEVICE_NAME_SHOWER =
"Alexa.DeviceName.Shower"
39 DEVICE_NAME_SPACE_HEATER =
"Alexa.DeviceName.SpaceHeater"
42 DEVICE_NAME_WASHER =
"Alexa.DeviceName.Washer"
45 SETTING_2G_GUEST_WIFI =
"Alexa.Setting.2GGuestWiFi"
48 SETTING_5G_GUEST_WIFI =
"Alexa.Setting.5GGuestWiFi"
51 SETTING_AUTO =
"Alexa.Setting.Auto"
54 SETTING_DIRECTION =
"Alexa.Setting.Direction"
57 SETTING_DRY_CYCLE =
"Alexa.Setting.DryCycle"
60 SETTING_FAN_SPEED =
"Alexa.Setting.FanSpeed"
63 SETTING_GUEST_WIFI =
"Alexa.Setting.GuestWiFi"
66 SETTING_HEAT =
"Alexa.Setting.Heat"
69 SETTING_MODE =
"Alexa.Setting.Mode"
72 SETTING_NIGHT =
"Alexa.Setting.Night"
75 SETTING_OPENING =
"Alexa.Setting.Opening"
78 SETTING_OSCILLATE =
"Alexa.Setting.Oscillate"
81 SETTING_PRESET =
"Alexa.Setting.Preset"
84 SETTING_QUIET =
"Alexa.Setting.Quiet"
87 SETTING_TEMPERATURE =
"Alexa.Setting.Temperature"
90 SETTING_WASH_CYCLE =
"Alexa.Setting.WashCycle"
93 SETTING_WATER_TEMPERATURE =
"Alexa.Setting.WaterTemperature"
96 SHOWER_HAND_HELD =
"Alexa.Shower.HandHeld"
99 SHOWER_RAIN_HEAD =
"Alexa.Shower.RainHead"
102 UNIT_ANGLE_DEGREES =
"Alexa.Unit.Angle.Degrees"
105 UNIT_ANGLE_RADIANS =
"Alexa.Unit.Angle.Radians"
108 UNIT_DISTANCE_FEET =
"Alexa.Unit.Distance.Feet"
111 UNIT_DISTANCE_INCHES =
"Alexa.Unit.Distance.Inches"
114 UNIT_DISTANCE_KILOMETERS =
"Alexa.Unit.Distance.Kilometers"
117 UNIT_DISTANCE_METERS =
"Alexa.Unit.Distance.Meters"
120 UNIT_DISTANCE_MILES =
"Alexa.Unit.Distance.Miles"
123 UNIT_DISTANCE_YARDS =
"Alexa.Unit.Distance.Yards"
126 UNIT_MASS_GRAMS =
"Alexa.Unit.Mass.Grams"
129 UNIT_MASS_KILOGRAMS =
"Alexa.Unit.Mass.Kilograms"
132 UNIT_PERCENT =
"Alexa.Unit.Percent"
135 UNIT_TEMPERATURE_CELSIUS =
"Alexa.Unit.Temperature.Celsius"
138 UNIT_TEMPERATURE_DEGREES =
"Alexa.Unit.Temperature.Degrees"
141 UNIT_TEMPERATURE_FAHRENHEIT =
"Alexa.Unit.Temperature.Fahrenheit"
144 UNIT_TEMPERATURE_KELVIN =
"Alexa.Unit.Temperature.Kelvin"
147 UNIT_VOLUME_CUBIC_FEET =
"Alexa.Unit.Volume.CubicFeet"
150 UNIT_VOLUME_CUBIC_METERS =
"Alexa.Unit.Volume.CubicMeters"
153 UNIT_VOLUME_GALLONS =
"Alexa.Unit.Volume.Gallons"
156 UNIT_VOLUME_LITERS =
"Alexa.Unit.Volume.Liters"
159 UNIT_VOLUME_PINTS =
"Alexa.Unit.Volume.Pints"
162 UNIT_VOLUME_QUARTS =
"Alexa.Unit.Volume.Quarts"
165 UNIT_WEIGHT_OUNCES =
"Alexa.Unit.Weight.Ounces"
168 UNIT_WEIGHT_POUNDS =
"Alexa.Unit.Weight.Pounds"
171 VALUE_CLOSE =
"Alexa.Value.Close"
174 VALUE_DELICATE =
"Alexa.Value.Delicate"
177 VALUE_HIGH =
"Alexa.Value.High"
180 VALUE_LOW =
"Alexa.Value.Low"
183 VALUE_MAXIMUM =
"Alexa.Value.Maximum"
186 VALUE_MEDIUM =
"Alexa.Value.Medium"
189 VALUE_MINIMUM =
"Alexa.Value.Minimum"
192 VALUE_OPEN =
"Alexa.Value.Open"
195 VALUE_QUICK_WASH =
"Alexa.Value.QuickWash"
199 """Base class for Alexa capabilityResources, modeResources, and presetResources.
201 Resources objects labels must be unique across all modeResources and
202 presetResources within the same device. To provide support for all
203 supported locales, include one label from the AlexaGlobalCatalog in the
206 You cannot use any words from the following list as friendly names:
207 https://developer.amazon.com/docs/alexa/device-apis/resources-and-assets.html#names-you-cannot-use
209 https://developer.amazon.com/docs/device-apis/resources-and-assets.html#capability-resources
213 """Initialize an Alexa resource."""
219 """Return capabilityResources object serialized for an API response."""
223 """Return serialized configuration for an API response.
225 Return ModeResources, PresetResources friendlyNames serialized.
227 raise NotImplementedError
230 """Return serialized labels for an API response.
232 Returns resource label objects for friendlyNames serialized.
234 labels: list[dict[str, Any]] = []
235 label_dict: dict[str, Any]
236 for label
in resources:
237 if label
in AlexaGlobalCatalog.__dict__.values():
238 label_dict = {
"@type":
"asset",
"value": {
"assetId": label}}
242 "value": {
"text": label,
"locale":
"en-US"},
245 labels.append(label_dict)
247 return {
"friendlyNames": labels}
251 """Implements Alexa ModeResources.
253 https://developer.amazon.com/docs/device-apis/resources-and-assets.html#capability-resources
256 def __init__(self, labels: list[str], ordered: bool =
False) ->
None:
257 """Initialize an Alexa modeResource."""
259 self._supported_modes: list[dict[str, Any]] = []
260 self._mode_ordered: bool = ordered
262 def add_mode(self, value: str, labels: list[str]) ->
None:
263 """Add mode to the supportedModes object."""
264 self._supported_modes.append({
"value": value,
"labels": labels})
267 """Return serialized configuration for an API response.
269 Returns configuration for ModeResources friendlyNames serialized.
271 mode_resources: list[dict[str, Any]] = []
272 for mode
in self._supported_modes:
274 "value": mode[
"value"],
277 mode_resources.append(result)
279 return {
"ordered": self._mode_ordered,
"supportedModes": mode_resources}
283 """Implements Alexa PresetResources.
285 Use presetResources with RangeController to provide a set of
286 friendlyNames for each RangeController preset.
288 https://developer.amazon.com/docs/device-apis/resources-and-assets.html#presetresources
297 unit: str |
None =
None,
299 """Initialize an Alexa presetResource."""
301 self._presets: list[dict[str, Any]] = []
306 if unit
in AlexaGlobalCatalog.__dict__.values():
309 def add_preset(self, value: float, labels: list[str]) ->
None:
310 """Add preset to configuration presets array."""
311 self._presets.append({
"value": value,
"labels": labels})
314 """Return serialized configuration for an API response.
316 Returns configuration for PresetResources friendlyNames serialized.
318 configuration: dict[str, Any] = {
332 "rangeValue": preset[
"value"],
335 for preset
in self._presets
337 configuration[
"presets"] = preset_resources
343 """Class for Alexa Semantics Object.
345 You can optionally enable additional utterances by using semantics. When
346 you use semantics, you manually map the phrases "open", "close", "raise",
347 and "lower" to directives.
349 Semantics is supported for the following interfaces only: ModeController,
350 RangeController, and ToggleController.
352 Semantics stateMappings are only supported for one interface of the same
353 type on the same device. If a device has multiple RangeControllers only
354 one interface may use stateMappings otherwise discovery will fail.
356 You can support semantics actionMappings on different controllers for the
357 same device, however each controller must support different phrases.
358 For example, you can support "raise" on a RangeController, and "open"
359 on a ModeController, but you can't support "open" on both RangeController
360 and ModeController. Semantics stateMappings are only supported for one
361 interface on the same device.
363 https://developer.amazon.com/docs/device-apis/alexa-discovery.html#semantics-object
366 MAPPINGS_ACTION =
"actionMappings"
367 MAPPINGS_STATE =
"stateMappings"
369 ACTIONS_TO_DIRECTIVE =
"ActionsToDirective"
370 STATES_TO_VALUE =
"StatesToValue"
371 STATES_TO_RANGE =
"StatesToRange"
373 ACTION_CLOSE =
"Alexa.Actions.Close"
374 ACTION_LOWER =
"Alexa.Actions.Lower"
375 ACTION_OPEN =
"Alexa.Actions.Open"
376 ACTION_RAISE =
"Alexa.Actions.Raise"
378 STATES_OPEN =
"Alexa.States.Open"
379 STATES_CLOSED =
"Alexa.States.Closed"
381 DIRECTIVE_RANGE_SET_VALUE =
"SetRangeValue"
382 DIRECTIVE_RANGE_ADJUST_VALUE =
"AdjustRangeValue"
383 DIRECTIVE_TOGGLE_TURN_ON =
"TurnOn"
384 DIRECTIVE_TOGGLE_TURN_OFF =
"TurnOff"
385 DIRECTIVE_MODE_SET_MODE =
"SetMode"
386 DIRECTIVE_MODE_ADJUST_MODE =
"AdjustMode"
389 """Initialize an Alexa modeResource."""
390 self._action_mappings: list[dict[str, Any]] = []
391 self._state_mappings: list[dict[str, Any]] = []
394 """Add action mapping between actions and interface directives."""
395 self._action_mappings.append(semantics)
398 """Add state mapping between states and interface directives."""
399 self._state_mappings.append(semantics)
402 """Add StatesToValue stateMappings."""
404 {
"@type": self.
STATES_TO_VALUESTATES_TO_VALUE,
"states": states,
"value": value}
408 self, states: list[str], min_value: float, max_value: float
410 """Add StatesToRange stateMappings."""
415 "range": {
"minimumValue": min_value,
"maximumValue": max_value},
420 self, actions: list[str], directive: str, payload: dict[str, Any]
422 """Add ActionsToDirective actionMappings."""
427 "directive": {
"name": directive,
"payload": payload},
432 """Return semantics object serialized for an API response."""
433 semantics: dict[str, Any] = {}
434 if self._action_mappings:
436 if self._state_mappings:
437 semantics[self.
MAPPINGS_STATEMAPPINGS_STATE] = self._state_mappings
None __init__(self, list[str] labels)
dict[str, list[dict[str, Any]]] serialize_capability_resources(self)
dict[str, Any] serialize_configuration(self)
dict[str, list[dict[str, Any]]] serialize_labels(self, list[str] resources)
dict[str, Any] serialize_configuration(self)
None add_mode(self, str value, list[str] labels)
None __init__(self, list[str] labels, bool ordered=False)
dict[str, Any] serialize_configuration(self)
None __init__(self, list[str] labels, float min_value, float max_value, float precision, str|None unit=None)
None add_preset(self, float value, list[str] labels)
None _add_action_mapping(self, dict[str, Any] semantics)
None add_states_to_value(self, list[str] states, Any value)
string ACTIONS_TO_DIRECTIVE
None add_action_to_directive(self, list[str] actions, str directive, dict[str, Any] payload)
None add_states_to_range(self, list[str] states, float min_value, float max_value)
None _add_state_mapping(self, dict[str, Any] semantics)
dict[str, Any] serialize_semantics(self)