Skip to content

misc: Rename AIOTClient and AIOTObject classes. #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions examples/micropython.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/arduino_iot_cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/arduino_iot_cloud/ucloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -157,7 +157,7 @@ async def run(self, client):
await asyncio.sleep(self.interval)


class AIOTClient:
class ArduinoCloudClient:
def __init__(
self,
device_id,
Expand Down Expand Up @@ -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.
Expand Down