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

Error Adding zones/regiosn on Aqara FP1 (RTCZCGQ11LM) #7307

Open
kikecortes6 opened this issue Apr 2, 2024 · 3 comments
Open

Error Adding zones/regiosn on Aqara FP1 (RTCZCGQ11LM) #7307

kikecortes6 opened this issue Apr 2, 2024 · 3 comments
Labels

Comments

@kikecortes6
Copy link
Contributor

kikecortes6 commented Apr 2, 2024

This part of the code always returns 00:00:00:00:ff at the end making impossible to create new zones

this part is the trigger

const sortedZonesWithSets: {[s: number]: [number]} = command.zones

but this part is the problem:

deviceConfig[0] = presence.constants.region_config_cmds.create;

const sortedZonesWithSets: {[s: number]: [number]} = command.zones
.reduce(
(accumulator: {[s: number]: Set}, zone: {x: number, y: number}) => {
if (!accumulator[zone.y]) {
accumulator[zone.y] = new Set();
}

                    accumulator[zone.y].add(zone.x);

                    return accumulator;
                },
                sortedZonesAccumulator,
            );
        const sortedZones = Object.entries(sortedZonesWithSets).reduce((acc, [key, value]) => {
            const numKey = parseInt(key, 10); // Convert string key back to number
            acc[numKey] = Array.from(value);
            return acc;
        }, {} as {[s: number]: number[]});

        const deviceConfig = new Uint8Array(7);

        // Command parameters
        deviceConfig[0] = presence.constants.region_config_cmds.create;
        deviceConfig[1] = command.region_id;
        deviceConfig[6] = presence.constants.region_config_cmd_suffix_upsert;
        // Zones definition
        deviceConfig[2] |= presence.encodeXCellsDefinition(sortedZones['1']);
        deviceConfig[2] |= presence.encodeXCellsDefinition(sortedZones['2']) << 4;
        deviceConfig[3] |= presence.encodeXCellsDefinition(sortedZones['3']);
        deviceConfig[3] |= presence.encodeXCellsDefinition(sortedZones['4']) << 4;
        deviceConfig[4] |= presence.encodeXCellsDefinition(sortedZones['5']);
        deviceConfig[4] |= presence.encodeXCellsDefinition(sortedZones['6']) << 4;
        deviceConfig[5] |= presence.encodeXCellsDefinition(sortedZones['7']);

        log('info', `create region ${command.region_id} ${printNumbersAsHexSequence([...deviceConfig], 2)}`);

        const payload = {
            [presence.constants.region_config_write_attribute]: {
                value: deviceConfig,
                type: presence.constants.region_config_write_attribute_type,
            },
        };

They variable sortedZones returns data, i had test it , the problem with the code is this one:

    deviceConfig[2] |= presence.encodeXCellsDefinition(sortedZones['1']);
    deviceConfig[2] |= presence.encodeXCellsDefinition(sortedZones['2']) << 4;
    deviceConfig[3] |= presence.encodeXCellsDefinition(sortedZones['3']);
    deviceConfig[3] |= presence.encodeXCellsDefinition(sortedZones['4']) << 4;
    deviceConfig[4] |= presence.encodeXCellsDefinition(sortedZones['5']);
    deviceConfig[4] |= presence.encodeXCellsDefinition(sortedZones['6']) << 4;
    deviceConfig[5] |= presence.encodeXCellsDefinition(sortedZones['7']);

fills all these with 0
Screenshot 2024-04-02 at 3 53 24 PM

@kikecortes6 kikecortes6 changed the title Error Adding zones Error Adding zones on Aqara FPQ (RTCZCGQ11LM) Apr 2, 2024
@kikecortes6 kikecortes6 changed the title Error Adding zones on Aqara FPQ (RTCZCGQ11LM) Error Adding zones/regiosn on Aqara FPQ (RTCZCGQ11LM) Apr 4, 2024
@kikecortes6
Copy link
Contributor Author

I think I found the problem is in here

encodeXCellsDefinition: (xCells?: number[]): number => {
, not sure why xCells is trying to use .size property I think is wrong, I think the correct way is to access .length property, if not please let me know why this peace of code uses .size property.

I will like to suggest this modification:
Screenshot 2024-04-07 at 4 31 02 PM

and here is an example of the code running:

code

@kikecortes6 kikecortes6 changed the title Error Adding zones/regiosn on Aqara FPQ (RTCZCGQ11LM) Error Adding zones/regiosn on Aqara FP1 (RTCZCGQ11LM) Apr 7, 2024
@Koenkk
Copy link
Owner

Koenkk commented Apr 8, 2024

Should be length indeed, could you make a pull request?

Copy link
Contributor

github-actions bot commented Oct 6, 2024

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days

@github-actions github-actions bot added the stale label Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants