-
Notifications
You must be signed in to change notification settings - Fork 119
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
Characteristic improvements #73
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e555607
Merged set_value and get_hap_value
cdce8p 78f6758
Additional changes
cdce8p 2505401
Addressed comments
cdce8p b25f052
Added debug statements
cdce8p 9c26ce3
Changed '_LOGGER' to 'logger'
cdce8p 9269b42
Changed raise error to return None
cdce8p 4bcf00c
Raising ValueErrors with custom msg
cdce8p 2dafa0f
Bugfix, added additional logger.error statements
cdce8p 79de11f
Rearanged functions
cdce8p 1d94c34
Added error_msg parameter
cdce8p 228d9f8
Added tests
cdce8p File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, didn't get my comment in quick enough before.
It seems really strange to handle the error here. Surely it's better just to raise an Exception and have the caller handle it. Doing this means we now have special return values to indicate a failure (which is very unpythonic).
If people don't like the traceback, then they should be catching the
ValueError
and logging it explicitly. (We could modify the examples to do this). py-HAP shouldn't be making that decision for them.Addtionally if the
ValueError
is caused by iOS, then we should be returning the correct status code to iOS to indicate an invalid value has been sent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure returning
None
is that special. It's basically the check: Didto_valid_value
really return a valid value? We can of course implement the try catch inset_value
, but I don't not if that is worth it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return None
is also universal that the function aborted.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't catch in
set_value
but in whatever calledset_value
. It seems strange to rob the caller of the ability to handle the error, just because our one usage now dosen't require that ability, and tracebacks are ugly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also returning
None
hides the error from the caller. Making even less obvious to the developer using the API that something has gone wrong.Submitting an invalid value the perfect time to fail fast and fail hard. Ensuring that anything that might rely on that valuing be set won't run unless the failure is explicitly handled.
Doing anything else if just going to quietly hide the error in impenetrable logs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that a user shouldn’t get trace backs. But it’s on HA to catch Exceptions, it’s not for py-HAP to accept any old input and carry on, just so HA doesn’t have do proper error handling.
py-HAP is just an API, a HA user shouldn’t have to interact directly with it. The HA ui should be doing all the heavy lifting.
If people are using py-HAP directly then it’s on them to catch errors and handle them, and they should be devs and know what to do with them.
If people are just using the demo accessories then they should be updated to capture the exception and produce a meaningful error message.
In each these scenarios the output will be different, we shouldn't be picking one and forcing everyone to use it.
And specifically with HA, doing the error handling in HA, rather than in py-hap means we can produce much better error messages(including HA info). Helping us debug issues quicker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I also point out that your proposed error message is very unhelpful. It says there is an invalid value, be not what caused it. Which accessory tried to set the value, and onto what characteristic, and why is it invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One final point. If your frustrated by the amount of work needed to do the error handling. I’m happy to do that work, both here and in HA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree.
'%s: value=%s is an invalid value.', self.display_name, value
should cover almost all cases. It's true that you don't get the accessory, but you know it already since it hasen't been updated. You also get the distinction betweenvalid values
andnumerics
. There isn't really anything more I would add / need.I won't stop you from looking through the open issues and suggesting solutions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are overthinking this a bit. It should be very rare to get invalid values:
That being said, I think that the current ValueError is good enough. When the dev is coding a new Accessory, he/she will probably get these early in testing. Once they are gone, they should be gone for good.