openmedialibrary/oml/bandwidth.py

30 lines
620 B
Python
Raw Normal View History

2015-11-30 23:26:35 +00:00
import state
from websocket import trigger_event
2015-12-01 08:59:52 +00:00
import logging
logger = logging.getLogger(__name__)
2015-11-30 23:26:35 +00:00
class Bandwidth(object):
up = 0
down = 0
_last = {}
def __init__(self):
self.update()
def update(self):
bandwidth = {'up': self.up, 'down': self.down}
if bandwidth != self._last:
trigger_event('bandwidth', bandwidth)
self._last = bandwidth
self.up = 0
self.down = 0
state.main.call_later(1, self.update)
def download(self, amount):
2015-12-25 15:21:01 +00:00
self.down += amount
2015-11-30 23:26:35 +00:00
def upload(self, amount):
2015-12-25 15:21:01 +00:00
self.up += amount
2015-11-30 23:26:35 +00:00