Skip to content

Commit

Permalink
added get_dev_reading_time to read the timestamp of a reading
Browse files Browse the repository at this point in the history
  • Loading branch information
logi85 committed Sep 12, 2017
1 parent 29c4cfb commit 11719b4
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions fhem/fhem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,42 @@ def get_dev_readings(self, dev, readings, timeout=0.1):
print("E - Reading not defined:", dev, reading)
return reads

def get_dev_reading_time(self, dev, reading, timeout=0.1):
'''Get the date and time of a specific reading from a FHEM device
:param dev: FHEM device
:param reading: name of FHEM reading
:param timeout: timeout for reply'''
read = None
state = self.get_dev_state(dev, timeout=timeout)
if state == {}:
return None
try:
read = state['Results'][0]['Readings'][reading]['Time']
except:
if self.loglevel > 0:
print("E - Reading not defined:", dev, reading)
return read
return read

def get_dev_readings_time(self, dev, readings, timeout=0.1):
'''Get a list of dates and times of readings for one FHEM device
:param dev: FHEM device
'param readings': array of FHEM reading names
:param timeout: timeout for reply'''
reads = {}
state = self.get_dev_state(dev, timeout=timeout)
if state == {}:
return reads
for reading in readings:
try:
rr1 = state['Results'][0]
reads[reading] = rr1['Readings'][reading]['Time']
except:
if self.loglevel > 0:
print("E - Reading not defined:", dev, reading)
return reads


def getFhemState(self, timeout=0.1):
if self.loglevel > 0:
print("Deprecation: use get_fhem_state instead of getFhemState")
Expand Down

0 comments on commit 11719b4

Please sign in to comment.