Skip to content

Commit

Permalink
Fix Habitica gems/hourglass sensors (home-assistant#135323)
Browse files Browse the repository at this point in the history
  • Loading branch information
tr4nt0r authored Jan 10, 2025
1 parent 560d15e commit bf747bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/habitica/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ class HabiticaSensorEntity(StrEnum):
HabiticaSensorEntityDescription(
key=HabiticaSensorEntity.GEMS,
translation_key=HabiticaSensorEntity.GEMS,
value_fn=lambda user, _: round(user.balance * 4) if user.balance else None,
value_fn=lambda user, _: None if (b := user.balance) is None else round(b * 4),
suggested_display_precision=0,
entity_picture="shop_gem.png",
),
HabiticaSensorEntityDescription(
key=HabiticaSensorEntity.TRINKETS,
translation_key=HabiticaSensorEntity.TRINKETS,
value_fn=lambda user, _: user.purchased.plan.consecutive.trinkets or 0,
value_fn=lambda user, _: user.purchased.plan.consecutive.trinkets,
suggested_display_precision=0,
native_unit_of_measurement="⧖",
entity_picture="notif_subscriber_reward.png",
Expand Down
9 changes: 8 additions & 1 deletion tests/components/habitica/fixtures/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@
}
}
},
"balance": 10
"balance": 10,
"purchased": {
"plan": {
"consecutive": {
"trinkets": 0
}
}
}
}
}

0 comments on commit bf747bb

Please sign in to comment.