terratunaz
terratunaz

Reputation: 664

SONOS - rateItem - Not triggering "Operation failed"

Clicking on either of the rating buttons on my SONOS app causes an "Operation failed" error to appear and I don't know why. Everything else about the app works as expected except for that.

Here is the code for my rate item function. I'm using the pysimplesoap module.

def rateItem(id, rating, device, householdId, loginToken):
    # rating =
    # Unrated track -> rating = 1 (good) | rating = 0 (bad)
    # Track has thumbs up  -> rating = 3 (good) | rating = 2 (bad)
    # Track has thumbs down -> rating = 5 (good) | rating = 6 (bad)
    user_record = SonosUserRecord.collection.find_one({"loginToken": loginToken})
    user = get_user_from_username(username=user_record["username"])

    now = datetime.utcnow()
    SonosUserRecord.collection.update({"loginToken": loginToken}, {"$set": {"last_update": now}})
    #rateItemResponse = {"shouldSkip": "false"}
    if rating == 1 or rating == 5:
        print "Rated positive"
        # Rated positive
        rating_value = 5
        toid = id.split(":")[1]
        rating = MongoTrackRating(user, toid)
        rating.set_rating(int(rating_value))
        MongoTrackRatingAggregate.update_track_rating_aggregate(toid, int(rating_value))
    if rating == 0 or rating == 2:
        print "Rated negative"
        # Rated negative
        #rateItemResponse["shouldSkip"] = "true"
        rating_value = 1
        toid = id.split(":")[1]
        rating = MongoTrackRating(user, toid)
        rating.set_rating(int(rating_value))
        MongoTrackRatingAggregate.update_track_rating_aggregate(toid, int(rating_value))
    return rateItemResponse

And then I register it.

dispatcher.register_function('rateItem', rateItem,
    returns={"rateItemResult": list},
    args={"id": str, "rating": int, 'device':str, 'householdId':str, 'loginToken': str})

What am I missing?

Upvotes: 0

Views: 50

Answers (0)

Related Questions