Dev module xiaomi v4

Hello everyone,

I’m currently developing the xiaomi module to integrate it into v4. For now, I want to have the minimum functionality (at this point I can retrieve the devices, including those for temperature and those for humidity).

I have a problem to modify my device on preact.

const xiaomiCapteurTemperature = update(state.xiaomiCapteurTemperature, {
    [index]: {
        features: {
            [value.getAttribute('data-key')]: {
                [field]: {
                    $set: value.value
                }
            }
        }
    }
}

I want to modify the device_feature value of my device. For this, I retrieve index which is the device number (among the list of xiaomi devices), then features for the features attribute (which lists all the features such as temperatures, humidity, …) and then I have data-key which allows me to retrieve the feature number to get the right one. Then I want to modify field which is therefore the ‹ name › column and then I finish by setting the value with the new value.

Why doesn’t it work? (front-end error)

Uncaught ReferenceError: xiaomiCapteurTemperature is not defined

Thanks :slightly_smiling_face:

Could you share a link to the sources? It’s a bit limited here :slight_smile:

Yes, it’s not wrong, it’s a bit complicated to help without the sources :smiley:

Be careful, I have a xiaomi branch, you must stay in it. And the files are in /front/src/routes/integrations/all/xiaomi

Thanks :slight_smile:

And I just realized I’m not on the official repo ^^

No problem, I’ll do everything properly later.

When reading quickly, I would say you have a scope issue.
Your variable is declared either in the if or in the else. Lines 75 and 87.
By line 95, your variable is undefined as it is out of scope of your conditions.

Okay, I’ll check it out! :slight_smile: Thanks

Thanks!!! It works perfectly, what a beginner’s mistake :smiley: Thanks a lot! It works perfectly

However, a small remark, don’t use [value.getAttribute('data-key')]:, that’s not good React practice at all ^^

I would advise you to create sub-components and manage this locally within the components, as I have done in the Z-Wave service for example, example here =>

https://github.com/GladysAssistant/Gladys/blob/master/front/src/routes/integration/all/zwave/node-page/Device.jsx

@pierre-gilles

I actually thought about that :smiley: Thanks ^^ I’m getting used to React, I’m originally on Vue.js, it’s a bit different in some points :slight_smile:

I’ll modify that.

@pierre-gilles

I just opened a PR, a question about the door detectors. How do you handle the fact that the detector can oscillate between 0 and 1? Isn’t that bothersome?

Thanks :slight_smile:

Oscillate between 0 and 1? What do you mean?

Well, normally if the two devices are next to each other they should be 1, but if they change state (at the limit of detectability, it could mess up, right?) Basically, it has trouble detecting them, so it randomly switches from 0 to 1 and potentially quickly.

I might be overcomplicating things ^^

You’re overcomplicating things!

I gave you a full review of your PR so you can improve its quality :slight_smile:

PS: reply to me on the PR, not here

Hey @pierre-gilles,

I made some changes to the xiaomi service code, I’m waiting for your feedback on what to change or not :blush:

Otherwise, I have a question, what is codecov exactly? I didn’t quite understand the principle, I saw that on my PR I have 60% but of what … ^^

This is an indication of code coverage by tests.
In short, you have 60% of your code covered by tests.

Oh thanks so I need to improve my tests ^^

Indeed, the checks are failing because your coverage is low. You need to write tests for each function!

I’ll reply on the PR.

@pierre-gilles I wanted to know what you think about this. I have therefore merged the different possible Xiaomi sensors. However, when we take the example of the gateway or even the Xiaomi lamps, I think it is still important to separate these elements, don’t you think?

I agree, we can have multiple tabs, then we can group all the sensors together in my opinion.

However, these views are only the « what the service sees » views, but we need another view that groups all the devices « Gladys side » like on the Z-Wave service.

OK, I’m making the changes and trying to set up the tests.