Skip to content

Commit

Permalink
now supports powercycle to test for bugs like letscontrolit#719
Browse files Browse the repository at this point in the history
  • Loading branch information
psy0rz committed Jan 16, 2018
1 parent 2aafbb5 commit 09e5d6a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
3 changes: 3 additions & 0 deletions test/espeasy.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def recv_domoticz_http(self, sensor_type, idx, timeout=60):
logging.getLogger("domoticz http").info("Waiting for request idx {idx} with sensortype {sensor_type}".format(sensor_type=sensor_type,idx=idx))

# read and parse http requests
while not http_requests.empty():
http_requests.get()

while time.time()-start_time<timeout:
request=http_requests.get(block=True, timeout=timeout)
if request.path == "/json.htm" and int(request.params.get('idx'))==idx:
Expand Down
2 changes: 1 addition & 1 deletion test/esptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ def run():
def test_in_range(value, min, max):

if value < min or value > max:
raise("Value {value} should be between {min} and {max}".format(value=value, min=min, max=max))
raise(Exception("Value {value} should be between {min} and {max}".format(value=value, min=min, max=max)))
41 changes: 41 additions & 0 deletions test/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,52 @@ def pingserial(self, timeout=60):

def reboot(self):
'''reboot the esp via the serial DTR line'''
self.log.debug("Rebooting")

self.serial_needed()
self._serial.setDTR(0)
time.sleep(0.1)
self._serial.setDTR(1)

def powercycle(self):
"""powercycle the device"""
self.poweroff()
self.poweron()

def poweroff(self):
"""power off device"""


#cant yet be done automaticly unfortunatly
self.log.info("Please power off node "+self._id)

done=False
while not done:
try:
self.serial_needed()
self._serial.readline()
except serial.SerialException:
done=True
if hasattr(self, '_serial'):
del self._serial

self.log.debug("Detected power off")

def poweron(self):
"""power on device"""

self.log.info("Please power on node "+self._id)

done=False
while not done:
try:
self.serial_needed()
self._serial.readline()
done=True
except serial.SerialException:
time.sleep(0.1)

self.log.debug("Detected power on")

def pingwifi(self, timeout=60):
"""waits until espeasy reponds via wifi"""
Expand Down
11 changes: 11 additions & 0 deletions test/test002
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ from esptest import *

# espeasy[0].controller_thingspeak(index=1, controllerip=config.http_server, controllerport=config.http_port)


@step
def prepare():
"""configure devices and controller"""
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)
Expand All @@ -29,6 +32,14 @@ def recv():
results=espeasy[0].recv_domoticz_http(SENSOR_TYPE_SINGLE,1418)
test_in_range(results[0], -5,40)

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


# @step
Expand Down

0 comments on commit 09e5d6a

Please sign in to comment.