mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Deal with cover assumed state (#22673)
* Deal with cover assumed state * Add docs
This commit is contained in:
parent
9eb4f89da4
commit
7cf92c2210
@ -27,6 +27,7 @@ from homeassistant.const import (
|
|||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
ATTR_SUPPORTED_FEATURES,
|
ATTR_SUPPORTED_FEATURES,
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
|
ATTR_ASSUMED_STATE,
|
||||||
)
|
)
|
||||||
from homeassistant.core import DOMAIN as HA_DOMAIN
|
from homeassistant.core import DOMAIN as HA_DOMAIN
|
||||||
from homeassistant.util import color as color_util, temperature as temp_util
|
from homeassistant.util import color as color_util, temperature as temp_util
|
||||||
@ -1055,11 +1056,19 @@ class OpenCloseTrait(_Trait):
|
|||||||
response = {}
|
response = {}
|
||||||
|
|
||||||
if domain == cover.DOMAIN:
|
if domain == cover.DOMAIN:
|
||||||
position = self.state.attributes.get(cover.ATTR_CURRENT_POSITION)
|
# When it's an assumed state, we will always report it as 50%
|
||||||
if position is not None:
|
# Google will not issue an open command if the assumed state is
|
||||||
response['openPercent'] = position
|
# open, even if that is currently incorrect.
|
||||||
|
if self.state.attributes.get(ATTR_ASSUMED_STATE):
|
||||||
|
response['openPercent'] = 50
|
||||||
else:
|
else:
|
||||||
if self.state.state != cover.STATE_CLOSED:
|
position = self.state.attributes.get(
|
||||||
|
cover.ATTR_CURRENT_POSITION
|
||||||
|
)
|
||||||
|
|
||||||
|
if position is not None:
|
||||||
|
response['openPercent'] = position
|
||||||
|
elif self.state.state != cover.STATE_CLOSED:
|
||||||
response['openPercent'] = 100
|
response['openPercent'] = 100
|
||||||
else:
|
else:
|
||||||
response['openPercent'] = 0
|
response['openPercent'] = 0
|
||||||
|
@ -21,7 +21,8 @@ from homeassistant.components.climate import const as climate
|
|||||||
from homeassistant.components.google_assistant import trait, helpers, const
|
from homeassistant.components.google_assistant import trait, helpers, const
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_ON, STATE_OFF, ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF,
|
STATE_ON, STATE_OFF, ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF,
|
||||||
TEMP_CELSIUS, TEMP_FAHRENHEIT, ATTR_SUPPORTED_FEATURES, ATTR_TEMPERATURE)
|
TEMP_CELSIUS, TEMP_FAHRENHEIT, ATTR_SUPPORTED_FEATURES, ATTR_TEMPERATURE,
|
||||||
|
ATTR_ASSUMED_STATE)
|
||||||
from homeassistant.core import State, DOMAIN as HA_DOMAIN, EVENT_CALL_SERVICE
|
from homeassistant.core import State, DOMAIN as HA_DOMAIN, EVENT_CALL_SERVICE
|
||||||
from homeassistant.util import color
|
from homeassistant.util import color
|
||||||
from tests.common import async_mock_service, mock_coro
|
from tests.common import async_mock_service, mock_coro
|
||||||
@ -1059,12 +1060,30 @@ async def test_openclose_cover(hass):
|
|||||||
assert trait.OpenCloseTrait.supported(cover.DOMAIN,
|
assert trait.OpenCloseTrait.supported(cover.DOMAIN,
|
||||||
cover.SUPPORT_SET_POSITION)
|
cover.SUPPORT_SET_POSITION)
|
||||||
|
|
||||||
|
# No position
|
||||||
|
trt = trait.OpenCloseTrait(hass, State('cover.bla', cover.STATE_OPEN, {
|
||||||
|
}), BASIC_CONFIG)
|
||||||
|
|
||||||
|
assert trt.sync_attributes() == {}
|
||||||
|
assert trt.query_attributes() == {
|
||||||
|
'openPercent': 100
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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() == {
|
||||||
|
'openPercent': 50
|
||||||
|
}
|
||||||
|
|
||||||
trt = trait.OpenCloseTrait(hass, State('cover.bla', cover.STATE_OPEN, {
|
trt = trait.OpenCloseTrait(hass, State('cover.bla', cover.STATE_OPEN, {
|
||||||
cover.ATTR_CURRENT_POSITION: 75
|
cover.ATTR_CURRENT_POSITION: 75
|
||||||
}), BASIC_CONFIG)
|
}), BASIC_CONFIG)
|
||||||
|
|
||||||
assert trt.sync_attributes() == {}
|
assert trt.sync_attributes() == {}
|
||||||
|
|
||||||
assert trt.query_attributes() == {
|
assert trt.query_attributes() == {
|
||||||
'openPercent': 75
|
'openPercent': 75
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user