Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add (unit)tests #43

Open
Cyber1000 opened this issue May 24, 2020 · 12 comments
Open

Add (unit)tests #43

Cyber1000 opened this issue May 24, 2020 · 12 comments

Comments

@Cyber1000
Copy link
Contributor

As there seems to be more refactoring in the near future since to coap-additions (#35) and library split (#34) I think we'll need some tests.

I'm not so deep into python-testing (since python is not my main profession), but I've looked into testing in coapthon and they seem to do it with coveralls which integrates nicely in travis (https://github.com/Tanganelli/CoAPthon3/blob/master/.travis.yml) and classes like unittest-class from the standard python library (https://github.com/Tanganelli/CoAPthon3/blob/master/coverage_test_advanced.py)

There might be other testing-frameworks though: https://realpython.com/python-testing/

Any inputs are welcome, I think we don't need to get overcomplicated, some decent (10-20) tests would cover most of our cases.

I would put some time into this.

@Cyber1000
Copy link
Contributor Author

Didn't have much time last week, but got some tests running (PR follows today/tomorrow).
To have better testing-data I would need some typical datasets for http and plain_coap:


for http I would need (@rgerganov please help):

  • name of your device
  • airctrl --ipaddr [ip] --protocol http -d (-d cause the json-data is relevant to me)
    • you may zero out the ProductId and DeviceId, since they are not relevant for testing
  • airctrl --ipaddr [ip] --protocol http --aqil 25 -d (does a set really respond with the same values you get from get_values?)
  • airctrl --ipaddr [ip] --protocol http --wifi
  • airctrl --ipaddr [ip] --protocol http --firmware
  • airctrl --ipaddr [ip] --protocol http --filters

@Cyber1000
Copy link
Contributor Author

for plain_coap I would need (@GeorgeSG please help) :

  • name of your device
  • airctrl --ipaddr [ip] --protocol plain_coap -d (-d cause the json-data is relevant to me)
    • you may zero out the ProductId and DeviceId, since they are not relevant for testing
  • Is there a payload of client.post right here, when you are executing airctrl --ipaddr [ip] --protocol plain_coap --aqil 25?
    client.post(path, json.dumps(payload))
    • with my encrypted coap I'm getting {"status":"success"}back
    • You may change the line to something like that:
response = client.post(path, json.dumps(payload)) 
print(response.payload)

@GeorgeSG
Copy link
Contributor

GeorgeSG commented Jun 1, 2020

for plain_coap I would need (@GeorgeSG please help) :

I'm pretty sure my device uses HTTP, not CoAP, it's AC2729/10.

@Cyber1000
Copy link
Contributor Author

@GeorgeSG ok I think I got confused by this:

My purifier uses 0.2.1 and it works.

And 0.2.1 seems to use either coap or http not depending on this version number, I think I mixed that ...
Thanks for the clarification

Someone here who runs the current master of airctrl with --protocol plain_coap?
for example @shexbeer?

@rgerganov
Copy link
Owner

$ airctrl --ipaddr 192.168.88.251 --protocol http -d
{'aqil': 100,
 'aqit': 0,
 'cl': False,
 'ddp': '1',
 'dt': 0,
 'dtrs': 0,
 'err': 0,
 'func': 'P',
 'iaql': 2,
 'mode': 'M',
 'om': '1',
 'pm25': 8,
 'pwr': '1',
 'rddp': '1',
 'rh': 30,
 'rhset': 60,
 'temp': 24,
 'uil': '1',
 'wl': 100}

[pwr]   Power: ON
[pm25]  PM25: 8
[rh]    Humidity: 30
[rhset] Target humidity: 60
[iaql]  Allergen index: 2
[temp]  Temperature: 24
[func]  Function: Purification
[mode]  Mode: manual
[om]    Fan speed: 1
[aqil]  Light brightness: 100
[uil]   Buttons light: ON
[ddp]   Used index: PM2.5
[wl]    Water level: 100
[cl]    Child lock: False

$ airctrl --ipaddr 192.168.88.251 --protocol http --aqil 25 -d 
{'aqil': 25,
 'aqit': 0,
 'cl': False,
 'ddp': '1',
 'dt': 0,
 'dtrs': 0,
 'err': 0,
 'func': 'P',
 'iaql': 1,
 'mode': 'M',
 'om': '1',
 'pm25': 4,
 'pwr': '1',
 'rddp': '1',
 'rh': 30,
 'rhset': 60,
 'temp': 24,
 'uil': '1',
 'wl': 100}

[pwr]   Power: ON
[pm25]  PM25: 4
[rh]    Humidity: 30
[rhset] Target humidity: 60
[iaql]  Allergen index: 1
[temp]  Temperature: 24
[func]  Function: Purification
[mode]  Mode: manual
[om]    Fan speed: 1
[aqil]  Light brightness: 25
[uil]   Buttons light: ON
[ddp]   Used index: PM2.5
[wl]    Water level: 100
[cl]    Child lock: False

$ airctrl --ipaddr 192.168.88.251 --protocol http --wifi      
{'cppid': 'e8c1000000000000',
 'dhcp': True,
 'gateway': '192.168.88.1',
 'ipaddress': '192.168.88.251',
 'macaddress': 'e8:c1:00:00:00:00',
 'netmask': '255.255.255.0',
 'password': '',
 'protection': 'wpa-2',
 'ssid': 'My SSID'}

$ airctrl --ipaddr 192.168.88.251 --protocol http --firmware
{'mandatory': False,
 'name': 'AC2729_10',
 'progress': 0,
 'state': 'idle',
 'statusmsg': '',
 'upgrade': '',
 'version': '8'}

$ airctrl --ipaddr 192.168.88.251 --protocol http --filters 
Pre-filter and Wick: clean in 33 hours
Wick filter: replace in 1142 hours
Active carbon filter: replace in 1142 hours
HEPA filter: replace in 1142 hours

@spider7611
Copy link

spider7611 commented Jun 4, 2020

my model Id: AC3858/50 protocol coap version.
will do what you need
airctrl --ipaddr 192.168.1.102 --protocol coap --pwr 1

[name] Name: Living Room
[type] Type: AC3858
[modelid] ModelId: AC3858/50
[swversion] Version: Ms4102
[language] language: EN
[om] Fan speed: 1
[pwr] Power: ON
[cl] Child lock: False
[aqil] Light brightness: 0
[uil] Buttons light: OFF
[uaset] uaset: A
[mode] Mode: AG
[pm25] PM25: 3
[iaql] Allergen index: 1
[aqit] Air quality notification threshold: 10
[tvoc] tvoc: 1
[ddp] Used index: PM2.5
[rddp] rddp: 1
[fltt1] HEPA filter type: NanoProtect Filter Series 3 (FY2422)
[fltt2] Active carbon filter type: none
[fltsts0] Pre-filter and Wick: clean in 155 hours
[fltsts1] HEPA filter: replace in 4560 hours
[fltsts2] Active carbon filter: replace in 65535 hours
[filna] filna: AC3036
[filid] filid: AC3036....
[ota] Over the air updates: no
[Runtime] Runtime: 0.96 hours
[WifiVersion] WifiVersion: AWS_Philips_AIR@53
[ProductId] ProductId: .....
[DeviceId] DeviceId: ....
[StatusType] StatusType: localcontrol
[ConnectType] ConnectType: Localcontrol

@spider7611
Copy link

spider7611 commented Jun 4, 2020

airctrl --ipaddr 192.168.1.102 --protocol plain_coap -d

Raw status:
{'ConnectType': 'Localcontrol',
 'DeviceId': '.......................',
 'ProductId': '.......................',
 'Runtime': 611108689,
 'StatusType': 'localcontrol',
 'WifiVersion': 'AWS_Philips_AIR@53',
 'aqil': 100,
 'aqit': 10,
 'cl': False,
 'ddp': '1',
 'err': 0,
 'filid': 'AC30360123456789012',
 'filna': 'AC3036',
 'fltsts0': 154,
 'fltsts1': 4560,
 'fltsts2': 65535,
 'fltt1': 'A3',
 'fltt2': 'none',
 'iaql': 7,
 'language': 'EN',
 'mode': 'AG',
 'modelid': 'AC3858/50',
 'name': 'Living Room',
 'om': '0',
 'ota': 'no',
 'pm25': 40,
 'pwr': '0',
 'rddp': '1',
 'swversion': 'Ms4102',
 'tvoc': 1,
 'type': 'AC3858',
 'uaset': 'A',
 'uil': '1'}
[name]                        Name: Living Room
[type]                        Type: AC3858
[modelid]                     ModelId: AC3858/50
[swversion]                   Version: Ms4102
[language]                    language: EN
[om]                          Fan speed: 0
[pwr]                         Power: OFF
[cl]                          Child lock: False
[aqil]                        Light brightness: 100
[uil]                         Buttons light: ON
[uaset]                       uaset: A
[mode]                        Mode: AG
[pm25]                        PM25: 40
[iaql]                        Allergen index: 7
[aqit]                        Air quality notification threshold: 10
[tvoc]                        tvoc: 1
[ddp]                         Used index: PM2.5
[rddp]                        rddp: 1
[fltt1]                       HEPA filter type: NanoProtect Filter Series 3 (FY2422)
[fltt2]                       Active carbon filter type: none
[fltsts0]                     Pre-filter and Wick: clean in 154 hours
[fltsts1]                     HEPA filter: replace in 4560 hours
[fltsts2]                     Active carbon filter: replace in 65535 hours
[filna]                       filna: AC3036
[filid]                       filid: AC30360123456789012
[ota]                         Over the air updates: no
[Runtime]                     Runtime: 1.75 hours
[WifiVersion]                 WifiVersion: AWS_Philips_AIR@53
[ProductId]                   ProductId: ..............
[DeviceId]                    DeviceId: ..............
[StatusType]                  StatusType: localcontrol
[ConnectType]                 ConnectType: Localcontrol
2020-06-04 16:25:36,867 - Thread-1   - coapthon.client.coap - DEBUG - Exiting receiver Thread due to request

@spider7611
Copy link

After this modification:

py-air-control/pyairctrl/plain_coap_client.py

Line 71 in a7f5214

 client.post(path, json.dumps(payload)) 
with my encrypted coap I'm getting {"status":"success"}back
You may change the line to something like that:
response = client.post(path, json.dumps(payload)) 
print(response.payload)

I get this error, maybe I do something wrong:

airctrl --ipaddr 192.168.1.102 --protocol plain_coap --aqil 25
Traceback (most recent call last):
  File "/home/spider2/.local/bin/airctrl", line 11, in <module>
    load_entry_point('py-air-control==2.0.0', 'console_scripts', 'airctrl')()
  File "/home/spider2/.local/lib/python3.6/site-packages/pyairctrl/airctrl.py", line 467, in main
    c.set_values(values, debug=args.debug)
  File "/home/spider2/.local/lib/python3.6/site-packages/pyairctrl/airctrl.py", line 359, in set_values
    self._client.set_values(values, debug)
  File "/home/spider2/.local/lib/python3.6/site-packages/pyairctrl/plain_coap_client.py", line 216, in set_values
    self._set(key, values[key])
  File "/home/spider2/.local/lib/python3.6/site-packages/pyairctrl/plain_coap_client.py", line 69, in _set
    self._send_hello_sequence(client)
  File "/home/spider2/.local/lib/python3.6/site-packages/pyairctrl/plain_coap_client.py", line 84, in _send_hello_sequence
    self._send_over_socket(self.server, packet)
  File "/home/spider2/.local/lib/python3.6/site-packages/pyairctrl/plain_coap_client.py", line 38, in _send_over_socket
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, protocol)
  File "/usr/lib/python3.6/socket.py", line 144, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 13] Permission denied

