7 Commits

Author SHA1 Message Date
2cead40a74 Correctie schrijf test
All checks were successful
build / build (push) Successful in 1m8s
2025-03-15 21:12:38 +01:00
ee8ca45a59 Version update for stat command
All checks were successful
build / build (push) Successful in 1m22s
2024-09-21 10:54:02 +02:00
af04830dfb Update python docstrins 2024-09-21 10:53:23 +02:00
a8e70e793f Run tox paralel to speedup tests 2024-09-21 10:50:04 +02:00
0c07dcfd66 Added stat command to find last measurement/forecast times 2024-09-21 10:48:34 +02:00
ef778c3e0a BUG FIX: cmdWrite fix
All checks were successful
build / build (push) Successful in 1m34s
2024-04-24 16:07:58 +02:00
49eb1522b6 Versie update: cmdWrite fix
Some checks failed
build / build (push) Has been cancelled
2024-04-24 16:06:15 +02:00
5 changed files with 58 additions and 14 deletions

View File

@@ -8,4 +8,4 @@ VERSION=$(grep version setup.cfg | sed 's/.*= *//')
sed -i "s/^__version__ = .*/__version__ = '${VERSION}'/" src/lmwsip/__init__.py sed -i "s/^__version__ = .*/__version__ = '${VERSION}'/" src/lmwsip/__init__.py
git add src/lmwsip/__init__.py git add src/lmwsip/__init__.py
tox tox -p

View File

@@ -1,6 +1,6 @@
[metadata] [metadata]
name = lmwsip name = lmwsip
version = 0.9.7 version = 0.9.9
author = Marcel Nijenhof author = Marcel Nijenhof
author_email = pypi@marceln.org author_email = pypi@marceln.org
description = Interface for the lmw sip protocol description = Interface for the lmw sip protocol

View File

