Skip to content

Commit 11719b4

Browse files
committed
added get_dev_reading_time to read the timestamp of a reading
1 parent 29c4cfb commit 11719b4

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

fhem/fhem/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,42 @@ def get_dev_readings(self, dev, readings, timeout=0.1):
439439
print("E - Reading not defined:", dev, reading)
440440
return reads
441441

442+
def get_dev_reading_time(self, dev, reading, timeout=0.1):
443+
'''Get the date and time of a specific reading from a FHEM device
444+
:param dev: FHEM device
445+
:param reading: name of FHEM reading
446+
:param timeout: timeout for reply'''
447+
read = None
448+
state = self.get_dev_state(dev, timeout=timeout)
449+
if state == {}:
450+
return None
451+
try:
452+
read = state['Results'][0]['Readings'][reading]['Time']
453+
except:
454+
if self.loglevel > 0:
455+
print("E - Reading not defined:", dev, reading)
456+
return read
457+
return read
458+
459+
def get_dev_readings_time(self, dev, readings, timeout=0.1):
460+
'''Get a list of dates and times of readings for one FHEM device
461+
:param dev: FHEM device
462+
'param readings': array of FHEM reading names
463+
:param timeout: timeout for reply'''
464+
reads = {}
465+
state = self.get_dev_state(dev, timeout=timeout)
466+
if state == {}:
467+
return reads
468+
for reading in readings:
469+
try:
470+
rr1 = state['Results'][0]
471+
reads[reading] = rr1['Readings'][reading]['Time']
472+
except:
473+
if self.loglevel > 0:
474+
print("E - Reading not defined:", dev, reading)
475+
return reads
476+
477+
442478
def getFhemState(self, timeout=0.1):
443479
if self.loglevel > 0:
444480
print("Deprecation: use get_fhem_state instead of getFhemState")

0 commit comments

Comments
 (0)