@Cyber1000
Copy link
Contributor Author

Thanks for your contributions, my time was limited this week, but I'm nearly done.
@spider7611
I was just wondering about your first post on this task:

airctrl --ipaddr 192.168.1.102 --protocol coap

And then you go on with:

airctrl --ipaddr 192.168.1.102 --protocol plain_coap

Does your device support coap and plain_coap, so both commands work or is the first command a typo?


Your problem with the permission error:

airctrl --ipaddr 192.168.1.102 --protocol plain_coap --aqil 25

  • Did you try this out with another user or on another computer? I would expect that also the other command would fail (or neither of the commands fails), cause the _send_hello_sequence is called from the get too.
  • I would try to call this with a sudo or a root user (though I don't know exactly why your are getting a permission error on your computer):
sudo airctrl --ipaddr 192.168.1.102 --protocol plain_coap --aqil 25

@Cyber1000
Copy link
Contributor Author

Cyber1000 commented Jun 4, 2020

@spider7611
I've digged a little deeper:
Did you really call:

airctrl --ipaddr 192.168.1.102 --protocol plain_coap -d

and not

airctrl --ipaddr 192.168.1.102 --protocol coap -d

?

The following is a coap only output:

[fltt1]                       HEPA filter type: NanoProtect Filter Series 3 (FY2422)

At least the "NanoProtect Filter Series 3" part wouldn't get translated this way, there would be no output at all for this line with plain_coap. At least code (beginning with

def _dump_status(self, status, debug=False):
) and my tests say so

@spider7611
Copy link

I'm confused. Maybe changed the plain_coap and coap. Will try again later, sorry.

@Cyber1000
Copy link
Contributor Author

No problem I was confused too :-)
I'll create a PR for now, cause it is overall ready.
I've used something similar in plan_caop as I used in coap for now, but we can fix this very fast.

@Cyber1000 Cyber1000 mentioned this issue Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants