Comments (10)
I would be willing to take this up, do you have an example string you are currently running the regex against so I can write a test?
from senseme.
That's a good question. I can see where the three are, but as for the string, I don't think I have an example of that at the moment. Do you have a device to run it on? If so, you could run a few commands and log the output (might have to add logging for that) to see them.
Tests are good, I've been meaning to add unit tests for some time!
If you don't have a device, I can get back to you in a couple of days with some strings.
from senseme.
I don't have a device myself, but can get started on the code changes I would intend to make and just insert whatever test strings you get back to me with into the test. Since you don't have a test framework yet for this project am I good implementing in pytest or would you prefer the built in unittest? I can do it in either.
from senseme.
I have been meaning to try pytest. Briefly looking at the docs for it I think that will be fine.
There isn't a linter config, but I am using black's autoformatting. (https://github.com/ambv/black)
from senseme.
Sorry about the delay on the test strings!
Here is a bunch!
>>> f = discover()[0]
DEBUG:senseme.senseme:Sending broadcast.
DEBUG:senseme.senseme:Listening...
INFO:senseme.senseme:Received a message
DEBUG:senseme.senseme:time_to_wait exceeded or devices_to_find met
>>> f
SenseMe(name='Living Room Fan', ip='192.168.1.50', model='FAN,HAIKU', series='HSERIES', mac='20:F8:5E:D8:A2:74')
>>> f.speed
INFO:senseme.senseme:Status: (Living Room Fan;FAN;SPD;ACTUAL;7)
INFO:senseme.senseme:(Living Room Fan;FAN;SPD;ACTUAL;7)
DEBUG:senseme.senseme:7
7
>>> f.brightness
INFO:senseme.senseme:Status: (Living Room Fan;LIGHT;LEVEL;ACTUAL;0)
INFO:senseme.senseme:(Living Room Fan;LIGHT;LEVEL;ACTUAL;0)
0
>>> f.light_toggle()
INFO:senseme.senseme:Status: (Living Room Fan;LIGHT;PWR;OFF)
INFO:senseme.senseme:(Living Room Fan;LIGHT;PWR;OFF)
>>> f.whoosh()
DEBUG:root:Ran function
INFO:senseme.senseme:Status: (Living Room Fan;DEVICE;BEEPER;ON)
INFO:senseme.senseme:(Living Room Fan;DEVICE;BEEPER;ON)
INFO:senseme.senseme:Status: (Living Room Fan;DEVICE;INDICATORS;ON)
INFO:senseme.senseme:(Living Room Fan;DEVICE;INDICATORS;ON)
INFO:senseme.senseme:Status: (Living Room Fan;DEVICE;LIGHT;PRESENT)
INFO:senseme.senseme:(Living Room Fan;DEVICE;LIGHT;PRESENT)
INFO:senseme.senseme:Status: (Living Room Fan;DEVICE;SERVER;PRODUCTION)
INFO:senseme.senseme:(Living Room Fan;DEVICE;SERVER;PRODUCTION)
INFO:senseme.senseme:Status: (Living Room Fan;ERRORLOG;ENTRIES;NUM;10)
INFO:senseme.senseme:(Living Room Fan;ERRORLOG;ENTRIES;NUM;10)
INFO:senseme.senseme:Status: (Living Room Fan;ERRORLOG;ENTRIES;MAX;10)
INFO:senseme.senseme:(Living Room Fan;ERRORLOG;ENTRIES;MAX;10)
INFO:senseme.senseme:Status: (Living Room Fan;FAN;AUTO;ON)
INFO:senseme.senseme:(Living Room Fan;FAN;AUTO;ON)
INFO:senseme.senseme:Status: (Living Room Fan;FAN;DIR;FWD)
INFO:senseme.senseme:(Living Room Fan;FAN;DIR;FWD)
INFO:senseme.senseme:Status: (Living Room Fan;FAN;PWR;ON)
INFO:senseme.senseme:(Living Room Fan;FAN;PWR;ON)
INFO:senseme.senseme:Status: (Living Room Fan;FAN;SPD;ACTUAL;7)
INFO:senseme.senseme:(Living Room Fan;FAN;SPD;ACTUAL;7)
INFO:senseme.senseme:Status: (Living Room Fan;FAN;SPD;MAX;7)
INFO:senseme.senseme:(Living Room Fan;FAN;SPD;MAX;7)
INFO:senseme.senseme:Status: (Living Room Fan;FAN;SPD;MIN;1)
INFO:senseme.senseme:(Living Room Fan;FAN;SPD;MIN;1)
INFO:senseme.senseme:Status: (Living Room Fan;FAN;BOOKENDS;1;7)
INFO:senseme.senseme:(Living Room Fan;FAN;BOOKENDS;1;7)
INFO:senseme.senseme:Status: (Living Room Fan;FAN;TIMER;CURR;0)
INFO:senseme.senseme:(Living Room Fan;FAN;TIMER;CURR;0)
INFO:senseme.senseme:Status: (Living Room Fan;FAN;TIMER;MAX;7)
INFO:senseme.senseme:(Living Room Fan;FAN;TIMER;MAX;7)
INFO:senseme.senseme:Status: (Living Room Fan;FAN;TIMER;MIN;1)
INFO:senseme.senseme:(Living Room Fan;FAN;TIMER;MIN;1)
INFO:senseme.senseme:Status: (Living Room Fan;FAN;WHOOSH;STATUS;OFF)
INFO:senseme.senseme:(Living Room Fan;FAN;WHOOSH;STATUS;OFF)
INFO:senseme.senseme:Status: (Living Room Fan;FW;NAME;FW000007)
INFO:senseme.senseme:(Living Room Fan;FW;NAME;FW000007)
INFO:senseme.senseme:Status: (Living Room Fan;FW;FW000007;2.5.0)
INFO:senseme.senseme:(Living Room Fan;FW;FW000007;2.5.0)
INFO:senseme.senseme:Status: (Living Room Fan;GROUP;LIST;Living Room)
INFO:senseme.senseme:(Living Room Fan;GROUP;LIST;Living Room)
INFO:senseme.senseme:Status: (Living Room Fan;GROUP;ROOM;TYPE;6)
INFO:senseme.senseme:(Living Room Fan;GROUP;ROOM;TYPE;6)
INFO:senseme.senseme:Status: (Living Room Fan;LEARN;MAXSPEED;7)
INFO:senseme.senseme:(Living Room Fan;LEARN;MAXSPEED;7)
INFO:senseme.senseme:Status: (Living Room Fan;LEARN;MINSPEED;0)
INFO:senseme.senseme:(Living Room Fan;LEARN;MINSPEED;0)
INFO:senseme.senseme:Status: (Living Room Fan;LEARN;ZEROTEMP;2000)
INFO:senseme.senseme:(Living Room Fan;LEARN;ZEROTEMP;2000)
INFO:senseme.senseme:Status: (Living Room Fan;LIGHT;AUTO;ON)
INFO:senseme.senseme:(Living Room Fan;LIGHT;AUTO;ON)
INFO:senseme.senseme:Status: (Living Room Fan;LIGHT;LEVEL;ACTUAL;0)
INFO:senseme.senseme:(Living Room Fan;LIGHT;LEVEL;ACTUAL;0)
INFO:senseme.senseme:Status: (Living Room Fan;LIGHT;BOOKENDS;1;16)
INFO:senseme.senseme:(Living Room Fan;LIGHT;BOOKENDS;1;16)
INFO:senseme.senseme:Status: (Living Room Fan;LIGHT;LEVEL;MAX;16)
INFO:senseme.senseme:(Living Room Fan;LIGHT;LEVEL;MAX;16)
INFO:senseme.senseme:Status: (Living Room Fan;LIGHT;LEVEL;MIN;1)
INFO:senseme.senseme:(Living Room Fan;LIGHT;LEVEL;MIN;1)
INFO:senseme.senseme:Status: (Living Room Fan;LIGHT;PWR;OFF)
INFO:senseme.senseme:(Living Room Fan;LIGHT;PWR;OFF)
INFO:senseme.senseme:Status: (Living Room Fan;LIGHT;BOOKENDS;1;16)
INFO:senseme.senseme:(Living Room Fan;LIGHT;BOOKENDS;1;16)
INFO:senseme.senseme:Status: (Living Room Fan;NAME;VALUE;Living Room Fan)
INFO:senseme.senseme:(Living Room Fan;NAME;VALUE;Living Room Fan)
INFO:senseme.senseme:Status: (Living Room Fan;NW;AP;STATUS;OFF)
INFO:senseme.senseme:(Living Room Fan;NW;AP;STATUS;OFF)
INFO:senseme.senseme:Status: (Living Room Fan;NW;DHCP;OFF)
INFO:senseme.senseme:(Living Room Fan;NW;DHCP;OFF)
INFO:senseme.senseme:Status: (Living Room Fan;NW;PARAMS;ACTUAL;192.168.1.50;255.255.255.0;192.168.1.1)
INFO:senseme.senseme:(Living Room Fan;NW;PARAMS;ACTUAL;192.168.1.50;255.255.255.0;192.168.1.1)
INFO:senseme.senseme:Status: (Living Room Fan;NW;SSID;sendratan)
INFO:senseme.senseme:(Living Room Fan;NW;SSID;sendratan)
INFO:senseme.senseme:Status: (Living Room Fan;NW;TOKEN;90000459-db50-42f2-96d2-74739961c961)
INFO:senseme.senseme:(Living Room Fan;NW;TOKEN;90000459-db50-42f2-96d2-74739961c961)
INFO:senseme.senseme:Status: (Living Room Fan;SCHEDULE;CAP;MAX EVENTS,29)
INFO:senseme.senseme:(Living Room Fan;SCHEDULE;CAP;MAX EVENTS,29)
INFO:senseme.senseme:Status: (Living Room Fan;SCHEDULE;EVENT;LIST;NONE)
INFO:senseme.senseme:(Living Room Fan;SCHEDULE;EVENT;LIST;NONE)
INFO:senseme.senseme:Status: (Living Room Fan;SLEEP;EVENT;OFF;LIGHT,LEVEL,12)
INFO:senseme.senseme:(Living Room Fan;SLEEP;EVENT;OFF;LIGHT,LEVEL,12)
INFO:senseme.senseme:Status: (Living Room Fan;SLEEP;EVENT;ON)
INFO:senseme.senseme:(Living Room Fan;SLEEP;EVENT;ON)
INFO:senseme.senseme:Status: (Living Room Fan;SLEEP;STATE;OFF)
INFO:senseme.senseme:(Living Room Fan;SLEEP;STATE;OFF)
INFO:senseme.senseme:Status: (Living Room Fan;SMARTMODE;ACTUAL;OFF)
INFO:senseme.senseme:(Living Room Fan;SMARTMODE;ACTUAL;OFF)
INFO:senseme.senseme:Status: (Living Room Fan;SMARTMODE;STATE;OFF)
INFO:senseme.senseme:(Living Room Fan;SMARTMODE;STATE;OFF)
INFO:senseme.senseme:Status: (Living Room Fan;SMARTSLEEP;IDEALTEMP;2111)
INFO:senseme.senseme:(Living Room Fan;SMARTSLEEP;IDEALTEMP;2111)
INFO:senseme.senseme:Status: (Living Room Fan;SMARTSLEEP;MAXSPEED;7)
INFO:senseme.senseme:(Living Room Fan;SMARTSLEEP;MAXSPEED;7)
INFO:senseme.senseme:Status: (Living Room Fan;SMARTSLEEP;MINSPEED;0)
INFO:senseme.senseme:(Living Room Fan;SMARTSLEEP;MINSPEED;0)
INFO:senseme.senseme:Status: (Living Room Fan;SNSROCC;TIMEOUT;CURR;3600000)
INFO:senseme.senseme:(Living Room Fan;SNSROCC;TIMEOUT;CURR;3600000)
INFO:senseme.senseme:Status: (Living Room Fan;SNSROCC;TIMEOUT;MAX;86400000)
INFO:senseme.senseme:(Living Room Fan;SNSROCC;TIMEOUT;MAX;86400000)
INFO:senseme.senseme:Status: (Living Room Fan;SNSROCC;TIMEOUT;MIN;60000)
INFO:senseme.senseme:(Living Room Fan;SNSROCC;TIMEOUT;MIN;60000)
INFO:senseme.senseme:Status: (Living Room Fan;TIME;VALUE;2018-10-10T23:20:19Z)
INFO:senseme.senseme:(Living Room Fan;TIME;VALUE;2018-10-10T23:20:19Z)
INFO:senseme.senseme:Status: (Living Room Fan;WINTERMODE;HEIGHT;213)
INFO:senseme.senseme:(Living Room Fan;WINTERMODE;HEIGHT;213)
INFO:senseme.senseme:Status: (Living Room Fan;WINTERMODE;STATE;OFF)
INFO:senseme.senseme:(Living Room Fan;WINTERMODE;STATE;OFF)
INFO:senseme.senseme:Socket Timed Out
from senseme.
Apologize for the misunderstanding, do you have an example of the raw messages that are received on the buffer? The regex currently does a match for messages that include DEVICE;ID which makes me wonder if other types of messages are received.
So this line here:
message = s.recvfrom(1024)
Maybe modify to add something that logs that message like this:
LOGGER.info("Received a message")
LOGGER.debug(f"Message: {message}")
from senseme.
Looking back at the code, you're right in that the examples I gave above aren't sufficient. The ones I gave are status updates, which don't have the same content as some of the other responses. The lines above are output from what is now line 1293, the _query
method, on the master branch (which was updated last night).
The lines I think you are looking for is the discover and discover_single (which are sadly duplicate of one another.) I'll get back to you with output from those.
from senseme.
Yeah looking to just get what the socket sees. So that s.recvfrom(1024)
in discover being assigned to message
is what will ultimately be passed to the new function to be decoded and parsed. I did see the master update which I'll have to pull in and fix conflicts before I make another push on the pull request. Depending on what those messages look like regex may still be the best way to parse it but this will at least refactor out the duplicate code.
from senseme.
Here is a working refactored function example. Not sure if this is more readable than regex, let me know your thoughts:
def decode_discovery(message: Tuple[bytes, Tuple[str, str]]) -> Tuple:
""" Takes a message in the return format of socket.recvfrom and returns decoded SenseMe discovery information """
message_decoded = message[0].decode("utf-8")
message_items = message_decoded.strip('()').split(';')
name = message_items[0]
mac = message_items[3]
model, series = message_items[4].split(',')
ip = message[1][0]
return name, mac, model, series, ip
from senseme.
Sorry to not get back to you, as I said in the PR comments.
The code looks good, I'll have to compare it to a string from the fan. It will probably be next week when I can get them to you.
from senseme.
Related Issues (20)
- discover_single_device doesn't use known details
- setup.py and distribution HOT 1
- unit tests
- Where to begin? Would like to get running in Flask. HOT 17
- Flask example: Leads to occasional 500 + Traceback
- Flask example: expand to support all library methods
- _get_all_request() is not handling two sections in one line correctly. HOT 2
- Update cache when properties are changed HOT 2
- Whoosh property does not work.
- Background monitor will stop running when _get_all_bare causes an exception. HOT 2
- Break get_all_request into separate, more testable, function
- doesn't work with python 2.7? HOT 4
- Fan returns ON/OFF rather than an integer on Brightness
- Issues due to not waiting for responses
- Trouble Discovering Fans HOT 1
- 2022 firmware changes network protocol HOT 2
- Discovery function has a lot of code re-use
- _query method has odd returns HOT 1
- Consider fan, light, light+fan classes
- Update run.py, wa.py, and readme to work with overhaul
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from senseme.