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

Converter cannot work in the "giot.switch.v83ksm" well #1478

Open
DragonsCgithub opened this issue Oct 28, 2024 · 12 comments
Open

Converter cannot work in the "giot.switch.v83ksm" well #1478

DragonsCgithub opened this issue Oct 28, 2024 · 12 comments
Assignees
Labels
enhancement New feature or request

Comments

@DragonsCgithub
Copy link

I have been using Gateway3 integration all the time, and it has always worked very well.

However, recently I added a new wall switch, and the new switch is not supported in Gateway3 integration.

giot.switch.v83ksm

After I tried to read the wiki and create a new xiaomi_gateway3.py file in the same-level directory as configuration.yaml to write my own Converter, but no matter how many times I restarted my Home Assistant, nothing changed.
image

There is still only one Mesh entity for the switch in the integration.
iShot_2024-10-28_15 43 45

Have I missed something? Thanks for your reply.

The following is my xiaomi_gateway3.py:

from custom_components.xiaomi_gateway3.core.devices import *

DEVICES = [{
    20448: ["GranwinIoT", "Mesh Smart Triple Wall Switch", "giot.switch.v83ksm"],
    "spec": [
        # 开关设置
        BaseConv("左键", "switch", mi="2.p.1"),
        BaseConv("中键", "switch", mi="3.p.1"),
        BaseConv("右键", "switch", mi="4.p.1"),
        # 开关模式设置
        MapConv("左键开关模式", "select", mi="2.p.2", map={
            0: "普通开关", 
            1: "无线开关", 
            2: "快速断通", 
            3: "点动开关", 
            4: "普通+无线"
        }),
        MapConv("中键开关模式", "select", mi="3.p.2", map={
            0: "普通开关", 
            1: "无线开关", 
            2: "快速断通", 
            3: "点动开关", 
            4: "普通+无线"
        }),
        MapConv("右键开关模式", "select", mi="4.p.2", map={
            0: "普通开关", 
            1: "无线开关", 
            2: "快速断通", 
            3: "点动开关", 
            4: "普通+无线"
        }),
        # 灯光设置
        MapConv("普通开关模式灯光", "select", mi="16.p.1", map={
            0: "跟随", 
            1: "相反", 
            2: "常灭", 
            3: "常亮"
        }),
        MapConv("非普通开关模式灯光", "select", mi="16.p.2", map={
            0: "跟随", 
            1: "相反", 
            2: "常灭", 
            3: "常亮"
        }),
        BoolConv("背光开关", "switch", mi="22.p.1"),
    ]
}] + DEVICES
@AlexxIT AlexxIT added the question Further information is requested label Oct 28, 2024
@AlexxIT
Copy link
Owner

AlexxIT commented Oct 28, 2024

Looks okay. Did you reboot Hass?

@DragonsCgithub
Copy link
Author

Looks okay. Did you reboot Hass?

yes sure. I have tried to reload the Gateway3 integration and reboot Home Assistant, but every time I open the device details, I am always disappointed.😔

@AlexxIT
Copy link
Owner

AlexxIT commented Oct 28, 2024

You can add your changes to target file directly. You importing it in your code.

@DragonsCgithub
Copy link
Author

You can add your changes to target file directly. You importing it in your code.

I am sorry. What is the "target file"?

@DragonsCgithub
Copy link
Author

I noticed the 'import' at the beginning of the file. Do I need to install relevant Python libraries to implement Converter?

@DragonsCgithub
Copy link
Author

I tried to use Converter to customize the switch giot.switch.v52ksm in my hand.

As a result, it still doesn't work.

It seems that the xiaomi_gateway3.py file is not executed by Home Assistant?

@AlexxIT
Copy link
Owner

AlexxIT commented Oct 28, 2024

This file https://github.com/AlexxIT/XiaomiGateway3/blob/master/custom_components/xiaomi_gateway3/core/devices.py

xiaomi_gateway3.py should be executed. You can check logs for any errors about this.

@DragonsCgithub
Copy link
Author

This file https://github.com/AlexxIT/XiaomiGateway3/blob/master/custom_components/xiaomi_gateway3/core/devices.py

xiaomi_gateway3.py should be executed. You can check logs for any errors about this.

I just tried adding a custom Converter in /homeassistant/custom_components/xiaomi_gateway3/core/converters/devices.py.

After rebooting, my switch finally displays normally. 🥹

I don't know if the file you mentioned refers to modifying this local file.

(Sorry, I am a Github novice and I am still learning to use Github.)

@DragonsCgithub
Copy link
Author

image

@DragonsCgithub
Copy link
Author

Oh! I have found the root of all problems.

