diff --git a/src/lmwsip/__init__.py b/src/lmwsip/__init__.py index d6c9545..55de6de 100644 --- a/src/lmwsip/__init__.py +++ b/src/lmwsip/__init__.py @@ -12,7 +12,7 @@ from datetime import datetime, timedelta from dateutil import tz """ Version info changed by git hook """ -__version__ = '0.9.7' +__version__ = '0.9.8' class LmwSip: """Class to connect to the LMW Standard Interface prototcol (sip) @@ -904,6 +904,26 @@ Returns a single string value or None # return(value) + def stat(self, process, location, parameter): + """Get the last measurement or the start en end of forecasts. + +Parameters: + process: + location: + parameter: +The default returns the last value. + +Example: + lmw.stat("WN", "HOEK", "H10") + +Returns a single string value or None +""" + stat="%s %s,%s,%s,STAT\r" % (process, self.meetnet, location, parameter) + d = self.sendrecv(stat) + if d[0] != '!': + raise LmwCmdWarn(stat, d) + return (d[2:-1]) + def _lmwdelta_(self, window): h = 24*window.days + window.seconds // 3600 m = (window.seconds % 3600)//60 diff --git a/tests/main.py b/tests/main.py index 1983f51..8302a3c 100755 --- a/tests/main.py +++ b/tests/main.py @@ -85,6 +85,14 @@ class lmwsipTest(unittest.TestCase): self.login() self.assertEqual(type(self.sip.value("WN", "DUMMY", "H10")), str) + def test_stat_wn(self): + self.login() + self.assertEqual(type(self.sip.stat("WN", "DUMMY", "H10")), str) + + def test_stat_vw(self): + self.login() + self.assertEqual(type(self.sip.stat("VW", "DUMMY", "H10V")), str) + def test_value1min(self): self.login() self.assertEqual(type(self.sip.value("WN", "DUMMY", "H1")), str) diff --git a/tests/stubSipServer.py b/tests/stubSipServer.py index 75d345c..544622e 100755 --- a/tests/stubSipServer.py +++ b/tests/stubSipServer.py @@ -13,6 +13,12 @@ Implements the following commands: CMD> TI LMW ANS< ! 20-JAN-01 00:00:00 + CMD> WN LMW,DUMMY,H10,STAT + ANS< ! 20-JAN-01 00:00 + + CMD> VW LMW,DUMMY,H10V,STAT + ANS< ! 20-JAN-01 00:00;20-JAN-01 01:00 + CMD> WN LMW,DUMMY,H10,+HH:MM,yyyy-mm-dd,HH:MM,DATA ANS< ! 1/10,;2/10;.... @@ -48,7 +54,7 @@ logoutcount=0 class sipProtocol(socketserver.BaseRequestHandler): def match(self, m): - return(self.data.find(m.encode()) == 0) + return(self.data.find(m.encode()) != -1) def send(self, a): a = "%s\r" % a @@ -86,12 +92,19 @@ class sipProtocol(socketserver.BaseRequestHandler): global logoutcount self.read() while self.data: - if self.match("LI USER,PASS"): + if self.match("CLOSE"): + self.request.close() + elif self.match("LI USER,PASS"): self.send("!") elif self.match("TI LMW"): self.send("! 20-JAN-01 00:00:00") elif self.match("WN LMW,DUMMY,H10,"): - self.meting(10) + if self.match("STAT"): + self.send("! 20-JAN-01 00:00") + else: + self.meting(10) + elif self.match("VW LMW,DUMMY,H10V,STAT"): + self.send("! 20-JAN-01 00:00;20-JAN-01 01:00") elif self.match("WN LMW,DUMMY,H1,"): self.meting(1) elif self.match("LOGOUTCOUNT"): @@ -99,8 +112,6 @@ class sipProtocol(socketserver.BaseRequestHandler): elif self.match("LO"): logoutcount+=1 self.send("!") - elif self.match("CLOSE"): - self.request.close() else: self.send("? ERROR") self.read()