miio.integrations.lumi.gateway.gateway module

Xiaomi Gateway implementation using Miio protecol.

class miio.integrations.lumi.gateway.gateway.Gateway(ip: str | None = None, token: str | None = None, start_id: int = 0, debug: int = 0, lazy_discover: bool = True, timeout: int | None = None, *, model: str | None = None, push_server=None)[source]

Bases: Device

Main class representing the Xiaomi Gateway.

Use the given property getters to access specific functionalities such as alarm (for alarm controls) or light (for lights).

Commands whose functionality or parameters are unknown, feel free to implement! * toggle_device * toggle_plug * remove_all_bind * list_bind [0] * bind_page * bind * remove_bind

  • self.get_prop(“used_for_public”) # Return the ‘used_for_public’ status, return value: [0] or [1], probably this has to do with developer mode.

  • self.set_prop(“used_for_public”, state) # Set the ‘used_for_public’ state, value: 0 or 1, probably this has to do with developer mode.

  • welcome

  • set_curtain_level

  • get_corridor_on_time

  • set_corridor_light [“off”]

  • get_corridor_light -> “on”

  • set_default_sound

  • set_doorbell_push, get_doorbell_push [“off”]

  • set_doorbell_volume [100], get_doorbell_volume

  • set_gateway_volume, get_gateway_volume

  • set_clock_volume

  • set_clock

  • get_sys_data

  • update_neighbor_token [{“did”:x, “token”:x, “ip”:x}]

## property getters * ctrl_device_prop * get_device_prop_exp [[sid, list, of, properties]]

## scene * get_lumi_bind [“scene”, <page number>] for rooms/devices

actions() DescriptorCollection[ActionDescriptor]

Return device actions.

call_action(name: str, params=None)

Call action by name.

change_setting(name: str, params=None)

Change setting value.

clock()[source]

Alarm clock.

async close()[source]

Cleanup all subscribed events and registered callbacks.

configure_wifi(ssid, password, uid=0, extra_params=None)

Configure the wifi settings.

descriptors() DescriptorCollection[Descriptor]

Return a collection containing all descriptors for the device.

discover_devices()[source]

Discovers SubDevices and returns a list of the discovered devices.

enable_telnet()[source]

Enable root telnet acces to the operating system, use login “admin” or “app”, no password.

gateway_push_callback(action: str, params: str)[source]

Callback from the push server regarding the gateway itself.

get_developer_key()[source]

Return the developer API key.

classmethod get_device_group()
get_devices_from_dict(device_dict)[source]

Get SubDevices from a dict containing at least “mac”, “did”, “parent_id” and “model”.

This dict can be obtained with the micloud package: https://github.com/squachen/micloud

get_illumination()[source]

Get illumination.

In lux?

get_prop(property)[source]

Get the value of a property for given sid.

get_prop_exp(properties)[source]

Get the value of a bunch of properties for given sid.

get_properties(properties, *, property_getter='get_prop', max_properties=None)

Request properties in slices based on given max_properties.

This is necessary as some devices have limitation on how many properties can be queried at once.

If max_properties is None, all properties are requested at once.

Parameters:
  • properties (list) – List of properties to query from the device.

  • max_properties (int) – Number of properties that can be requested at once.

Returns:

List of property values.

info(*, skip_cache=False) DeviceInfo

Get (and cache) miIO protocol information from the device.

This includes information about connected wlan network, and hardware and software versions.

Parameters:

bool (skip_cache) – Skip the cache

match_type_id(type_id, sid)[source]

Match the type_id to obtain the model_info.

match_zigbee_model(zigbee_model, sid)[source]

Match the zigbee_model to obtain the model_info.

push_callback(source_device: str, action: str, params: str)[source]

Callback from the push server.

raw_command(command, parameters)

Send a raw command to the device. This is mostly useful when trying out commands which are not implemented by a given device instance.

Parameters:
  • command (str) – Command to send

  • parameters (dict) – Parameters to send

register_callback(id: str, callback: Callable[[str, str], None])[source]

Register a external callback function for updates of this subdevice.

remove_callback(id: str)[source]

Remove a external callback using its id.

send(command: str, parameters: Any | None = None, retry_count: int | None = None, *, extra_parameters=None) Any

Send a command to the device.

Basic format of the request: {“id”: 1234, “method”: command, “parameters”: parameters}

extra_parameters allows passing elements to the top-level of the request. This is necessary for some devices, such as gateway devices, which expect the sub-device identifier to be on the top-level.

Parameters:
  • command (str) – Command to send

  • parameters (dict) – Parameters to send

  • retry_count (int) – How many times to retry on error

  • extra_parameters (dict) – Extra top-level parameters

  • model (str) – Force model to avoid autodetection

send_handshake()

Send initial handshake to the device.

sensors() DescriptorCollection[PropertyDescriptor]

Return read-only properties.

set_developer_key(key)[source]

Set the developer API key.

set_prop(property, value)[source]

Set the device property.

settings() DescriptorCollection[PropertyDescriptor]

Return settable properties.

setup_device(dev_info, model_info)[source]

Setup a device using the SubDeviceInfo and model_info.

status() DeviceStatus

Return device status.

supports_miot() bool

Return True if the device supports miot commands.

This requests a single property (siid=1, piid=1) and returns True on success.

timezone()[source]

Get current timezone.

update(url: str, md5: str)

Start an OTA update.

update_progress() int

Return current update progress [0-100].

update_state()

Return current update state.

property alarm: Alarm

Return alarm control interface.

property device_id: int

Return the device id (did).

property devices

Return a dict of the already discovered devices.

property light: Light

Return light control interface.

property mac

Return the mac address of the gateway.

property model: str

Return device model.

property radio: Radio

Return radio control interface.

property raw_id: int

Return the last used protocol sequence id.

retry_count = 3
property subdevice_model_map

Return the subdevice model map.

supported_models = ['lumi.gateway.v3', 'lumi.gateway.mieu01', 'lumi.gateway.mgl03', 'lumi.gateway.aqhm01', 'lumi.acpartner.v1', 'lumi.acpartner.v2', 'lumi.acpartner.v3']
timeout = 5
token: str | None
property zigbee: Zigbee

Return zigbee control interface.