46045-syslab/syslab/virtual/FlexHouse_real.py

47 lines
1.5 KiB
Python

class FlexHouse_real():
def __init__(self):
pass
def setActivePower(self, power_reference):
if power_reference < -10:
power_reference = -10
if power_reference > 0:
raise ValueError("Positive power means production")
self.__setValue('flexHousePowerRef_kW',-power_reference)
def getTemperature(self):
return self.__getValue('flexHouseTemperature_C')
def getActivePower(self):
return self.__getValue('flexHousePower_kW')
def __getValue(self, key):
from requests import get, auth
import re
if not type(key) is str: raise TypeError('Key should be a string, found {0}'.format(type(key)))
if key is '': raise TypeError('Key should be an empty string')
url = 'http://whiteboard.syslab.dk/wbget.php'
r = get(url, auth=auth.HTTPBasicAuth('twinPV99', 'twinPV99'))
entries = r.text.split('\n')
result = None
for entry in entries:
entry = entry.rstrip().lstrip()
g = re.match('SYSLAB@(\d+):{0}=(.+);'.format(key), entry)
if g is None:
continue
else:
g = g.groups()
result = g[1]
break
return result
def __setValue(selv, key, value):
from requests import post, auth
url = '{0}{1}?source=SYSLAB&{2}={3}'.format('http://whiteboard.syslab.dk/', 'wbset.php', key, str(value))
post(url, auth=auth.HTTPBasicAuth('twinPV99', 'twinPV99'))