<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _leave_unused_rooms(self, _address_to_room_ids: Dict[AddressHex, List[_RoomID]]):
 """ Checks for rooms we've joined and which partner isn't health-checked and leave. **MUST** be called from a context that holds the `_account_data_lock`. """

        _msg = '_leave_unused_rooms called without account data lock'
        assert self._account_data_lock.locked(), _msg

        # TODO: Remove the next five lines and check if transfers start hanging again
        self._client.set_account_data(
            'network.raiden.rooms',  # back from cast in _set_room_id_for_address
            cast(Dict[str, Any], _address_to_room_ids),
        )
        return

        # cache in a set all whitelisted addresses
        whitelisted_hex_addresses: Set[AddressHex] = {
            to_checksum_address(address)
            for address in self._address_mgr.known_addresses
        }

        keep_rooms: Set[_RoomID] = set()

        for address_hex, room_ids in list(_address_to_room_ids.items()):
            if not room_ids:  # None or empty
                room_ids = list()
            if not isinstance(room_ids, list):  # old version, single room
                room_ids = [room_ids]

            if address_hex not in whitelisted_hex_addresses:
                _address_to_room_ids.pop(address_hex)
                continue

            counters = [0, 0]  # public, private
            new_room_ids: List[_RoomID] = list()

            # limit to at most 2 public and 2 private rooms, preserving order
            for room_id in room_ids:
                if room_id not in self._client.rooms:
                    continue
                elif self._client.rooms[room_id].invite_only is None:
                    new_room_ids.append(room_id)  # not known, postpone cleaning
                elif counters[self._client.rooms[room_id].invite_only] < 2:
                    counters[self._client.rooms[room_id].invite_only] += 1
                    new_room_ids.append(room_id)  # not enough rooms of this type yet
                else:
                    continue  # enough rooms, leave and clean

            keep_rooms |= set(new_room_ids)
            if room_ids != new_room_ids:
                _address_to_room_ids[address_hex] = new_room_ids

        rooms: List[Tuple[_RoomID, Room]] = list(self._client.rooms.items())

        self.log.debug(
            'Updated address room mapping',
            address_to_room_ids=_address_to_room_ids,
        )
        self._client.set_account_data('network.raiden.rooms', _address_to_room_ids)

        def leave(room: Room):
            """A race between /leave and /sync may remove the room before
            del on _client.rooms key. Suppress it, as the end result is the same: no more room"""
            try:
                self.log.debug('Leaving unused room', room=room)
                return room.leave()
            except KeyError:
                return True

        for room_id, room in rooms:
            if room_id in {groom.room_id for groom in self._global_rooms.values() if groom}:
                # don't leave global room
                continue
            if room_id not in keep_rooms:
                greenlet = self._spawn(leave, room)
                greenlet.name = (
                    f'MatrixTransport.leave '
                    f'node:{pex(self._raiden_service.address)} '
                    f'user_id:{self._user_id}'
                )