Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error in image platform of Habitica integration #135897

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

tr4nt0r
Copy link
Contributor

@tr4nt0r tr4nt0r commented Jan 18, 2025

Proposed change

  • Fixes a minor bug were the generation of the image was not triggered on the first refresh only on the second coordinator refresh
  • Adds tests for the image platform

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

homeassistant/components/habitica/image.py Outdated Show resolved Hide resolved
tests/components/habitica/test_image.py Outdated Show resolved Hide resolved
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft January 19, 2025 11:52
@tr4nt0r tr4nt0r marked this pull request as ready for review January 19, 2025 14:27
@home-assistant home-assistant bot requested a review from joostlek January 19, 2025 14:27
Comment on lines +79 to +82
def _appearance(self) -> UserStyles:
"""Gather all attributes relevant for avatar appearance from user data."""

return UserStyles.from_dict(asdict(self.coordinator.data.user))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This did not answer my question

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then i misunderstood, sorry. UserStyles is a subset of UserData, and when doing this, the resulting object will only contain the fields that are relevant and I can then easily compare if there were changes in gear, pets/mounts, background and so on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume casting won't work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, doesn't work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much fields are there? Because I don't really like that we practically make a copy of the object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like 40? It's a bit nested. The method that generates the avatar takes a UserStyles object

UserStyles(items=ItemsUserStyles(gear=GearItemsUserStyles(equipped=EquippedGear(weapon='weapon_special_2', armor='armor_special_pageArmor', head='head_special_2', shield='shield_special_lootBag', back='back_base_0', headAccessory='headAccessory_base_0', eyewear='eyewear_base_0', body='body_base_0'), costume=EquippedGear(weapon='weapon_base_0', armor='armor_special_snowSovereignRobes', head='head_mystery_202501', shield='shield_mystery_202501', back='back_base_0', headAccessory='headAccessory_base_0', eyewear='eyewear_base_0', body='body_base_0')), currentMount='Gryphon-White', currentPet='Wolf-Spooky'), preferences=PreferencesUserStyles(hair=HairPreferences(color='brown', base=0, bangs=1, beard=0, mustache=0, flower=16), size='broad', skin='98461a', shirt='pink', chair='none', costume=True, sleep=False, background='surrounded_by_ghosts'), stats=StatsUserStyles(buffs=BuffsUserStyles(per=31, con=31, stealth=0, seafoam=False, shinySeed=False, snowball=False, spookySparkles=False), Class=<HabiticaClass.WARRIOR: 'warrior'>))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants