Skip to content

Commit

Permalink
Merge 19a60a3 into e7bc941
Browse files Browse the repository at this point in the history
  • Loading branch information
henfri committed Jan 5, 2019
2 parents e7bc941 + 19a60a3 commit 026b86d
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pyblnet/blnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,51 @@ def _turn(self, digital_id, value, can_node=None):
else:
raise EnvironmentError('Can\'t set values with blnet web disabled')

def get_value(self, name=None, id=None, type='digital', ret='value', cached=None):
"""
higher level interface to get a value or mode by name or id
ret: can be 'value', 'mode'
returns the value if ret='value' or the mode if ret='mode' as first return value
and the dictionary containing name, value, id and mode as a second return value
cached: in order to prevent polling data from BLNet with every call,
the data can be fetched once and stored and passed to this function
"""
val=None
dic=None
if name is None and id is None: return val
if cached is None:
cached=self.fetch()
for key,v in cached[type].items():
if str(v['name'])==str(name) or name is None:
if str(v['id'])==str(id) or id is None:
val=v[ret]
dic=v
return val, dic

def get_digital_value(self, ret='value', name=None, id=None, cached=None):
val, dic=self.get_value(type='digital', ret='value', name=name, id=id, cached=cached)
return val, dic

def get_analog_value(self, ret='value', name=None, id=None, cached=None):
val, dic=self.get_value(type='analog', ret='value', name=name, id=id, cached=cached)
return val, dic

def get_energy_value(self, ret='value', name=None, id=None, cached=None):
val, dic=self.get_value(type='energy', ret='value', name=name, id=id, cached=cached)
return val, dic

def get_speed_value(self, ret='value', name=None, id=None, cached=None):
val, dic=self.get_value(type='speed', ret='value', name=name, id=id, cached=cached)
return val, dic

def get_power_value(self, ret='value', name=None, id=None, cached=None):
val, dic=self.get_value(type='power', ret='value', name=name, id=id, cached=cached)
return val, dic



@staticmethod
def _convert_web(values):
"""
Expand Down

0 comments on commit 026b86d

Please sign in to comment.