|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +# |
| 4 | +# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file |
| 7 | +# except in compliance with the License. A copy of the License is located at |
| 8 | +# |
| 9 | +# http://aws.amazon.com/apache2.0/ |
| 10 | +# |
| 11 | +# or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for |
| 13 | +# the specific language governing permissions and limitations under the License. |
| 14 | +# |
| 15 | + |
| 16 | +import pprint |
| 17 | +import re # noqa: F401 |
| 18 | +import six |
| 19 | +import typing |
| 20 | +from enum import Enum |
| 21 | +from ask_sdk_model.interfaces.alexa.presentation.apl.command import Command |
| 22 | + |
| 23 | + |
| 24 | +if typing.TYPE_CHECKING: |
| 25 | + from typing import Dict, List, Optional |
| 26 | + from datetime import datetime |
| 27 | + |
| 28 | + |
| 29 | +class SetValueCommand(Command): |
| 30 | + """ |
| 31 | + Change a dynamic property of a component without redrawing the screen. |
| 32 | +
|
| 33 | +
|
| 34 | + :param delay: The delay in milliseconds before this command starts executing; must be non-negative. Defaults to 0. |
| 35 | + :type delay: (optional) int |
| 36 | + :param description: A user-provided description of this command. |
| 37 | + :type description: (optional) str |
| 38 | + :param when: If false, the execution of the command is skipped. Defaults to true. |
| 39 | + :type when: (optional) bool |
| 40 | + :param component_id: The id of the component whose value to set. |
| 41 | + :type component_id: (optional) str |
| 42 | + :param object_property: The name of the property to set. |
| 43 | + :type object_property: (optional) str |
| 44 | + :param value: The property value to set. |
| 45 | + :type value: (optional) str |
| 46 | +
|
| 47 | + """ |
| 48 | + deserialized_types = { |
| 49 | + 'object_type': 'str', |
| 50 | + 'delay': 'int', |
| 51 | + 'description': 'str', |
| 52 | + 'when': 'bool', |
| 53 | + 'component_id': 'str', |
| 54 | + 'object_property': 'str', |
| 55 | + 'value': 'str' |
| 56 | + } # type: Dict |
| 57 | + |
| 58 | + attribute_map = { |
| 59 | + 'object_type': 'type', |
| 60 | + 'delay': 'delay', |
| 61 | + 'description': 'description', |
| 62 | + 'when': 'when', |
| 63 | + 'component_id': 'componentId', |
| 64 | + 'object_property': 'property', |
| 65 | + 'value': 'value' |
| 66 | + } # type: Dict |
| 67 | + |
| 68 | + def __init__(self, delay=None, description=None, when=None, component_id=None, object_property=None, value=None): |
| 69 | + # type: (Optional[int], Optional[str], Optional[bool], Optional[str], Optional[str], Optional[str]) -> None |
| 70 | + """Change a dynamic property of a component without redrawing the screen. |
| 71 | +
|
| 72 | + :param delay: The delay in milliseconds before this command starts executing; must be non-negative. Defaults to 0. |
| 73 | + :type delay: (optional) int |
| 74 | + :param description: A user-provided description of this command. |
| 75 | + :type description: (optional) str |
| 76 | + :param when: If false, the execution of the command is skipped. Defaults to true. |
| 77 | + :type when: (optional) bool |
| 78 | + :param component_id: The id of the component whose value to set. |
| 79 | + :type component_id: (optional) str |
| 80 | + :param object_property: The name of the property to set. |
| 81 | + :type object_property: (optional) str |
| 82 | + :param value: The property value to set. |
| 83 | + :type value: (optional) str |
| 84 | + """ |
| 85 | + self.__discriminator_value = "SetValue" # type: str |
| 86 | + |
| 87 | + self.object_type = self.__discriminator_value |
| 88 | + super(SetValueCommand, self).__init__(object_type=self.__discriminator_value, delay=delay, description=description, when=when) |
| 89 | + self.component_id = component_id |
| 90 | + self.object_property = object_property |
| 91 | + self.value = value |
| 92 | + |
| 93 | + def to_dict(self): |
| 94 | + # type: () -> Dict[str, object] |
| 95 | + """Returns the model properties as a dict""" |
| 96 | + result = {} # type: Dict |
| 97 | + |
| 98 | + for attr, _ in six.iteritems(self.deserialized_types): |
| 99 | + value = getattr(self, attr) |
| 100 | + if isinstance(value, list): |
| 101 | + result[attr] = list(map( |
| 102 | + lambda x: x.to_dict() if hasattr(x, "to_dict") else |
| 103 | + x.value if isinstance(x, Enum) else x, |
| 104 | + value |
| 105 | + )) |
| 106 | + elif isinstance(value, Enum): |
| 107 | + result[attr] = value.value |
| 108 | + elif hasattr(value, "to_dict"): |
| 109 | + result[attr] = value.to_dict() |
| 110 | + elif isinstance(value, dict): |
| 111 | + result[attr] = dict(map( |
| 112 | + lambda item: (item[0], item[1].to_dict()) |
| 113 | + if hasattr(item[1], "to_dict") else |
| 114 | + (item[0], item[1].value) |
| 115 | + if isinstance(item[1], Enum) else item, |
| 116 | + value.items() |
| 117 | + )) |
| 118 | + else: |
| 119 | + result[attr] = value |
| 120 | + |
| 121 | + return result |
| 122 | + |
| 123 | + def to_str(self): |
| 124 | + # type: () -> str |
| 125 | + """Returns the string representation of the model""" |
| 126 | + return pprint.pformat(self.to_dict()) |
| 127 | + |
| 128 | + def __repr__(self): |
| 129 | + # type: () -> str |
| 130 | + """For `print` and `pprint`""" |
| 131 | + return self.to_str() |
| 132 | + |
| 133 | + def __eq__(self, other): |
| 134 | + # type: (object) -> bool |
| 135 | + """Returns true if both objects are equal""" |
| 136 | + if not isinstance(other, SetValueCommand): |
| 137 | + return False |
| 138 | + |
| 139 | + return self.__dict__ == other.__dict__ |
| 140 | + |
| 141 | + def __ne__(self, other): |
| 142 | + # type: (object) -> bool |
| 143 | + """Returns true if both objects are not equal""" |
| 144 | + return not self == other |
0 commit comments