Skip to content

Conversation

@starkillerOG
Copy link
Contributor

@starkillerOG starkillerOG commented Jul 14, 2022

Implement push server for the gateways.
Split out from PR #1288
Follow up of PR #1446

Test script:

import logging
import asyncio
from miio import Gateway, PushServer

_LOGGER = logging.getLogger(__name__)
logging.basicConfig(level="INFO")

gateway_ip = "192.168.1.IP"
token = "TokenTokenToken"


async def asyncio_demo(loop):
    def gateway_callback(action, params):
        _LOGGER.info("Gateway '%s' callback, params: '%s'", action, params)

    def subdevice_callback(action, params):
        _LOGGER.info("Subdevice '%s' callback, params: '%s'", action, params)
    
    push_server = PushServer(gateway_ip)
    gateway = Gateway(gateway_ip, token, push_server=push_server)
    
    await push_server.start()

    await loop.run_in_executor(None, gateway.alarm.subscribe_events)
    gateway.register_callback("DEMO_CB", gateway_callback)

    await loop.run_in_executor(None, gateway.discover_devices)
    
    for device in gateway.devices.values():
        device.register_callback("DEMO_CB", subdevice_callback)
        await loop.run_in_executor(None, device.subscribe_events)
    
    _LOGGER.info("Listening")
    
    await asyncio.sleep(60)

    push_server.stop()
    gateway.close()

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(asyncio_demo(loop))

@starkillerOG
Copy link
Contributor Author

@rytilahti this is the follow-up PR for the push server implementation for the gateway.
Could you review this and merge before the release this week?

@codecov-commenter
Copy link

codecov-commenter commented Jul 14, 2022

Codecov Report

Merging #1459 (1450c1e) into master (4dd3cd8) will decrease coverage by 0.87%.
The diff coverage is 36.95%.

@@            Coverage Diff             @@
##           master    #1459      +/-   ##
==========================================
- Coverage   83.35%   82.48%   -0.88%     
==========================================
  Files         139      140       +1     
  Lines       13670    13897     +227     
  Branches     3248     3304      +56     
==========================================
+ Hits        11395    11463      +68     
- Misses       2057     2214     +157     
- Partials      218      220       +2     
Impacted Files Coverage Δ
miio/gateway/devices/subdevice.py 33.14% <23.07%> (-3.74%) ⬇️
miio/gateway/alarm.py 47.72% <35.29%> (-7.83%) ⬇️
miio/gateway/gateway.py 44.44% <39.28%> (-3.15%) ⬇️
miio/gateway/gatewaydevice.py 69.23% <100.00%> (+2.56%) ⬆️
miio/push_server/__init__.py 100.00% <100.00%> (ø)
miio/push_server/server.py 24.62% <100.00%> (+1.14%) ⬆️
...io/integrations/vacuum/dreame/dreamevacuum_miot.py 74.38% <0.00%> (-4.36%) ⬇️
miio/__init__.py 100.00% <0.00%> (ø)
miio/cloud.py 33.33% <0.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@starkillerOG
Copy link
Contributor Author

again a unrelated test failure about the utils module

@starkillerOG
Copy link
Contributor Author

@rytilahti could you add this to the 5.12 milestone?

@rytilahti rytilahti added this to the 0.5.12 milestone Jul 15, 2022
@rytilahti rytilahti changed the title gateway push server Implement push notifications for gateway Jul 15, 2022
@rytilahti
Copy link
Owner

again a unrelated test failure about the utils module

Yeah, 3.11-dev checks on mac and windows are flaky, maybe I should disable them altogether :-(

@starkillerOG
Copy link
Contributor Author

@rytilahti thank you very much for the review and the feedback!
I have processed everything.
Could you review again/merge?

(I am away this weekend so won't be able to work on this after tonight, if you have further suggestions, feel free to just make commits and merge the commits in this PR)

starkillerOG and others added 2 commits July 16, 2022 00:17
* Renamed the file to use correct extension
* Fixed the link to obtaining event information
* Marked code block to use yaml
Copy link
Owner

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

I updated the docs a bit but I suppose this is otherwise fine for now, let's get it merged! Thanks @starkillerOG!

@starkillerOG
Copy link
Contributor Author

@rytilahti thank you very much for your help and suggestions, very glad we manged to get this merged before the new release :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants