Skip to content

Fix lumi.gateway.mitw01 gateway mappings - #2871

Open
choucheyu wants to merge 2 commits into
al-one:masterfrom
choucheyu:fix/lumi-mitw01-gateway
Open

Fix lumi.gateway.mitw01 gateway mappings#2871
choucheyu wants to merge 2 commits into
al-one:masterfrom
choucheyu:fix/lumi-mitw01-gateway

Conversation

@choucheyu

Copy link
Copy Markdown

Summary

  • Add lumi.gateway.mitw01 (Taiwan Mi Control Hub) miio2miot mappings for light on/off, brightness, color, illumination, guard/alarm, volume, doorbell, and night-light properties.
  • Add extended MIOT spec entries for the hub's missing light brightness/color, illumination sensor, and legacy gateway properties.
  • Allow miio2miot set_template output to opt into raw dict params so legacy set_device_prop calls can send { "sid": "lumi.0", ... } without being wrapped in a list.
  • Keep the miio props cache in sync when callbacks receive raw dict params.

Testing

  • python3 -m py_compile custom_components/xiaomi_miot/core/miio2miot.py custom_components/xiaomi_miot/core/miio2miot_specs.py
  • Parsed custom_components/xiaomi_miot/core/miot_specs_extend.json and asserted lumi.gateway.mitw01 contains light, illumination, and legacy gateway services.
  • Imported miio2miot_specs.py directly and smoke-tested the new set_callback_via_param_index(..., key=...) path with raw dict params.
  • Tested equivalent local patch on a real lumi.gateway.mitw01 hub: en_alarm_light changed via Home Assistant number.set_value, direct local get_device_prop read back the changed value, then restored; alarm_time_len was tested the same way and restored.

Notes

For this gateway, alarm_time_len and en_alarm_light are legacy miio device props. The working write form is:

{"method": "set_device_prop", "params": {"sid": "lumi.0", "alarm_time_len": 30}}

Wrapping that dict in a list returns a params error, so this PR adds raw_params support for these mappings.

Add local miio2miot mappings for the Taiwan Mi Control Hub light, illumination, guard/alarm, volume, doorbell, and night-light properties. Support raw dict miio params so set_device_prop can update alarm_time_len and en_alarm_light.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for the Taiwan Mi Control Hub (lumi.gateway.mitw01) by extending the MIOT specifications and mapping its properties. It also introduces a raw_params flag to handle raw parameter payloads and updates set_callback_via_param_index to support dictionary parameters. The feedback suggests adding a defensive type check in set_callback_via_param_index to ensure params is a list or tuple before checking its length, preventing potential TypeError crashes when raw_params is used.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +11 to +15
elif len(params) > index:
value = params[index]
if key and isinstance(value, dict):
value = value.get(key)
props[prop] = value

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If raw_params is enabled, params can potentially be None or a non-sequence type (e.g., if the template returns null for the params key). In such cases, calling len(params) will raise a TypeError: object of type 'NoneType' has no len(). Defensively checking if params is an instance of list or tuple before checking its length prevents potential runtime crashes.

Suggested change
elif len(params) > index:
value = params[index]
if key and isinstance(value, dict):
value = value.get(key)
props[prop] = value
elif isinstance(params, (list, tuple)) and len(params) > index:
value = params[index]
if key and isinstance(value, dict):
value = value.get(key)
props[prop] = value

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed in bc64930 by checking for list/tuple before len(params).

Defensively handle non-sequence params in set_callback_via_param_index when raw_params templates are used.
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

Successfully merging this pull request may close these issues.

1 participant