Skip to content

Conversation

edleno2
Copy link

@edleno2 edleno2 commented Aug 1, 2025

Proposed change

When writing unit tests using Fluent Assertion I discovered that equality checks against ServiceTarget can only be done as reference equality. This would be extremely hard to use since the creation of ServiceTargets often happens in internal code. This code adds Equal(object) which matches the signature used by Fluent Assertions when CallService is used with a target of "object?".

Type of change

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

Additional information

This change did cause one regression of a unit test. The test relied on the LACK of an equals so that the comparison between a class (ServiceTarget) and a record (HassTarget) was done on a member by member basis. Once an equals was added this lead to the issue that neither the class nor the record could equate each other. Added an option to force member comparison. This is a known limitation with class to record comparisons (see answer 2 in this link)

Added unit tests to show which equal operators will work, and which will not. Keeping to the principle to make the least impactive change I did not override the == or != operator for actual ServiceTarget classes. Those type of comparisons will still default to checking object reference equality.

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • The code compiles without warnings (code quality check)
  • Tests have been added to verify that the new code works.

edleno2 and others added 3 commits July 31, 2025 16:37
…t Assertions. Without this since ServiceTarget is a class the only check is if two objects are the SAME object (i.e. reference check only)
@edleno2
Copy link
Author

edleno2 commented Aug 1, 2025

Noticed I hadn't added not equal test cases. Just to show that all not equal checks are just the negative of Equal(object).

@edleno2
Copy link
Author

edleno2 commented Aug 2, 2025

Do I also need to clean up the "empty" commit from resyncing my repo and squash the commits. I saw some comments in discord about commits not being signed but I don't understand the signing process.

Copy link

codecov bot commented Aug 9, 2025

Codecov Report

❌ Patch coverage is 27.58621% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 82%. Comparing base (8be1690) to head (6bcfe26).

Files with missing lines Patch % Lines
src/HassModel/NetDaemon.HassModel/ServiceTarget.cs 27% 16 Missing and 5 partials ⚠️
Additional details and impacted files
@@         Coverage Diff          @@
##           main   #1323   +/-   ##
====================================
- Coverage    82%     82%   -1%     
====================================
  Files       197     197           
  Lines      3871    3900   +29     
  Branches    429     442   +13     
====================================
+ Hits       3194    3202    +8     
- Misses      511     527   +16     
- Partials    166     171    +5     
Flag Coverage Δ
unittests 82% <27%> (-1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@FrankBakkerNl FrankBakkerNl left a comment

Choose a reason for hiding this comment

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

I think making ServiceTarget a record will do the same thing with less chance of mistakes. Not sure why I did not do that originally.

@helto4real
Copy link
Collaborator

@FrankBakkerNl what do you think we should proceed with this PR?

@FrankBakkerNl
Copy link
Contributor

I think the record solution would be better. @edleno2 did you want to do this?

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

Successfully merging this pull request may close these issues.

3 participants