mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-27 19:57:38 +00:00
added http server emulation and domotics http to testsuite
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
wifi.txt
|
||||
__pycache__
|
||||
wificonfig.py
|
||||
|
||||
*.pyc
|
||||
|
||||
+3
-3
@@ -29,6 +29,6 @@ nodes=[
|
||||
|
||||
mqtt_broker="192.168.13.236"
|
||||
|
||||
#make sure this command is running on the http_pretender:
|
||||
# python -m pretenders.server.server --host 0.0.0.0 --port 8000
|
||||
http_pretender="192.168.13.236"
|
||||
#ip of the server running this script
|
||||
http_server="192.168.13.236"
|
||||
http_port=8080
|
||||
|
||||
@@ -47,6 +47,29 @@ class EspEasy:
|
||||
)
|
||||
|
||||
|
||||
def controller_domoticz_http(self, **kwargs):
|
||||
"""config controller to use domoticz via http"""
|
||||
|
||||
self._node.log.info("Config controller domoticz http "+str(kwargs))
|
||||
self._node.http_post(
|
||||
twice=True, # needed for controllers and devices because of the way its implemented
|
||||
page="controllers",
|
||||
|
||||
params="""
|
||||
index:{index}
|
||||
""".format(**kwargs),
|
||||
|
||||
data="""
|
||||
protocol:1
|
||||
usedns:0
|
||||
controllerip:{controllerip}
|
||||
controllerport:{controllerport}
|
||||
controlleruser:
|
||||
controllerpassword:
|
||||
controllerenabled:on
|
||||
""".format(**kwargs)
|
||||
)
|
||||
|
||||
def device_p001(self, **kwargs):
|
||||
self._node.log.info("Config device plugin p001 "+str(kwargs))
|
||||
|
||||
|
||||
+39
-5
@@ -6,6 +6,9 @@ import config
|
||||
import time
|
||||
import paho.mqtt.client as mqtt
|
||||
import json
|
||||
import bottle
|
||||
import threading
|
||||
from Queue import Queue, Empty
|
||||
from espcore import *
|
||||
|
||||
|
||||
@@ -64,8 +67,39 @@ for n in config.nodes:
|
||||
espeasy.append(EspEasy(node[-1]))
|
||||
|
||||
|
||||
### http pretender
|
||||
from pretenders.client.http import HTTPMock
|
||||
from pretenders.common.constants import FOREVER
|
||||
mock = HTTPMock(config.http_pretender, 8000, timeout=20, name='esptest')
|
||||
mock.reset()
|
||||
### http server stuff.
|
||||
|
||||
# the http server just accepts everything and stores it in the http_requests queue
|
||||
import bottle
|
||||
|
||||
http_requests = Queue()
|
||||
@bottle.route('/<filename:path>')
|
||||
def urlhandler(filename):
|
||||
http_requests.put(bottle.request.copy())
|
||||
|
||||
http_thread=threading.Thread(target=bottle.run, kwargs=dict(host='0.0.0.0', port=config.http_port, reloader=False))
|
||||
http_thread.daemon=True
|
||||
http_thread.start()
|
||||
|
||||
def http_expect_request(path, matches, timeout=60):
|
||||
"""wait until a specific path and paraters are request on the http server. ignores all other requests"""
|
||||
|
||||
start_time=time.time()
|
||||
|
||||
logging.getLogger("HTTP").info("Waiting for http request on path {path}, with values {matches}".format(path=path, matches=matches))
|
||||
|
||||
# check http results
|
||||
while time.time()-start_time<timeout:
|
||||
while http_requests.full():
|
||||
request=http_requests.pop()
|
||||
|
||||
if request.path == path:
|
||||
ok=True
|
||||
for match in matches.items():
|
||||
if not match[0] in request.params or request.params[match[0]]!=match[1]:
|
||||
ok=False
|
||||
if ok:
|
||||
return(request)
|
||||
time.sleep(1)
|
||||
|
||||
raise(Exception("Timeout while expecting http message"))
|
||||
|
||||
+14
-19
@@ -3,32 +3,27 @@
|
||||
from esptest import *
|
||||
|
||||
#node0 has 2x ds18b20
|
||||
#values are send to domoticz via http
|
||||
#values are send to domoticz via mqtt
|
||||
|
||||
|
||||
# mock.when("GET /test").reply(
|
||||
# '{"account": "10000", "outstanding": "10.00"}',
|
||||
# status=200,
|
||||
# times=FOREVER)
|
||||
|
||||
mock.reply("kutje")
|
||||
print(mock.pretend_url)
|
||||
|
||||
import time
|
||||
time.sleep(100)
|
||||
|
||||
espeasy[0].controller_domoticz_mqtt(index=1, controllerip=config.mqtt_broker)
|
||||
### config mqtt and the 2 devices
|
||||
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)
|
||||
|
||||
#wait for request
|
||||
temp1=http_expect_request("/json.html", { 'idx': 1417 }, timeout=10)
|
||||
temp2=http_expect_request("/json.html", { 'idx': 1418 }, timeout=10)
|
||||
|
||||
# check mqtt results
|
||||
if not ( float(temp1.params['svalue'])>0 and float(temp1.params['svalue'])<40 and float(temp2.params['svalue'])>0 and float(temp2.params['svalue'])<40):
|
||||
raise(Exception("Wrong results"))
|
||||
|
||||
|
||||
### reconfig for mqtt and expect results
|
||||
espeasy[0].controller_domoticz_mqtt(index=1, controllerip=config.mqtt_broker)
|
||||
temp1=mqtt_expect_json("domoticz/in", { 'idx': 1417 }, timeout=10)
|
||||
temp2=mqtt_expect_json("domoticz/in", { 'idx': 1418 }, timeout=10)
|
||||
|
||||
if float(temp1['svalue'])>0 and float(temp1['svalue'])<40 and float(temp2['svalue'])>0 and float(temp2['svalue'])<40:
|
||||
|
||||
#FIXME:
|
||||
log.info("passed")
|
||||
else:
|
||||
raise(Exception("Test failed"))
|
||||
if not ( float(temp1['svalue'])>0 and float(temp1['svalue'])<40 and float(temp2['svalue'])>0 and float(temp2['svalue'])<40):
|
||||
raise(Exception("Wrong results"))
|
||||
|
||||
Reference in New Issue
Block a user