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 for stateless covers #22962
Fix for stateless covers #22962
Conversation
cover.DOMAIN, cover.SERVICE_CLOSE_COVER, { | ||
ATTR_ENTITY_ID: self.state.entity_id | ||
}, blocking=True, context=data.context) | ||
if position is not None: |
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.
merge this into else on line above and make it elif
cover.DOMAIN, cover.SERVICE_OPEN_COVER, { | ||
ATTR_ENTITY_ID: self.state.entity_id | ||
}, blocking=True, context=data.context) | ||
if self.state.state != cover.STATE_CLOSED: |
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.
same
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, we should remove this logic. This makes no sense. We get explicit commands from Google, not toggle commands. We should not have the current state influence how we handle 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.
Please add a test
I have reached out to Google about this issue, this is their suggested fix:
|
@@ -1050,6 +1051,8 @@ def query_attributes(self): | |||
# open, even if that is currently incorrect. | |||
if self.state.attributes.get(ATTR_ASSUMED_STATE): | |||
response['openPercent'] = 50 | |||
elif self.state.state == STATE_UNKNOWN: |
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.
See my comment with the response from Google. We should raise NotSupported
error instead when it's an assumed state or unknown state.
Accidentally closed the PR while pushing corrections. |
Codecov Report
@@ Coverage Diff @@
## dev #22962 +/- ##
==========================================
- Coverage 93.95% 93.84% -0.12%
==========================================
Files 448 449 +1
Lines 36750 36767 +17
==========================================
- Hits 34529 34503 -26
- Misses 2221 2264 +43
Continue to review full report at Codecov.
|
@@ -1049,7 +1050,9 @@ def query_attributes(self): | |||
# Google will not issue an open command if the assumed state is | |||
# open, even if that is currently incorrect. | |||
if self.state.attributes.get(ATTR_ASSUMED_STATE): | |||
response['openPercent'] = 50 | |||
response['willReportState'] = False |
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.
This is wrong. reportState is a sync attribute and we already set it to False. You need to raise an error instead
raise SmartHomeError(
ERR_FUNCTION_NOT_SUPPORTED,
'Querying state is not supported')
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.
And you need to raise that error when it's both assumed state and when it's unknown.
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.
Ok, but it won't fix the issue. It looks like google assistant is making a query before executing an open/close command. When we raise an error on query it raises the same error while executing the command. While CommandOnly is not available can we just assume openPercent = 50? It would allow us to open and close stateless covers.
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 wasn't raising the right error. Now with ERR_NOT_SUPPORTED it works. Stateless covers are moving but google assistant says otherwise due to the raised error.
cover.DOMAIN, cover.SERVICE_OPEN_COVER, { | ||
ATTR_ENTITY_ID: self.state.entity_id | ||
}, blocking=True, context=data.context) | ||
if params['openPercent'] < 100: |
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.
These two checks can be removed? We should not get a position and not be able to deal with it. Google should return just 0 or 100 for covers that we won't support getting the state from.
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.
It can be removed, I can raise an error instead. I though it was better to open and close the cover with a position command even if it didn't support setting a position.
raise SmartHomeError(
ERR_FUNCTION_NOT_SUPPORTED,
'Setting a position is not supported')
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.
In what cases do we get here?
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.
We get here if we ask for a position and the cover doesn't support setting position. Raising this error may be less confusing for the user than a cover not doing what he asked.
Hey, do you want is to test it again? |
# Assumed state | ||
trt = trait.OpenCloseTrait(hass, State('cover.bla', cover.STATE_OPEN, { | ||
ATTR_ASSUMED_STATE: True, | ||
}), BASIC_CONFIG) | ||
|
||
assert trt.sync_attributes() == {} | ||
assert trt.query_attributes() == { |
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 you update the test to make sure that we raise for unknown and assumed state?
with pytest.raises(SmartHomeError):
trt.query_attributes()
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.
Awesome, thanks ! This will be part of the beta on Wednesday, released a week later 👍
Description:
Stateless covers didn't work with previous trait
Related issue (if applicable): fixes #22740
Checklist:
tox
. Your PR cannot be merged unless tests passIf the code does not interact with devices: