Skip to content

Commit

Permalink
test suite: added dht22
Browse files Browse the repository at this point in the history
  • Loading branch information
psy0rz committed Jan 19, 2018
1 parent 400ee82 commit 51b7668
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 27 deletions.
10 changes: 5 additions & 5 deletions test/controlleremu.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ def recv_domoticz_http(self, sensor_type, idx, timeout=60):
return svalues
elif sensor_type==SENSOR_TYPE_DUAL and len(svalues)==2:
return svalues
elif sensor_type==SENSOR_TYPE_HUM and len(svalues)==3:
elif sensor_type==SENSOR_TYPE_TEMP_HUM and len(svalues)==3:
return svalues
elif sensor_type==SENSOR_TYPE_BARO and len(svalues)==5:
return [svalues[0], svalues[3]]
elif sensor_type==SENSOR_TYPE_TRIPLE and len(svalues)==3:
return svalues
elif sensor_type==SENSOR_TYPE_HUM_BARO and len(svalues)==5:
elif sensor_type==SENSOR_TYPE_TEMHUM_BARO and len(svalues)==5:
return [svalues[0],svalues[2], svalues[3]]
elif sensor_type==SENSOR_TYPE_QUAD and len(svalues)==4:
return svalues
Expand Down Expand Up @@ -154,13 +154,13 @@ def recv_domoticz_mqtt(self, sensor_type, idx, timeout=60):
return svalues
elif sensor_type==SENSOR_TYPE_DUAL and len(svalues)==2:
return svalues
elif sensor_type==SENSOR_TYPE_HUM and len(svalues)==3:
elif sensor_type==SENSOR_TYPE_TEMP_HUM and len(svalues)==3:
return svalues
elif sensor_type==SENSOR_TYPE_BARO and len(svalues)==5:
elif sensor_type==SENSOR_TYPE_TEMP_BARO and len(svalues)==5:
return [svalues[0], svalues[3]]
elif sensor_type==SENSOR_TYPE_TRIPLE and len(svalues)==3:
return svalues
elif sensor_type==SENSOR_TYPE_HUM_BARO and len(svalues)==5:
elif sensor_type==SENSOR_TYPE_TEMP_HUM_BARO and len(svalues)==5:
return [svalues[0],svalues[2], svalues[3]]
elif sensor_type==SENSOR_TYPE_QUAD and len(svalues)==4:
return svalues
Expand Down
36 changes: 34 additions & 2 deletions test/espeasy.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def device_p001(self, **kwargs):


def device_p004(self, **kwargs):
self._node.log.info("Config device plugin p004 "+str(kwargs))
self._node.log.info("Config ds18b20 with "+str(kwargs))

