For tests, how can I run only certain tests (to check if what we modify still works at the service level)?
Because the other tests are not modified, so they must work ^^
For tests, how can I run only certain tests (to check if what we modify still works at the service level)?
Because the other tests are not modified, so they must work ^^
Great, thanks! This is a lifesaver… ![]()
The best way is to use .only for your test!
Source:
(@Jacky’s solution works very well too)
Not necessarily true, your code can impact the rest of the functionality ![]()
Yes, I know, but I meant in the sense that when I test, I should first test my service and see if everything is okay afterward ![]()
Okay, I’ll do that then, thanks!
I have an issue, here is the example:
describe('GET /api/v1/service/xiaomi/sensor', () => {
it('should get all sensors', async () => {
await authenticatedRequest
.get('/api/v1/service/xiaomi/sensor')
.expect('Content-Type', /json/)
.expect(200)
.then((res) => {
expect(res.body).should.be.a('array');
});
});
});
I get this result =>
1) GET /api/v1/service/xiaomi/sensor
should get all sensors:
Error: expected 200 "OK", got 404 "Not Found"
at Test._assertStatus (node_modules/supertest/lib/test.js:268:12)
at Test._assertFunction (node_modules/supertest/lib/test.js:283:11)
at Test.assert (node_modules/supertest/lib/test.js:173:18)
at Server.localAssert (node_modules/supertest/lib/test.js:131:12)
at emitCloseNT (net.js:1618:8)
at process._tickCallback (internal/process/next_tick.js:63:19)
Is it because I’m running the test on the service, possibly the reason? And therefore the server is not launched?
@Jacky
Thanks a lot, I’ll check all that out.
I’m not the best at testing, but the Xiaomi module is a good example to improve on a bit of everything ![]()
When you hope to have enough code coverage but in fact you have 89% ![]()
No change!! I just upgraded to 91.33 ![]()
Not at all!!!
I actually tested a function lol
In the tests, the service controllers are not launched on the server (since otherwise, the services would have to be launched in reality)
For now, the best solution I have found is to unit test each controller, you can check the other services to see how I did it!
Yes, that’s what I did! I instantiate the controller and test each route.
I’m good on coverage but not satisfied… Because basically, I have a small part of the code that allows modifying the sensor value and it’s not tested. The issue is that this element is not present because it needs to be created first, and then we trigger an event with a value to update. So, I don’t know what the best method is to create the element.
You can see that if device is null, it doesn’t go into this.gladys.event.emit. This part is not tested yet.
Normally you are supposed to do unit testing, so you can simulate all cases by injecting different parameters/mocked functions. The « gladys » variable that you pass must have all functions mocked with fake!
Oh yes!!!
Why didn’t I think of that earlier… I just need to create a Gladys that sends me an object! Thanks ![]()
I’ll keep you updated on the service’s progress.
Currently, I manage these devices:
Apparently, there seems to be an issue with Windows installations. On Mac and Linux, it seems to work.
Regarding the services page, here is the Xiaomi service:
Then, when you go into the service, you have access to two pages:
Here are screenshots of the two pages:
Feel free to give me feedback.
If you want to test:
git checkout xiaomiThen you need to follow these commands: A privacy-first, open-source home assistant | Gladys Assistant
Awesome, especially since you don’t have much to hold me accountable for the equipment you have and would like to add! I can add them, I’ll just need you to provide feedback from the gateway and I’ll work from your information ![]()
@damalgos, we tested with @pierre-gilles on his Mac, no problem! My Xiaomi devices are reporting without any issues, opening detector, temperature sensor.
The problem therefore comes from the node on Windows. I’ll look into it a bit, otherwise I’ll check on Linux or in Docker on Syno.
You can install WSL ![]()
Otherwise, yes I saw some info about it not working on Windows… Probably a port opening issue due to the firewall, you should disable everything and test on Windows ![]()
Anyway, I’m glad everything is coming back up without issues. On your side, are the services coming back up quickly? Mine are a bit slow ^^
It was coming back up quickly, yes. For certain equipment, you have to wait for them to talk on the network, of course. And it’s very responsive, for example, when you open/close a door; We were in awe with pierre-gilles! – It’s a change from Zwave where nothing is standardized and there are too many possible settings!
Great if it works well! On my side, it’s the same for the sensors except for the temperature, it’s slow haha
Do you happen to have any other unsupported devices? So I can detect them and add them ![]()
Victory, I finally succeeded on Windows 10!!!
I tried to modify the broadcast, multicast, firewall routes… Nothing!
Finally, I simply added my IP in addMembership, which gives this in the file: xiaomi.listening.js:
async function listening() {
logger.debug('UDP Client listening on ’ + MULTICAST_ADDRESS + « : » + DISCOVERY_PORT);
this.socket.setBroadcast(true)
this.socket.setMulticastTTL(128);
this.socket.addMembership(‹ 224.0.0.50 ›,‹ 192.168.10.70 ›);
const payload = ‹ {« cmd »: « whois »} ›;
this.socket.send(payload, 0, payload.length, DISCOVERY_PORT, MULTICAST_ADDRESS);
I’m getting down to business, I’m going to get my Xiaomis ^^