@@ -12,7 +12,7 @@ from datetime import datetime, timedelta
from dateutil import tz from dateutil import tz
""" Version info changed by git hook """ """ Version info changed by git hook """
__version__ = '0.9.7' __version__ = '0.9.9'
class LmwSip: class LmwSip:
"""Class to connect to the LMW Standard Interface prototcol (sip) """Class to connect to the LMW Standard Interface prototcol (sip)
@@ -835,14 +835,14 @@ Returns:
data: Values to be writen (e.g. 33/10;35/10). data: Values to be writen (e.g. 33/10;35/10).
Example: Example:
lmw.cmd("WNT", "HOEK", "H10", "+00:20", "13-08-2018", "16:00", "33/10;35/10") lmw.cmdWrite("WNT", "HOEK", "H10", "+00:20", "13-08-2018", "16:00", "33/10;35/10")
Returns: Returns:
The LMW answer string The LMW answer string
""" """
cmdstr=process + " " + self.meetnet + "," + location + "," + \ cmdstr=process + " " + self.meetnet + "," + location + "," + \
parameter + "," + time_delta + "," + day + "," + \ parameter + "," + time_delta + "," + day + "," + \
time_of_day + values + "\r" time_of_day + "," + values + "\r"
d = self.sendrecv(cmdstr) d = self.sendrecv(cmdstr)
if (d[0] != '!'): if (d[0] != '!'):
raise LmwCmdWarn(cmdstr, d) raise LmwCmdWarn(cmdstr, d)
@@ -862,7 +862,7 @@ Parameters:
The default returns the last value string including quality. The default returns the last value string including quality.
Example: Example:
lmw.data_string("WN", "HOEK", "H10") lmw.valueStr("WN", "HOEK", "H10")
Returns a single string value with quality Returns a single string value with quality
""" """
@@ -889,7 +889,7 @@ Parameters:
The default returns the last value. The default returns the last value.
Example: Example:
lmw.data_string("WN", "HOEK", "H10") lmw.value("WN", "HOEK", "H10")
Returns a single string value or None Returns a single string value or None
""" """
@@ -904,6 +904,26 @@ Returns a single string value or None
# #
return(value) return(value)
def stat(self, process, location, parameter):
"""Get the last measurement or the start en end of forecasts.
Parameters:
process: <WN|VW|AS>
location: <lmw location (e.g. HOEK)>
parameter: <lmw parameter (e.g. H10)>
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): def _lmwdelta_(self, window):
h = 24*window.days + window.seconds // 3600 h = 24*window.days + window.seconds // 3600
m = (window.seconds % 3600)//60 m = (window.seconds % 3600)//60
@@ -938,7 +958,7 @@ The times should have correct timezone information. Otherwise local timezone
is assumed. Timezones are converted to 'GMT+1' for the sip commands. is assumed. Timezones are converted to 'GMT+1' for the sip commands.
Example: Example:
lmw.data_string("WN", "HOEK", "H10", ...) lmw.timeSerie("WN", "HOEK", "H10", ...)
Returns a LmwtimeSerie object Returns a LmwtimeSerie object

View File

@@ -79,12 +79,20 @@ class lmwsipTest(unittest.TestCase):
def test_cmdWrite(self): def test_cmdWrite(self):
self.login() self.login()
self.assertEqual(type(self.sip.cmdWrite("WN", "DUMMY", "H10", "+00:20", "2020-01-01", "00:00", "35/10;33/10")), str) self.assertEqual(type(self.sip.cmdWrite("WNT", "DUMMY", "H10", "+00:20", "2020-01-01", "00:00", "35/10;33/10")), str)
def test_value(self): def test_value(self):
self.login() self.login()
self.assertEqual(type(self.sip.value("WN", "DUMMY", "H10")), str) 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): def test_value1min(self):
self.login() self.login()
self.assertEqual(type(self.sip.value("WN", "DUMMY", "H1")), str) self.assertEqual(type(self.sip.value("WN", "DUMMY", "H1")), str)

View File

@@ -13,6 +13,15 @@ Implements the following commands:
CMD> TI LMW CMD> TI LMW
ANS< ! 20-JAN-01 00:00:00 ANS< ! 20-JAN-01 00:00:00
CMD> WNT LMW,DUMMY,H1,+HH:MM,yyyy-mm-dd,HH:MM,NN/NN;NN/NN
ANS< ! 1/10,;2/10;....
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 CMD> WN LMW,DUMMY,H10,+HH:MM,yyyy-mm-dd,HH:MM,DATA
ANS< ! 1/10,;2/10;.... ANS< ! 1/10,;2/10;....
@@ -48,7 +57,7 @@ logoutcount=0
class sipProtocol(socketserver.BaseRequestHandler): class sipProtocol(socketserver.BaseRequestHandler):
def match(self, m): def match(self, m):
return(self.data.find(m.encode()) == 0) return(self.data.find(m.encode()) != -1)
def send(self, a): def send(self, a):
a = "%s\r" % a a = "%s\r" % a
@@ -86,12 +95,21 @@ class sipProtocol(socketserver.BaseRequestHandler):
global logoutcount global logoutcount
self.read() self.read()
while self.data: while self.data:
if self.match("LI USER,PASS"): if self.match("CLOSE"):
self.request.close()
elif self.match("LI USER,PASS"):
self.send("!") self.send("!")
elif self.match("TI LMW"): elif self.match("TI LMW"):
self.send("! 20-JAN-01 00:00:00") self.send("! 20-JAN-01 00:00:00")
elif self.match("WNT LMW,DUMMY,H10,"):
self.send("!")
elif self.match("WN LMW,DUMMY,H10,"): elif self.match("WN LMW,DUMMY,H10,"):
if self.match("STAT"):
self.send("! 20-JAN-01 00:00")
else:
self.meting(10) 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,"): elif self.match("WN LMW,DUMMY,H1,"):
self.meting(1) self.meting(1)
elif self.match("LOGOUTCOUNT"): elif self.match("LOGOUTCOUNT"):
@@ -99,8 +117,6 @@ class sipProtocol(socketserver.BaseRequestHandler):
elif self.match("LO"): elif self.match("LO"):
logoutcount+=1 logoutcount+=1
self.send("!") self.send("!")
elif self.match("CLOSE"):
self.request.close()
else: else:
self.send("? ERROR") self.send("? ERROR")
self.read() self.read()