My integration version is 3.3.3 (I don't know why the integration has not been checked for updates).

However, I used the new version method of from custom_components.xiaomi_gateway3.core.devices import * to write the Converter.

That's why my xiaomi_gateway3.py didn't work.

Now I have reinstalled to the latest version of the integration and written xiaomi_gateway3.py as above. Everything works as expected!

Thank you, AlexxIT! 😀

@AlexxIT
Copy link
Owner

AlexxIT commented Oct 28, 2024

If you write English version for converter - I can add it to all users.

@DragonsCgithub
Copy link
Author

If you write English version for converter - I can add it to all users.

Very willingly. In addition to the 3-Switch version in my hand, I have also added a Converter to other version switches of this series.

from custom_components.xiaomi_gateway3.core.devices import *

DEVICES = [
    {
        20446: ["GranwinIoT", "Mesh Smart One-Button Switch", "giot.switch.v81ksm"],
        "spec": [
            # Switch
            BaseConv("Switch ", "switch", mi="2.p.1"),
            # Switch Mode
            MapConv("Left Switch Mode;", "select", mi="2.p.2", map={
                0: "Normal Switch", 
                1: "Wireless Switch", 
                2: "Flex Switch", 
                3: "Inching Switch", 
                4: "Normal + Wireless Switch"
            }),
            # Backlight
            MapConv("Normal Mode LED", "select", mi="16.p.1", map={
                0: "Follow Switch Status", 
                1: "Opposite To The Switch State", 
                2: "Often Out State", 
                3: "Normally On State"
            }),
            MapConv("Special Mode LED", "select", mi="16.p.2", map={
                0: "Follow Switch Status", 
                1: "Opposite To The Switch State", 
                2: "Often Out State", 
                3: "Normally On State"
            }),
            BaseConv("Backlight", "switch", mi="22.p.1"),
            # Wireless Mode Action
            BaseConv("action", "sensor"),
            ConstConv("action", mi="12.e.1", value=BUTTON_SINGLE),
            ConstConv("action", mi="12.e.2", value=BUTTON_DOUBLE),
            ConstConv("action", mi="12.e.3", value=BUTTON_HOLD),
        ],
    },
    {
        20447: ["GranwinIoT", "Mesh Smart Two-Button Switch", "giot.switch.v82ksm"],
        "spec": [
            # Switch
            BaseConv("Left Switch ", "switch", mi="2.p.1"),
            BaseConv("Right Switch", "switch", mi="3.p.1"),
            # Switch Mode
            MapConv("Left Switch Mode;", "select", mi="2.p.2", map={
                0: "Normal Switch", 
                1: "Wireless Switch", 
                2: "Flex Switch", 
                3: "Inching Switch", 
                4: "Normal + Wireless Switch"
            }),
            MapConv("Right Switch Mode", "select", mi="3.p.2", map={
                0: "Normal Switch", 
                1: "Wireless Switch", 
                2: "Flex Switch", 
                3: "Inching Switch", 
                4: "Normal + Wireless Switch"
            }),
            # Backlight
            MapConv("Normal Mode LED", "select", mi="16.p.1", map={
                0: "Follow Switch Status", 
                1: "Opposite To The Switch State", 
                2: "Often Out State", 
                3: "Normally On State"
            }),
            MapConv("Special Mode LED", "select", mi="16.p.2", map={
                0: "Follow Switch Status", 
                1: "Opposite To The Switch State", 
                2: "Often Out State", 
                3: "Normally On State"
            }),
            BaseConv("Backlight", "switch", mi="22.p.1"),
            # Wireless Mode Action
            BaseConv("action", "sensor"),
            ConstConv("action", mi="12.e.1", value=BUTTON_SINGLE),
            ConstConv("action", mi="12.e.2", value=BUTTON_DOUBLE),
            ConstConv("action", mi="12.e.3", value=BUTTON_HOLD),
            ConstConv("action", mi="13.e.1", value=BUTTON_SINGLE),
            ConstConv("action", mi="13.e.2", value=BUTTON_DOUBLE),
            ConstConv("action", mi="13.e.3", value=BUTTON_HOLD),
        ],
    },
    {
        20448: ["GranwinIoT", "Mesh Smart Three-Button Switch", "giot.switch.v83ksm"],
        "spec": [
            # Switch
            BaseConv("Left Switch ", "switch", mi="2.p.1"),
            BaseConv("Middle Switch", "switch", mi="3.p.1"),
            BaseConv("Right Switch", "switch", mi="4.p.1"),
            # Switch Mode
            MapConv("Left Switch Mode;", "select", mi="2.p.2", map={
                0: "Normal Switch", 
                1: "Wireless Switch", 
                2: "Flex Switch", 
                3: "Inching Switch", 
                4: "Normal + Wireless Switch"
            }),
            MapConv("Middle Switch Mode", "select", mi="3.p.2", map={
                0: "Normal Switch", 
                1: "Wireless Switch", 
                2: "Flex Switch", 
                3: "Inching Switch", 
                4: "Normal + Wireless Switch"
            }),
            MapConv("Right Switch Mode", "select", mi="4.p.2", map={
                0: "Normal Switch", 
                1: "Wireless Switch", 
                2: "Flex Switch", 
                3: "Inching Switch", 
                4: "Normal + Wireless Switch"
            }),
            # Backlight
            MapConv("Normal Mode LED", "select", mi="16.p.1", map={
                0: "Follow Switch Status", 
                1: "Opposite To The Switch State", 
                2: "Often Out State", 
                3: "Normally On State"
            }),
            MapConv("Special Mode LED", "select", mi="16.p.2", map={
                0: "Follow Switch Status", 
                1: "Opposite To The Switch State", 
                2: "Often Out State", 
                3: "Normally On State"
            }),
            BaseConv("Backlight", "switch", mi="22.p.1"),
            # Wireless Mode Action
            BaseConv("action", "sensor"),
            ConstConv("action", mi="12.e.1", value=BUTTON_SINGLE),
            ConstConv("action", mi="12.e.2", value=BUTTON_DOUBLE),
            ConstConv("action", mi="12.e.3", value=BUTTON_HOLD),
            ConstConv("action", mi="13.e.1", value=BUTTON_SINGLE),
            ConstConv("action", mi="13.e.2", value=BUTTON_DOUBLE),
            ConstConv("action", mi="13.e.3", value=BUTTON_HOLD),
            ConstConv("action", mi="14.e.1", value=BUTTON_SINGLE),
            ConstConv("action", mi="14.e.2", value=BUTTON_DOUBLE),
            ConstConv("action", mi="14.e.3", value=BUTTON_HOLD),
        ],
    }
]+ DEVICES

@AlexxIT AlexxIT added enhancement New feature or request and removed question Further information is requested labels Oct 29, 2024
@AlexxIT AlexxIT self-assigned this Oct 29, 2024
@AlexxIT AlexxIT reopened this Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants