diff --git a/README.md b/README.md index c37e533..6ac3591 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ def on_switch_changed(client, value): # 1. Create a client object, which is used to connect to the IoT cloud and link local # objects to cloud objects. Note a username and password can be used for basic authentication # on both CPython and MicroPython. For more advanced authentication methods, please see the examples. -client = AIOTClient(device_id=b"DEVICE_ID", username=b"DEVICE_ID", password=b"SECRET_KEY") +client = ArduinoCloudClient(device_id=b"DEVICE_ID", username=b"DEVICE_ID", password=b"SECRET_KEY") # 2. Register cloud objects. # Note: The following objects must be created first in the dashboard and linked to the device. diff --git a/examples/example.py b/examples/example.py index c9e1bd1..55c288d 100644 --- a/examples/example.py +++ b/examples/example.py @@ -4,7 +4,7 @@ import time import logging from time import strftime -from arduino_iot_cloud import AIOTClient +from arduino_iot_cloud import ArduinoCloudClient from arduino_iot_cloud import Location from arduino_iot_cloud import Schedule from arduino_iot_cloud import ColoredLight @@ -59,8 +59,8 @@ def user_task(client): # To use a secure element, set the token's "pin" and URI in "keyfile" and "certfile", and # the CA certificate (if any) in "ssl_params". Alternatively, a username and password can # be used to authenticate, for example: - # client = AIOTClient(device_id=b"DEVICE_ID", username=b"DEVICE_ID", password=b"SECRET_KEY") - client = AIOTClient( + # client = ArduinoCloudClient(device_id=b"DEVICE_ID", username=b"DEVICE_ID", password=b"SECRET_KEY") + client = ArduinoCloudClient( device_id=DEVICE_ID, ssl_params={ "pin": "1234", diff --git a/examples/micropython.py b/examples/micropython.py index 260cca2..f639eb6 100644 --- a/examples/micropython.py +++ b/examples/micropython.py @@ -6,7 +6,7 @@ import network import logging from time import strftime -from arduino_iot_cloud import AIOTClient +from arduino_iot_cloud import ArduinoCloudClient from arduino_iot_cloud import Location from arduino_iot_cloud import Schedule from arduino_iot_cloud import ColoredLight @@ -68,8 +68,8 @@ def wifi_connect(): # Create a client object to connect to the Arduino IoT cloud. # For MicroPython, the key and cert files must be stored in DER format on the filesystem. # Alternatively, a username and password can be used to authenticate: - # client = AIOTClient(device_id=b"DEVICE_ID", username=b"DEVICE_ID", password=b"SECRET_KEY") - client = AIOTClient( + # client = ArduinoCloudClient(device_id=b"DEVICE_ID", username=b"DEVICE_ID", password=b"SECRET_KEY") + client = ArduinoCloudClient( device_id=DEVICE_ID, ssl_params={ "keyfile": KEY_PATH, "certfile": CERT_PATH, "cadata": CADATA, "cert_reqs": ussl.CERT_REQUIRED diff --git a/src/arduino_iot_cloud/__init__.py b/src/arduino_iot_cloud/__init__.py index 3ba436d..dba7630 100644 --- a/src/arduino_iot_cloud/__init__.py +++ b/src/arduino_iot_cloud/__init__.py @@ -4,8 +4,8 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at https://mozilla.org/MPL/2.0/. -from .ucloud import AIOTClient # noqa -from .ucloud import AIOTObject +from .ucloud import ArduinoCloudClient # noqa +from .ucloud import ArduinoCloudObject from .ucloud import timestamp try: @@ -36,27 +36,27 @@ ) -class Location(AIOTObject): +class Location(ArduinoCloudObject): def __init__(self, name, **kwargs): super().__init__(name, keys={"lat", "lon"}, **kwargs) -class Color(AIOTObject): +class Color(ArduinoCloudObject): def __init__(self, name, **kwargs): super().__init__(name, keys={"hue", "sat", "bri"}, **kwargs) -class ColoredLight(AIOTObject): +class ColoredLight(ArduinoCloudObject): def __init__(self, name, **kwargs): super().__init__(name, keys={"swi", "hue", "sat", "bri"}, **kwargs) -class DimmedLight(AIOTObject): +class DimmedLight(ArduinoCloudObject): def __init__(self, name, **kwargs): super().__init__(name, keys={"swi", "bri"}, **kwargs) -class Schedule(AIOTObject): +class Schedule(ArduinoCloudObject): def __init__(self, name, **kwargs): kwargs.update({("runnable", True)}) # Force task creation. self.on_active = kwargs.pop("on_active", None) @@ -78,7 +78,7 @@ async def run(self, aiot): await asyncio.sleep(self.interval) -class Task(AIOTObject): +class Task(ArduinoCloudObject): def __init__(self, name, **kwargs): kwargs.update({("runnable", True)}) # Force task creation. self.on_run = kwargs.pop("on_run", None) diff --git a/src/arduino_iot_cloud/ucloud.py b/src/arduino_iot_cloud/ucloud.py index ee5b95b..95d58c9 100644 --- a/src/arduino_iot_cloud/ucloud.py +++ b/src/arduino_iot_cloud/ucloud.py @@ -37,7 +37,7 @@ def timestamp(): return int(time.time()) -class AIOTObject(SenmlRecord): +class ArduinoCloudObject(SenmlRecord): def __init__(self, name, **kwargs): self.on_read = kwargs.pop("on_read", None) self.on_write = kwargs.pop("on_write", None) @@ -46,7 +46,7 @@ def __init__(self, name, **kwargs): value = kwargs.pop("value", None) if keys := kwargs.pop("keys", {}): value = { # Create a complex object (with sub-records). - k: AIOTObject(f"{name}:{k}", value=v, callback=self.senml_callback) + k: ArduinoCloudObject(f"{name}:{k}", value=v, callback=self.senml_callback) for (k, v) in {k: kwargs.pop(k, None) for k in keys}.items() } self._updated = False @@ -157,7 +157,7 @@ async def run(self, client): await asyncio.sleep(self.interval) -class AIOTClient: +class ArduinoCloudClient: def __init__( self, device_id, @@ -256,9 +256,9 @@ def register(self, aiotobj, coro=None, **kwargs): if isinstance(aiotobj, str): if kwargs.get("value", None) is None and kwargs.get("on_read", None) is not None: kwargs["value"] = kwargs.get("on_read")(self) - aiotobj = AIOTObject(aiotobj, **kwargs) + aiotobj = ArduinoCloudObject(aiotobj, **kwargs) - # Register the AIOTObject + # Register the ArduinoCloudObject self.records[aiotobj.name] = aiotobj # Create a task for this object if it has any callbacks.