wappsto / wappsto-python Goto Github PK
View Code? Open in Web Editor NEWPython module for rapid prototyping for wappsto.com
License: Apache License 2.0
Python module for rapid prototyping for wappsto.com
License: Apache License 2.0
Able to set init value of a control state
When the connection to wappsto is lost, all events should be stored to disk. When the is a connection again, it should upload all the stored events.
the item should be added to add_id_to_confirm_list only before sending it, otherwise, it would block sending until sending limit is reached
In the test function 'def get_send_thread_values' the type is checked using number value instead of constant names.
For smaller numbers the json may say:
"min":-3,
"max":3,
"step":1.0e-07,
Hello,
We've tried to activate or update your repository on Depfu and couldn't find any supported dependency files. If we were to guess, we would say that this is not actually a project Depfu supports and has probably been activated by error.
Please note that Depfu currently only searches for your dependency files in the root folder. We do support monorepos and non-root files, but don't auto-detect them. If that's the case with this repo, please send us a quick email with the folder you want Depfu to work on and we'll set it up right away!
Please note that using the "All Repositories" setting doesn't make a lot of sense with Depfu.
Please let us know by sending an email to [email protected].
This is an automated issue by Depfu. You're getting it because someone configured Depfu to automatically update dependencies on this project.
encode in WappstoEncoder and build_json in Instantiator does the same task with minor differences
All the spaces in a string is being removed when saving the json. So the device description is
"'description': 'The Grove - Red LED Button is stable and reliable with 100 000 times long life. With the build-in LED, you can apply it to many interesting projects, it is really useful to use the LED to show the status of the button. We use a high-quality N-Channel MOSFET to control the LED to ensure the high switching speed and low power consumption.'"
but it is being saved like:
'"description":"TheGrove-RedLEDButtonisstableandreliablewith100000timeslonglife.Withthebuild-inLED,youcanapplyittomanyinterestingprojects,itisreallyusefultousetheLEDtoshowthestatusofthebutton.Weuseahigh-qualityN-ChannelMOSFETtocontroltheLEDtoensurethehighswitchingspeedandlowpowerconsumption.".
The last_controlled should be Deprecated and it should use get_data instead.
https://stackoverflow.com/questions/922550/how-to-mark-a-global-as-deprecated-in-python
Add a test to make sure that a DELETE request is handled correctly.
There need to be an option to enable trace for all messages.
When the json looks like this:
{"min":0,"max":1,"step":1,"unit":""}
It is converted into this:
{"min": 0, "max": 1, "step": 1, "unit": null}
It should be:
{"min": 0, "max": 1, "step": 1}
You cannot use ctrl-c or any signal to stop the program while it is connecting to wappsto.
If there is a typo in the name or port it is not possible to stop the program in a nice way.
This should be possible during initialization as well, and handles so everything is close nicely.
If main.py does not set all callbacks wappsto-python must not crash when it tries to call these.
It should write an error instead.
Test cases to cover network, device, value, status callback - and when not set - could be a good diea.
When there are multiple items in the queue, it would be helpful to group all the events together in a single request.
So instead of sending a single json-rpc request, you should send a bulk json-rpc request.
It is basically just adding all the events into an array before sending them.
After there was this error in the logs, the device stop sending any messages to the server. But after a control message from the server to the device, it started sending event again.
ERROR: Error reporting state: TLS/SSL connection has been closed (EOF) (_ssl.c:2337)
INFO: Server Disconnect
INFO: Current status: Reconnecting
INFO: Trying to reconnect in 5 seconds
ERROR: Error reporting state: TLS/SSL connection has been closed (EOF) (_ssl.c:2337)
DEBUG: Update pir value to: 0
INFO: Closing connection...
INFO: Reconnected
INFO: Current status: Connected
INFO: Sending reconnect data
INFO: Current status: Running
INFO: Wappsto Initialization Complete.
In tox.ini remove "test" under ignore and start fixing errors :)
Also change line with to 120 from 80.
When a number value is updated from the user, if the the data should be validated and changed to match the limits and step sizes in the value.
Also make a test for this, to see that the step size is enforced.
Feb 27 08:31:37 SELUXIT rapid-prototype-runner[325]: 2020-02-27 08:31:37,349 - DEBUG: Callback <function network_callback at 0x762322b8> has been set.
Feb 27 08:31:37 SELUXIT rapid-prototype-runner[325]: Traceback (most recent call last):
Feb 27 08:31:37 SELUXIT rapid-prototype-runner[325]: File "main.py", line 196, in
Feb 27 08:31:37 SELUXIT rapid-prototype-runner[325]: service.get_by_id("8cd4c33f-05d0-45da-951d-0d7361e5b220").set_callback(wappsto_8cd4c33f_05d0_45da_951d_0d7361e5b220_callback)
Feb 27 08:31:37 SELUXIT rapid-prototype-runner[325]: File "/usr/lib/python3.7/site-packages/wappsto/init.py", line 129, in get_by_id
Feb 27 08:31:37 SELUXIT rapid-prototype-runner[325]: return self.socket.handlers.get_by_id(id)
Feb 27 08:31:37 SELUXIT rapid-prototype-runner[325]: AttributeError: 'NoneType' object has no attribute 'handlers'
Feb 27 08:31:37 SELUXIT rapid-prototype-runner[325]: Program ERROR with return code: 1
Basic testcase:
load json, connect, initialize data model, send event, receive event, close
numbers are shown in 5E+3 but should be 5000
pending and so on not sent
There needs to be a test for both string and blob value types.
{'name':'', 'data': 7} should be {'data': 7}
Feb 19 15:58:03 PQPI-076802be rapid-prototype-runner[295]: 2020-02-19 15:58:03,765 - ERROR: Value error: b'[{"jsonrpc":"2.0","id":179,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:52.510Z"}
}},{"jsonrpc":"2.0","id":180,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:52.596Z"}}},{"jsonrpc":"2.0","id":181,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:52.646Z"
}}},{"jsonrpc":"2.0","id":182,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:52.763Z"}}},{"jsonrpc":"2.0","id":183,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:52.848Z
"}}},{"jsonrpc":"2.0","id":184,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:52.935Z"}}},{"jsonrpc":"2.0","id":185,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:52.975
Z"}}},{"jsonrpc":"2.0","id":186,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:53.082Z"}}},{"jsonrpc":"2.0","id":187,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:53.16
7Z"}}},{"jsonrpc":"2.0","id":188,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:53.253Z"}}},{"jsonrpc":"2.0","id":189,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:53.2
94Z"}}},{"jsonrpc":"2.0","id":190,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:53.400Z"}}},{"jsonrpc":"2.0","id":191,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:53.
483Z"}}},{"jsonrpc":"2.0","id":192,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:53.569Z"}}},{"jsonrpc":"2.0","id":193,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:53
.611Z"}}},{"jsonrpc":"2.0","id":194,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:53.717Z"}}},{"jsonrpc":"2.0","id":196,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:5
3.731Z"}}},{"jsonrpc":"2.0","id":195,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:53.814Z"}}},{"jsonrpc":"2.0","id":197,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:'
Feb 19 15:58:03 PQPI-076802be rapid-prototype-runner[295]: 2020-02-19 15:58:03,781 - ERROR: Value error: b'57:53.900Z"}}},{"js'
Feb 19 15:58:03 PQPI-076802be rapid-prototype-runner[295]: 2020-02-19 15:58:03,793 - ERROR: Value error: b'onrpc":"2.0","id":198,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:53.941Z"}}},{"
jsonrpc":"2.0","id":199,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:54.047Z"}}},{"jsonrpc":"2.0","id":200,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:54.131Z"}}},{
"jsonrpc":"2.0","id":201,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:54.217Z"}}},{"jsonrpc":"2.0","id":202,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:54.258Z"}}},
{"jsonrpc":"2.0","id":203,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:54.369Z"}}},{"jsonrpc":"2.0","id":204,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:54.452Z"}}}
,{"jsonrpc":"2.0","id":205,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:54.538Z"}}},{"jsonrpc":"2.0","id":206,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:54.578Z"}}
},{"jsonrpc":"2.0","id":207,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:54.686Z"}}},{"jsonrpc":"2.0","id":208,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:54.769Z"}
}},{"jsonrpc":"2.0","id":209,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:54.855Z"}}},{"jsonrpc":"2.0","id":210,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:54.899Z"
}}},{"jsonrpc":"2.0","id":211,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:55.006Z"}}},{"jsonrpc":"2.0","id":212,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:55.089Z
"}}},{"jsonrpc":"2.0","id":213,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:55.175Z"}}},{"jsonrpc":"2.0","id":214,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:55.216
Z"}}},{"jsonrpc":"2.0","id":215,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:55.325Z"}}},{"jsonrpc":"2.0","id":216,"result":{"value":true,"meta":{"server_send_time":"2020-02-19T14:57:55'
Feb 19 15:58:03 PQPI-076802be rapid-prototype-runner[295]: 2020-02-19 15:58:03,806 - ERROR: Value error: b'.409Z"}}},{"jsonrpc'
When connection, the url in the RPC POST message is "/network//device" and it should just be "/network"
{"jsonrpc": "2.0", "method": "POST", "params": {"url": "/network/1b2f5a4c-3b94-46ee-8826-d9096906e6d4/device", "data": {"name": "Truck Portable Air Tuner", "meta": {"id": "00455c1d-6e76-4581-9299-85886a9cca40", "type": "device", "version": "2.0"}, "included": "1", "manufacturer": "Brunsforge", "product": "P-3239", "version": "2.0", "serial": "0391431465-1", "description": "Is like chalk and cheese What do you call cheese that isn't yours? Nacho Cheese; say cheese it is blue sky thinking processed cheese has several technical advantages over traditional cheese but don't you agree? It is no use crying over spilled milk they can also age quite well in ripening cellars where wash, rinse, repeat they can also age quite well in ripening cellars where cut the cheese.", "protocol": "Finsync Tag Controller_protocol", "communication": "always"}}, "id": 2}
We need to test if the trace functionality works for all types of incoming messages.
So if trace is enabled on a message, the module should send a HTTP trace message.
It should be possible to set the initial value of the report states before the first POST message is send to wappsto.
It needs to be possible to change the period and delta of a value, using the json-rpc calls.
If control value exist during connection, read the existing value and call "set" value.
Currently the initialization process do not use the ID of the RPC message sent with the POST request to verify that success/fail is received for the correct message.
If a control/get message is sent form the server during the initialization process, it can disrupt everything.
It should be possible to send a DELETE request from the client to the server.
Feb 27 12:09:57 SELUXIT rapid-prototype-runner[323]: File "main.py", line 208, in
Feb 27 12:09:57 SELUXIT rapid-prototype-runner[323]: service.get_by_id("0d1ad152-f102-4d40-ae29-62e66a12d406").set_callback(wappsto_0d1ad152_f102_4d40_ae29_62e66a12d406_callback)
Feb 27 12:09:57 SELUXIT rapid-prototype-runner[323]: File "/usr/lib/python3.7/site-packages/wappsto/init.py", line 131, in get_by_id
Feb 27 12:09:57 SELUXIT rapid-prototype-runner[323]: return self.handler.get_by_id(id)
Feb 27 12:09:57 SELUXIT rapid-prototype-runner[323]: File "/usr/lib/python3.7/site-packages/wappsto/connection/handlers.py", line 219, in get_by_id
Feb 27 12:09:57 SELUXIT rapid-prototype-runner[323]: if value.control_state.uuid == id:
Feb 27 12:09:57 SELUXIT rapid-prototype-runner[323]: AttributeError: 'NoneType' object has no attribute 'uuid'
Feb 27 12:09:57 SELUXIT rapid-prototype-runner[323]: Program ERROR with return code: 1
Feb 27 12:09:57 SELUXIT rapid-prototype-runner[323]: Updated to Default.
Feb 27 12:09:57 SELUXIT rapid-prototype-runner[323]: Starting Default Script
There should be a limit on the amount of event that will be bulked together to avoid to large messages.
Maybe max 10 messages together in a single bulk.
In the logs I have seen this log message:
DEBUG: Raw Send Json: b'[]'
But it should not be possible to send an empty message.
Replace old code with standard library
We use this function:
def __convert_to_real(self, raw_value):
if self.minimum < 0:
total = abs(self.minimum) + self.maximum
elif self.minimum and self.maximum < 0:
total = abs(self.minimum) - abs(self.maximum)
else:
total = self.maximum - self.minimum
return ((float(raw_value) * total) / 4095) + self.minimum
Where self.minimum is 0, and self.maximum is 100
Input raw value is 1 or 2 as you saw.
The status object/callback are disconnected from the main running thread, and all information may not be updated to the user.
In the main.py file it is difficult to import status and get the correct status object.
A lot of places in the code info is used as log level where it maybe should be debug.
Other places warnings and errors are printed as info, etc.
In the folder test_JSON, the files have uuid as the name. You should just use normal names for them.
send_data.py is a queue item/msg, so it has a very confusing name - as the connection.py have a function called send_data as well.
Rename all the '_cl' variables, because it makes more sense that it is the name of the variable, and then just change the name of the import.
It seams a bit strange with the pbject_instantiation. I think that it should be refactored.
We need better coverage of the code, to make sure that most of the code is tested. It is okay to add some exception handling to coverage ignore.
For each value there is an option to define delta and period.
Here is how we would like these two entries to work:
A refresh (get request) from the server must be sent no matter what period and delta is set to.
period, is a time defined in second that defines how often a value should be updated.
If the code sends multiple updates, these should be blocked (for example a period of 20 minutes will block values being updated every minute.)
When the time for period is triggered Wappsto-python should call a 'refresh' to ensure the value is updated.
delta, is a size that the value must be bigger/smaller than before it should be updated, for example a delta in temperature of 0.5 degree ensure that the temperature must be 0.5 degree varmer or colder before a new measurement is sent - even if the sensor measures every second.
When both delta and period are defined, delta should work as before, but period must ensure that as minimum we still update in the period interval, but only if delta values have not been triggered.
When the first POST message is send, it should be a complete network json, with all devices and values...
The values that are send is now looking like this:
DEBUG: Raw Send Json: b'{"jsonrpc": "2.0", "method": "PUT", "params": {"url": "/network/076802be-e65b-42b6-bcda-76d51e08fed8/device/4b7590d4-f6a8-4f73-9683-0a15b6d97185/value/7436695d-d57f-4fc6-a08a-4eaaeebbedea/state/8a9a5eca-a558-4cc7-935c-554478584ebb", "data": {"meta": {"id": "8a9a5eca-a558-4cc7-935c-554478584ebb", "type": "state", "version": "2.0"}, "type": "Report", "status": "Send", "data": "967.0000000000000", "timestamp": "2020-02-04T13:43:33.327822Z"}}, "id": 764}'
The value should be limited to the step size, so 967 instead of 967.0000000000000
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.