miio.integrations.chuangmi.remote.chuangmi_ir module

class miio.integrations.chuangmi.remote.chuangmi_ir.ChuangmiIr(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)[source]

Bases: Device

Main class representing Chuangmi IR Remote Controller.

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.

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.

classmethod get_device_group()
get_indicator_led()[source]

Get the indicator led status.

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

learn(key: int = 1)[source]

Learn an infrared command.

Parameters:

key (int) – Storage slot, must be between 1 and 1000000

play(command: str)[source]

Plays a command in one of the supported formats.

play_pronto(pronto: str, repeats: int = 1, length: int = -1)[source]

Play a Pronto Hex encoded IR command. Supports only raw Pronto format, starting with 0000.

Parameters:
  • pronto (str) – Pronto Hex string.

  • repeats (int) – Number of extra signal repeats.

  • length (int) – Length of the command. -1 means not sending the length parameter.

play_raw(command: str, frequency: int = 38400, length: int = -1)[source]

Play a captured command.

Parameters:
  • command (str) – Command to execute

  • frequency (int) – Execution frequency

  • length (int) – Length of the command. -1 means not sending the length parameter.

classmethod pronto_to_raw(pronto: str, repeats: int = 1) Tuple[str, int][source]

Play a Pronto Hex encoded IR command. Supports only raw Pronto format, starting with 0000.

Parameters:
  • pronto (str) – Pronto Hex string.

  • repeats (int) – Number of extra signal repeats.

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

read(key: int = 1)[source]

Read a learned command.

Positive response (chuangmi.ir.v2): {‘key’: ‘1’, ‘code’: ‘Z6WPAasBAAA3BQAA4AwJAEA….AAABAAEBAQAAAQAA==’}

Negative response (chuangmi.ir.v2): {‘error’: {‘code’: -5002, ‘message’: ‘no code for this key’}, ‘id’: 5}

Negative response (chuangmi.ir.v2): {‘error’: {‘code’: -5003, ‘message’: ‘learn timeout’}, ‘id’: 17}

Parameters:

key (int) – Slot to read from

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_indicator_led(indicator_led: bool)[source]

Set the indicator led on/off.

settings() DescriptorCollection[PropertyDescriptor]

Return settable properties.

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.

update(url: str, md5: str)

Start an OTA update.

update_progress() int

Return current update progress [0-100].

update_state()

Return current update state.

PRONTO_RE = re.compile('^([\\da-f]{4}\\s?){3,}([\\da-f]{4})$', re.IGNORECASE)
property device_id: int

Return the device id (did).

property model: str

Return device model.

property raw_id: int

Return the last used protocol sequence id.

retry_count = 3
supported_models = ['chuangmi.ir.v2', 'chuangmi.remote.v2', 'chuangmi.remote.h102a03', 'xiaomi.wifispeaker.l05g']
timeout = 5
token: str | None
class miio.integrations.chuangmi.remote.chuangmi_ir.ProntoPulseAdapter(subcon)[source]

Bases: Adapter

benchmark(sampledata, filename=None)

Measures performance of your construct (its parsing and building runtime), both for the original instance and the compiled instance. Uses timeit module, over at min 1 loop, and at max over 100 millisecond time.

Optionally, results are saved to a text file for later inspection. Otherwise you can print the resulting string to terminal.

Parameters:
  • sampledata – bytes, a valid blob parsable by this construct

  • filename – optional, string, results are saved to that file

Returns:

string containing measurements

build(obj, **contextkw)

Build an object in memory (a bytes object).

Whenever data cannot be written, ConstructError or its derivative is raised. This method is NOT ALLOWED to raise any other exceptions although (1) user-defined lambdas can raise arbitrary exceptions which are propagated (2) external libraries like numpy can raise arbitrary exceptions which are propagated (3) some list and dict lookups can raise IndexError and KeyError which are propagated.

Context entries are passed only as keyword parameters **contextkw.

Parameters:

**contextkw – context entries, usually empty

Returns:

bytes

Raises:

ConstructError – raised for any reason

build_file(obj, filename, **contextkw)

Build an object into a closed binary file. See build().

build_stream(obj, stream, **contextkw)

Build an object directly into a stream. See build().

compile(filename=None)

Transforms a construct into another construct that does same thing (has same parsing and building semantics) but is much faster when parsing. Already compiled instances just compile into itself.

Optionally, partial source code can be saved to a text file. This is meant only to inspect the generated code, not to import it from external scripts.

Returns:

Compiled instance

export_ksy(schemaname='unnamed_schema', filename=None)
parse(data, **contextkw)

Parse an in-memory buffer (often bytes object). Strings, buffers, memoryviews, and other complete buffers can be parsed with this method.

Whenever data cannot be read, ConstructError or its derivative is raised. This method is NOT ALLOWED to raise any other exceptions although (1) user-defined lambdas can raise arbitrary exceptions which are propagated (2) external libraries like numpy can raise arbitrary exceptions which are propagated (3) some list and dict lookups can raise IndexError and KeyError which are propagated.

Context entries are passed only as keyword parameters **contextkw.

Parameters:

**contextkw – context entries, usually empty

Returns:

some value, usually based on bytes read from the stream but sometimes it is computed from nothing or from the context dictionary, sometimes its non-deterministic

Raises:

ConstructError – raised for any reason

parse_file(filename, **contextkw)

Parse a closed binary file. See parse().

parse_stream(stream, **contextkw)

Parse a stream. Files, pipes, sockets, and other streaming sources of data are handled by this method. See parse().

sizeof(**contextkw)

Calculate the size of this object, optionally using a context.

Some constructs have fixed size (like FormatField), some have variable-size and can determine their size given a context entry (like Bytes(this.otherfield1)), and some cannot determine their size (like VarInt).

Whenever size cannot be determined, SizeofError is raised. This method is NOT ALLOWED to raise any other exception, even if eg. context dictionary is missing a key, or subcon propagates ConstructError-derivative exception.

Context entries are passed only as keyword parameters **contextkw.

Parameters:

**contextkw – context entries, usually empty

Returns:

integer if computable, SizeofError otherwise

Raises:

SizeofError – size could not be determined in actual context, or is impossible to be determined