|
1 | | -# 2.0.0 Migration Guide |
2 | | - |
3 | | -The 2.0 release of the `google-cloud-iot` client is a significant upgrade based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-python), and includes substantial interface changes. Existing code written for earlier versions of this library will likely require updates to use this version. This document describes the changes that have been made, and what you need to do to update your usage. |
4 | | - |
5 | | -If you experience issues or have questions, please file an [issue](https://github.com/googleapis/python-iot/issues). |
6 | | - |
7 | | -## Supported Python Versions |
8 | | - |
9 | | -> **WARNING**: Breaking change |
10 | | -
|
11 | | -The 2.0.0 release requires Python 3.6+. |
12 | | - |
| 1 | +<!-- "Copyright 2023 ClearBlade Inc." |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | +https://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +Unless required by applicable law or agreed to in writing, software |
| 8 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +See the License for the specific language governing permissions and |
| 11 | +limitations under the License. |
| 12 | +Copyright 2018 Google LLC |
| 13 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 14 | +you may not use this file except in compliance with the License. |
| 15 | +You may obtain a copy of the License at |
| 16 | +https://www.apache.org/licenses/LICENSE-2.0 |
| 17 | +Unless required by applicable law or agreed to in writing, software |
| 18 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 19 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 20 | +See the License for the specific language governing permissions and |
| 21 | +limitations under the License. |
| 22 | +Copyright 2023 ClearBlade Inc. |
| 23 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 24 | +you may not use this file except in compliance with the License. |
| 25 | +You may obtain a copy of the License at |
| 26 | +https://www.apache.org/licenses/LICENSE-2.0 |
| 27 | +Unless required by applicable law or agreed to in writing, software |
| 28 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 29 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 30 | +See the License for the specific language governing permissions and |
| 31 | +limitations under the License. |
| 32 | +Copyright 2018 Google LLC |
| 33 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 34 | +you may not use this file except in compliance with the License. |
| 35 | +You may obtain a copy of the License at |
| 36 | +https://www.apache.org/licenses/LICENSE-2.0 |
| 37 | +Unless required by applicable law or agreed to in writing, software |
| 38 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 39 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 40 | +See the License for the specific language governing permissions and |
| 41 | +limitations under the License. --> |
13 | 42 |
|
14 | | -## Method Calls |
15 | | - |
16 | | -> **WARNING**: Breaking change |
17 | | -
|
18 | | -Methods expect request objects. We provide a script that will convert most common use cases. |
19 | | - |
20 | | -* Install the library with `libcst`. |
21 | | - |
22 | | -```py |
23 | | -python3 -m pip install google-cloud-iot[libcst] |
24 | | -``` |
25 | | - |
26 | | -* The script `fixup_iot_v1_keywords.py` is shipped with the library. It expects |
27 | | -an input directory (with the code to convert) and an empty destination directory. |
| 43 | +# 2.0.0 Migration Guide |
28 | 44 |
|
29 | | -```sh |
30 | | -$ fixup_iot_v1_keywords.py --input-directory .samples/ --output-directory samples/ |
31 | | -``` |
| 45 | +The 2.0 release of the `clearblade-cloud-iot` client is a significant upgrade based on addition of two new classes in **iot_v1**: |
32 | 46 |
|
33 | | -**Before:** |
34 | | -```py |
35 | | -from google.cloud import iot_v1 |
| 47 | +- **DeviceCredential** |
| 48 | +- **PublicKeyCredential** |
36 | 49 |
|
37 | | -client = iot_v1.DeviceManagerClient() |
| 50 | +The release also includes enhancements to these classes already present in **iot_v1**: |
38 | 51 |
|
39 | | -registry = client.get_device_registry("registry_name") |
40 | | -``` |
| 52 | +- **DeviceConfig** |
| 53 | +- **DeviceState** |
41 | 54 |
|
| 55 | +The version was made with the intent of minimizing required code changes. **However these changes should be considrered Breaking changes**. |
42 | 56 |
|
43 | | -**After:** |
44 | | -```py |
45 | | -from google.cloud import iot_v1 |
| 57 | +# |
46 | 58 |
|
47 | | -client = iot_v1.DeviceManagerClient() |
| 59 | +1. If **device** is an object of class **Device**. |
48 | 60 |
|
49 | | -registry = client.get_device_registry(request={'name': "registry_name"}) |
50 | | -``` |
| 61 | + **Before**: |
| 62 | + device.credentials is of type **[dict]** (i.e. list of dicts). |
51 | 63 |
|
52 | | -### More Details |
| 64 | + **After**: |
| 65 | + device.credentials is of type **[DeviceCredential]** (i.e. list of objects of class DeviceCredential). |
53 | 66 |
|
54 | | -In `google-cloud-iot<2.0.0`, parameters required by the API were positional parameters and optional parameters were keyword parameters. |
| 67 | + The **DeviceCredential** class has these features for usability: |
55 | 68 |
|
56 | | -**Before:** |
57 | | -```py |
58 | | - def create_device( |
59 | | - self, |
60 | | - parent, |
61 | | - device, |
62 | | - retry=google.api_core.gapic_v1.method.DEFAULT, |
63 | | - timeout=google.api_core.gapic_v1.method.DEFAULT, |
64 | | - metadata=None, |
65 | | - ): |
66 | | -``` |
| 69 | + - A **get** method that mimics the **get** method of a dict. |
| 70 | + - Allows accessing attributes using dot notation OR square-brackets. |
| 71 | + - Supports camel-case as well as snake-case for accessing attributes: |
67 | 72 |
|
68 | | -In the 2.0.0 release, all methods have a single positional parameter `request`. Method docstrings indicate whether a parameter is required or optional. |
| 73 | + e.g. All these are valid for retrieving the public key: |
69 | 74 |
|
70 | | -Some methods have additional keyword only parameters. The available parameters depend on the `google.api.method_signature` annotation specified by the API producer. |
| 75 | + - **public_key = device.credentials[0]['publicKey']** |
| 76 | + - **public_key = device.credentials[0]['public_key']** |
| 77 | + - **public_key = device.credentials[0].get('publicKey')** |
| 78 | + - **public_key = device.credentials[0].get('public_key')** |
| 79 | + - **public_key = device.credentials[0].publicKey** |
| 80 | + - **public_key = device.credentials[0].public_key** |
71 | 81 |
|
| 82 | +# |
72 | 83 |
|
73 | | -**After:** |
74 | | -```py |
75 | | - def create_device( |
76 | | - self, |
77 | | - request: device_manager.CreateDeviceRequest = None, |
78 | | - *, |
79 | | - parent: str = None, |
80 | | - device: resources.Device = None, |
81 | | - retry: retries.Retry = gapic_v1.method.DEFAULT, |
82 | | - timeout: float = None, |
83 | | - metadata: Sequence[Tuple[str, str]] = (), |
84 | | - ) -> resources.Device: |
85 | | -``` |
| 84 | +2. This refers to pub_key mentioned in the previous section. |
86 | 85 |
|
87 | | -> **NOTE:** The `request` parameter and flattened keyword parameters for the API are mutually exclusive. |
88 | | -> Passing both will result in an error. |
| 86 | + **Before**: |
| 87 | + public_key was of type **dict**. |
89 | 88 |
|
| 89 | + **After**: |
| 90 | + public_key is an object of class **PublicKeyCredential**. |
90 | 91 |
|
91 | | -Both of these calls are valid: |
| 92 | + The **PublicKeyCredential** class has these features for usability: |
92 | 93 |
|
93 | | -```py |
94 | | -response = client.create_device( |
95 | | - request={ |
96 | | - "parent": parent, |
97 | | - "device": device, |
98 | | - } |
99 | | -) |
100 | | -``` |
| 94 | + - A **get** method that mimics the **get** method of a dict. |
| 95 | + - Allows accessing attributes using dot notation OR square-brackets. |
101 | 96 |
|
102 | | -```py |
103 | | -response = client.create_device( |
104 | | - parent=parent, |
105 | | - device=device, |
106 | | -) |
107 | | -``` |
| 97 | + e.g. All these are valid for retrieving the public key format: |
108 | 98 |
|
109 | | -This call is invalid because it mixes `request` with a keyword argument `device`. Executing this code |
110 | | -will result in an error. |
| 99 | + - **format = public_key['format']** |
| 100 | + - **format = public_key.get('format')** |
| 101 | + - **format = public_key.format** |
111 | 102 |
|
112 | | -```py |
113 | | -response = client.create_device( |
114 | | - request={ |
115 | | - "parent": parent, |
116 | | - }, |
117 | | - device=device |
118 | | -) |
119 | | -``` |
| 103 | +# |
120 | 104 |
|
| 105 | +3. This section refers to **dev_config** which holds device config. |
121 | 106 |
|
| 107 | + **Before**: |
| 108 | + dev_config is of type **dict**. |
122 | 109 |
|
123 | | -## Enums and Types |
| 110 | + **After**: |
| 111 | + dev_config is an object of class **DeviceConfig**. |
124 | 112 |
|
| 113 | + The **DeviceConfig** class has these features for usability: |
125 | 114 |
|
126 | | -> **WARNING**: Breaking change |
| 115 | + - A **get** method that mimics the **get** method of a dict. |
| 116 | + - Allows accessing attributes using dot notation OR square-brackets. |
| 117 | + - Supports camel-case as well as snake-case for accessing attributes: |
127 | 118 |
|
128 | | -The submodules `enums` and `types` have been removed. |
| 119 | + e.g. All these are valid for retrieving the cloud_update_time: |
129 | 120 |
|
130 | | -**Before:** |
131 | | -```py |
132 | | -from google.cloud import iot_v1 |
| 121 | + - **cloud_update_time = device.credentials[0]['cloudUpdateTime']** |
| 122 | + - **cloud_update_time = device.credentials[0]['cloud_update_time']** |
| 123 | + - **cloud_update_time = device.credentials[0].get('cloudUpdateTime')** |
| 124 | + - **cloud_update_time = device.credentials[0].get('cloud_update_time')** |
| 125 | + - **cloud_update_time = device.credentials[0].cloudUpdateTime** |
| 126 | + - **cloud_update_time = device.credentials[0].cloud_update_time** |
133 | 127 |
|
134 | | -gateway_type = iot_v1.enums.GatewayType.GATEWAY |
135 | | -device = iot_v1.types.Device(name="name") |
136 | | -``` |
| 128 | +# |
137 | 129 |
|
| 130 | +4. This section refers to **dev_state** which contains device state. |
138 | 131 |
|
139 | | -**After:** |
140 | | -```py |
141 | | -from google.cloud import iot_v1 |
| 132 | + **Before**: |
| 133 | + dev_state is of type **dict**. |
142 | 134 |
|
143 | | -gateway_type = iot_v1.GatewayType.GATEWAY |
144 | | -device = iot_v1.Device(name="name") |
145 | | -``` |
| 135 | + **After**: |
| 136 | + dev_state is an object of class **DeviceState**. |
146 | 137 |
|
147 | | -## Location Path Helper Method |
| 138 | + The **DeviceState** class has these features for usability: |
148 | 139 |
|
149 | | -Location path helper method has been removed. Please construct |
150 | | -the path manually. |
| 140 | + - A **get** method that mimics the **get** method of a dict. |
| 141 | + - Allows accessing attributes using dot notation OR square-brackets. |
| 142 | + - Supports camel-case as well as snake-case for accessing attributes: |
151 | 143 |
|
152 | | -```py |
153 | | -project = 'my-project' |
154 | | -location = 'location' |
| 144 | + e.g. All these are valid for retrieving the binary_data: |
155 | 145 |
|
156 | | -location_path = f'projects/{project}/locations/{location}' |
157 | | -``` |
| 146 | + - **binary_data = device.credentials[0]['binaryData']** |
| 147 | + - **binary_data = device.credentials[0]['binary_data']** |
| 148 | + - **binary_data = device.credentials[0].get('binaryData')** |
| 149 | + - **binary_data = device.credentials[0].get('binary_data')** |
| 150 | + - **binary_data = device.credentials[0].binaryData** |
| 151 | + - **binary_data = device.credentials[0].binary_data** |
0 commit comments