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

Capitalisation of Air Purifier modes #715

Closed
dewi-ny-je opened this issue Jun 3, 2020 · 1 comment
Closed

Capitalisation of Air Purifier modes #715

dewi-ny-je opened this issue Jun 3, 2020 · 1 comment

Comments

@dewi-ny-je
Copy link

dewi-ny-je commented Jun 3, 2020

Issue: in miio/airpurifier.py you define the air purifier modes as:

class OperationMode(enum.Enum):
    # Supported modes of the Air Purifier Pro, 2, V3
    Auto = "auto"
    Silent = "silent"
    Favorite = "favorite"
    # Additional supported modes of the Air Purifier 2 and V3
    Idle = "idle"
    # Additional supported modes of the Air Purifier V3
    Medium = "medium"
    High = "high"
    Strong = "strong"

Home Assistant depends on your library and in https://github.com/home-assistant/core/blob/dev/homeassistant/components/xiaomi_miio/fan.py they define the modes as:

OPERATION_MODES_AIRPURIFIER = ["Auto", "Silent", "Favorite", "Idle"]
OPERATION_MODES_AIRPURIFIER_PRO = ["Auto", "Silent", "Favorite"]
OPERATION_MODES_AIRPURIFIER_PRO_V7 = OPERATION_MODES_AIRPURIFIER_PRO
OPERATION_MODES_AIRPURIFIER_2S = ["Auto", "Silent", "Favorite"]
OPERATION_MODES_AIRPURIFIER_3 = ["Auto", "Silent", "Favorite", "Fan"]
OPERATION_MODES_AIRPURIFIER_V3 = [
    "Auto",
    "Silent",
    "Favorite",
    "Idle",
    "Medium",
    "High",
    "Strong",
]
OPERATION_MODES_AIRFRESH = ["Auto", "Silent", "Interval", "Low", "Middle", "Strong"]

As result, when a script does a string comparison, they don't match due to capitalisation.

I am really no expert coder, so I ask you straightforward: since capitalised it looks nicer, would it make sense to modify your library to introduce capitals? Yes/no and why?

I can submit a pull request (I think that's the name) with the edit, if you pre-approve the idea.

@rytilahti
Copy link
Owner

So, the enum values are the real values the device is reporting, so we cannot change those in this library. After checking the homeassistant's code, the cause for the problem is visible here:
https://github.com/home-assistant/core/blob/dev/homeassistant/components/xiaomi_miio/fan.py#L814 - where it tries to acquire the enum member using the value instead of the key, which is not possible.

The proper way to fix this would be to modify the homeassistant platform to store not just the name but the enums themselves in the _speedlist, and then access either value or name whichever is relevant.

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

2 participants