miio.push_server.server module

class miio.push_server.server.PushServer(device_ip=None)[source]

Bases: object

Async UDP push server acting as a fake miio device to handle event notifications from other devices.

Assuming you already have a miio_device class initialized:

# First create the push server
push_server = PushServer(miio_device.ip)
# Then start the server
await push_server.start()
# Register the miio device to the server and specify a callback function to receive events for this device
# The callback function schould have the form of "def callback_func(source_device, action, params):"
push_server.register_miio_device(miio_device, callback_func)
# create a EventInfo object with the information about the event you which to subscribe to (information taken from packet captures of automations in the mi home app)
event_info = EventInfo(
# Send a message to the miio_device to subscribe for the event to receive messages on the push_server
await push_server.subscribe_event(miio_device, event_info)
# Now you will see the callback function beeing called whenever the event occurs
await asyncio.sleep(30)
# When done stop the push_server, this will send messages to all subscribed miio_devices to unsubscribe all events
await push_server.stop()
add_method(name: str, response: Union[Dict, Callable])[source]

Add a method to server.

The response can be either a callable or a dictionary to send back as response.

register_miio_device(device: Device, callback: Callable[[str, str, str], None])[source]

Register a miio device to this push server.

async start()[source]

Start Miio push server.

async stop()[source]

Stop Miio push server.

async subscribe_event(device: Device, event_info: EventInfo) Optional[str][source]

Subscribe to a event such that the device will start pushing data for that event.

async unregister_miio_device(device: Device)[source]

Unregister a miio device from this push server.

async unsubscribe_event(device: Device, event_id: str)[source]

Unsubscribe from a event by id.

property methods

Return a dict of implemented methods.

property server_id

Return the ID of the fake device beeing emulated.

property server_ip

Return the IP of the device running this server.

property server_model

Return the model of the fake device beeing emulated.