'Update device state.'

def update(self):

    currently_tracked = set()
    states = self._session.get(OPENSKY_API_URL).json().get(ATTR_STATES)
    for state in states:
        data = dict(zip(OPENSKY_API_FIELDS, state))
        missing_location = ((data.get(ATTR_LONGITUDE) is None) or (data.get(ATTR_LATITUDE) is None))
        if missing_location:
            continue
        if data.get(ATTR_ON_GROUND):
            continue
        distance = util_location.distance(self._latitude, self._longitude, data.get(ATTR_LATITUDE), data.get(ATTR_LONGITUDE))
        if ((distance is None) or (distance > self._radius)):
            continue
        callsign = data[ATTR_CALLSIGN].strip()
        if (callsign == ''):
            continue
        currently_tracked.add(callsign)
    if (self._previously_tracked is not None):
        entries = (currently_tracked - self._previously_tracked)
        exits = (self._previously_tracked - currently_tracked)
        self._handle_boundary(entries, EVENT_OPENSKY_ENTRY)
        self._handle_boundary(exits, EVENT_OPENSKY_EXIT)
    self._state = len(currently_tracked)
    self._previously_tracked = currently_tracked
