elad-bar / ha-edgeos

Integration with EdgeOS (Ubiquiti)
133 stars 24 forks source link

Feature Request: Add support for Mbits as a unit #84

Closed clearwave1 closed 1 year ago

clearwave1 commented 1 year ago

Most internet speed checks and the Ubiquiti Edgerouter uses megabits as the unit they report.

I have edited your code updates for over a year to add this feature for my own uses but it is so simple I thought maybe you could offer it to everyone.

All that is needed is the following in const.py: MEGA_BIT = MEGA_BYTE / 8.4 (I came up with 8.4 by experimenting against the actual Edgerouter output) ATTR_MBIT = "MBits" UNIT_MAPPING = { ATTR_BYTE: BYTE, ATTR_KILO: KILO_BYTE, ATTR_MEGA: MEGA_BYTE, ATTR_MBIT: MEGA_BIT }

UNIT_OF_MEASUREMENT_MAPPING = { ATTR_BYTE: "B", ATTR_KILO: "KB", ATTR_MEGA: "MB", ATTR_MBIT: "Mb" }

Thanks in advance for considering this.

clearwave1 commented 1 year ago

@elad-bar - would you consider adding this or should I submit a pull request?

elad-bar commented 1 year ago

I personally not going to use Mbits...

How would you like to implement it in terms of user's configuration?

Btw, bit / byte ratio is exactly 8, compared it in the past with the data extarcted by snmp, ui and unms, unless you have found an official documentation that says otherwise, i suggest stick to it.

clearwave1 commented 1 year ago

Mbits is appropriate when watching upload/download speed real-time. This is also what Ookla and other speed test tools use.

I'm using this on the WAN interfaces to monitor the speed we're getting and using with each provider. Using Mbits for something like total download likely doesn't make sense so it would be optimal if the user could pick the metric per entity.

Finally, I'm an IT guy from way back so I'm aware that there are 8 bits to a byte. However, dividing your MEGA_BYTE variable by 8 does not come up with the same value that the router shows. I'm wondering whether your MEGA_BYTE value is possibly not correct. For me, the way around this after a bunch of testing was to use 8.4 as a divisor. Using 8.4 I get very close to the same value that the router shows (in Mbits).

By adding the code above, I am able to choose Mbits from your choice of units and get the values from the router in real-time in Mbits.

elad-bar commented 1 year ago

please check release v2.0.27

thanks

clearwave1 commented 1 year ago

Where in the code do you do the unit calculation now? It appears that it has moved out of const.py.

elad-bar commented 1 year ago

right, it is being done as part of the HA core functionality, please take a look at issue #90

clearwave1 commented 1 year ago

I tried it and it now works as expected without me having to update your code each release.

Thanks very much for adding this.

elad-bar commented 1 year ago

Thanks for the update, glad it works for you