miio.push_server.server module

class miio.push_server.server.PushServer(device_ip)[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(

action=”alarm_triggering”, extra=”[1,19,1,111,[0,1],2,0]”, trigger_token=miio_device.token,

) # Send a message to the miio_device to subscribe for the event to receive messages on the push_server await loop.run_in_executor(None, 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 push_server.stop()

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

Register a miio device to this push server.

async start()[source]

Start Miio push server.

stop()[source]

Stop Miio push server.

subscribe_event(device: miio.device.Device, event_info: miio.push_server.eventinfo.EventInfo) Optional[str][source]

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

unregister_miio_device(device: miio.device.Device)[source]

Unregister a miio device from this push server.

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

Unsubscribe from a event by id.

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.

miio.push_server.server.calculated_token_enc(token)[source]