diff --git a/adafruit_io/adafruit_io.py b/adafruit_io/adafruit_io.py index 28822a4..8463046 100755 --- a/adafruit_io/adafruit_io.py +++ b/adafruit_io/adafruit_io.py @@ -636,12 +636,17 @@ def send_batch_data(self, feed_key: str, data_list: list): Sends a batch array of data to a specified Adafruit IO feed :param str feed_key: Adafruit IO feed key - :param list Data: Data list to send + :param list Data: Data list to send (namedtuples or dicts with 'value' key) """ validate_feed_key(feed_key) + if not isinstance(data_list, list) or data_list == []: + raise ValueError("Data must be a list of dicts or namedtuples") + if not isinstance(data_list[0], dict): # assume namedtuple + data_list = type(data_list)((data._asdict() for data in data_list)) + if not all("value" in data for data in data_list): + raise ValueError("Data list items must at least contain a 'value' key") path = "feeds/{0}/data/batch".format(feed_key) - data_dict = type(data_list)((data._asdict() for data in data_list)) - self._post(path, {"data": data_dict}) + self._post(path, {"data": data_list}) def receive_all_data(self, feed_key: str): """