Kane610 / aiounifi

Asynchronous library to communicate with Unifi Controller
MIT License
57 stars 49 forks source link

Add types for update_stats #657

Closed kimdv closed 1 month ago

kimdv commented 2 months ago

It will be part of https://github.com/home-assistant/core/pull/116737

This will add typed info for update_stats.WAN.monitors

JSON example from a UDM SE

{
  "data": [
    {
      "uptime_stats": {
        "WAN": {
          "monitors": [
            {
              "availability": 100.0,
              "latency_average": 5,
              "target": "www.microsoft.com",
              "type": "icmp"
            },
            {
              "availability": 100.0,
              "latency_average": 7,
              "target": "google.com",
              "type": "icmp"
            },
            {
              "availability": 100.0,
              "latency_average": 5,
              "target": "1.1.1.1",
              "type": "icmp"
            }
          ]
        },
        "WAN2": {
          "monitors": [
            {
              "availability": 0.0,
              "target": "www.microsoft.com",
              "type": "icmp"
            },
            {
              "availability": 0.0,
              "target": "google.com",
              "type": "icmp"
            },
            {
              "availability": 0.0,
              "target": "1.1.1.1",
              "type": "icmp"
            }
          ]
        }
      }
    }
  ]
}
Kane610 commented 2 months ago

I have more time to look tomorrow. I was also planning on doing this for you but good you got here first :)

kimdv commented 2 months ago

I have more time to look tomorrow. I was also planning on doing this for you but good you got here first :)

Awesome! :D

kimdv commented 1 month ago

@Kane610 I get this test error

FAILED tests/test_devices.py::test_device[device_payload5-reference_data5] - AssertionError: assert None == {'WAN': {'monitors': [{'availability': 100.0, 'latency_average': 5, 'target': 'www.microsoft.com', 'type': 'icmp'}, {'...ilability': 0.0, 'target': 'google.com', 'type': 'icmp'}, {'availability': 0.0, 'target': '1.1.1.1', 'type': 'icmp'}]}}

Not sure why? Is it because that we expect an object that isn't there? In this case I must be the uptime_stats

kimdv commented 1 month ago

@Kane610 I get this test error

FAILED tests/test_devices.py::test_device[device_payload5-reference_data5] - AssertionError: assert None == {'WAN': {'monitors': [{'availability': 100.0, 'latency_average': 5, 'target': 'www.microsoft.com', 'type': 'icmp'}, {'...ilability': 0.0, 'target': 'google.com', 'type': 'icmp'}, {'availability': 0.0, 'target': '1.1.1.1', 'type': 'icmp'}]}}

Not sure why? Is it because that we expect an object that isn't there? In this case I must be the uptime_stats

I needed to add in fixtures.py.

But removing the data in 13772ac2531230fabada5a1e6fcdcad050d03493 don't make it fail?

Kane610 commented 1 month ago

@Kane610 I get this test error

FAILED tests/test_devices.py::test_device[device_payload5-reference_data5] - AssertionError: assert None == {'WAN': {'monitors': [{'availability': 100.0, 'latency_average': 5, 'target': 'www.microsoft.com', 'type': 'icmp'}, {'...ilability': 0.0, 'target': 'google.com', 'type': 'icmp'}, {'availability': 0.0, 'target': '1.1.1.1', 'type': 'icmp'}]}}

Not sure why? Is it because that we expect an object that isn't there? In this case I must be the uptime_stats

I needed to add in fixtures.py.

But removing the data in 13772ac don't make it fail?

Removing the data doesn't do anything you remove the data to check against the existence of the data so when you remove it there is no comparison done for the update stats

Kane610 commented 1 month ago

I will do a release shortly