Skip to content

Commit d15d1f5

Browse files
committed
[fix] Handled time=None in DeviceDataWriter.write()
1 parent 9513b48 commit d15d1f5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

openwisp_monitoring/device/writer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from copy import deepcopy
33
from datetime import datetime, timedelta
4+
from django.utils import timezone
45

56
from django.contrib.contenttypes.models import ContentType
67
from django.core.exceptions import ObjectDoesNotExist
@@ -60,7 +61,10 @@ def _append_metric_data(
6061
)
6162

6263
def write(self, data, time=None, current=False):
63-
time = datetime.strptime(time, "%d-%m-%Y_%H:%M:%S.%f").replace(tzinfo=UTC)
64+
if time:
65+
time = datetime.strptime(time, "%d-%m-%Y_%H:%M:%S.%f").replace(tzinfo=UTC)
66+
else:
67+
time = timezone.now()
6468
self._init_previous_data()
6569
self.device_data.data = data
6670
# saves raw device data

0 commit comments

Comments
 (0)