self._node.http_post(
twice=True, # needed for controllers and devices because of the way its implemented
Expand Down Expand Up @@ -160,8 +160,40 @@ def device_p004(self, **kwargs):
""".format(**kwargs)
)

def device_p005(self, **kwargs):
self._node.log.info("Config DHT22 on D3 with "+str(kwargs))

self._node.http_post(
twice=True, # needed for controllers and devices because of the way its implemented
page="devices",

params="""
index:{index}
""".format(**kwargs),

data="""
TDNUM:5
TDN:
TDE:on
taskdevicepin1:0
plugin_005_dhttype:22
TDSD1:on
TDID1:{TDID1}
TDT:5
TDVN1:Temperature
TDF1:
TDVD1:2
TDVN2:Humidity
TDF2:
TDVD2:2
edit:1
page:1
""".format(**kwargs)
)


def device_p036(self, **kwargs):
self._node.log.info("Config device plugin p036 "+str(kwargs))
self._node.log.info("Config framed oled p036 with "+str(kwargs))

self._node.http_post(
twice=True, # needed for controllers and devices because of the way its implemented
Expand Down
2 changes: 2 additions & 0 deletions test/esptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@ def test_in_range(value, min, max):

if value < min or value > max:
raise(Exception("Value {value} should be between {min} and {max}".format(value=value, min=min, max=max)))

log.info("OK: value {value} is between {min} and {max}".format(value=value, min=min, max=max))
33 changes: 13 additions & 20 deletions test/test002
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,39 @@ from esptest import *


@step
def prepare_http():
"""configure devices and controller"""
def prepare_devices():
node[0].reboot()
node[0].pingserial()
espeasy[0].controller_domoticz_http(index=1, controllerip=config.http_server, controllerport=config.http_port)
espeasy[0].device_p004(index=1, taskdevicepin1=2, plugin_004_dev=0, plugin_004_res=9, TDID1=1417)
espeasy[0].device_p004(index=2, taskdevicepin1=2, plugin_004_dev=1, plugin_004_res=9, TDID1=1418)
espeasy[0].device_p004(index=1, taskdevicepin1=2, plugin_004_dev=0, plugin_004_res=9, TDID1=2001)
espeasy[0].device_p004(index=2, taskdevicepin1=2, plugin_004_dev=1, plugin_004_res=9, TDID1=2002)


@step
def recv_http():
"""wait for http result"""
results=controller.recv_domoticz_http(SENSOR_TYPE_SINGLE,1417)
def test_domoticz_http():
espeasy[0].controller_domoticz_http(index=1, controllerip=config.http_server, controllerport=config.http_port)
results=controller.recv_domoticz_http(SENSOR_TYPE_SINGLE,2001)
test_in_range(results[0], -5,40)
results=controller.recv_domoticz_http(SENSOR_TYPE_SINGLE,1418)
results=controller.recv_domoticz_http(SENSOR_TYPE_SINGLE,2002)
test_in_range(results[0], -5,40)


@step
def prepare_mqtt():
"""switch to mqtt"""
espeasy[0].controller_domoticz_mqtt(index=1, controllerip=config.mqtt_broker)


@step
def recv_mqtt():
"""wait for mqtt result"""
results=controller.recv_domoticz_mqtt(SENSOR_TYPE_SINGLE,1417)
def test_domoticz_mqtt():
espeasy[0].controller_domoticz_mqtt(index=1, controllerip=config.mqtt_broker)
results=controller.recv_domoticz_mqtt(SENSOR_TYPE_SINGLE,2001)
test_in_range(results[0], -5,40)
results=controller.recv_domoticz_mqtt(SENSOR_TYPE_SINGLE,1418)
results=controller.recv_domoticz_mqtt(SENSOR_TYPE_SINGLE,2002)
test_in_range(results[0], -5,40)


@step
def powercycle():
"""test result on poweron"""
node[0].powercycle()
results=controller.recv_domoticz_mqtt(SENSOR_TYPE_SINGLE,1417)
results=controller.recv_domoticz_mqtt(SENSOR_TYPE_SINGLE,2001)
test_in_range(results[0], -5,40)
results=controller.recv_domoticz_mqtt(SENSOR_TYPE_SINGLE,1418)
results=controller.recv_domoticz_mqtt(SENSOR_TYPE_SINGLE,2002)
test_in_range(results[0], -5,40)


Expand Down
30 changes: 30 additions & 0 deletions test/test004
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3

from esptest import *

# hardware requirements:
# - node 0
# - DHT22 on D3

# tests:
# - correct values are send to domoticz via mqtt


@step
def prepare():
node[0].reboot()
node[0].pingserial()
espeasy[0].controller_domoticz_mqtt(index=1, controllerip=config.mqtt_broker)
espeasy[0].device_p005(index=1, TDID1=4001)


@step
def test():
results=controller.recv_domoticz_mqtt(SENSOR_TYPE_TEMP_HUM,4001)
test_in_range(results[0], -5,40)
test_in_range(results[1], 10,80)




run()

0 comments on commit 51b7668

Please sign in to comment.