Google assistant openclose (#39612)
* Make sure we set discreteOnlyOpenClose for binary sensors * Mark switches that are assumed state as commandOnlyOnOff * Drop stray extra line * Fix pylint error Co-authored-by: springstan <46536646+springstan@users.noreply.github.com>
This commit is contained in:
parent
8818a5ab6c
commit
d128443a2a
3 changed files with 20 additions and 3 deletions
|
@ -315,6 +315,8 @@ class OnOffTrait(_Trait):
|
||||||
|
|
||||||
def sync_attributes(self):
|
def sync_attributes(self):
|
||||||
"""Return OnOff attributes for a sync request."""
|
"""Return OnOff attributes for a sync request."""
|
||||||
|
if self.state.attributes.get(ATTR_ASSUMED_STATE, False):
|
||||||
|
return {"commandOnlyOnOff": True}
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def query_attributes(self):
|
def query_attributes(self):
|
||||||
|
@ -1541,6 +1543,7 @@ class OpenCloseTrait(_Trait):
|
||||||
response = {}
|
response = {}
|
||||||
if self.state.domain == binary_sensor.DOMAIN:
|
if self.state.domain == binary_sensor.DOMAIN:
|
||||||
response["queryOnlyOpenClose"] = True
|
response["queryOnlyOpenClose"] = True
|
||||||
|
response["discreteOnlyOpenClose"] = True
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def query_attributes(self):
|
def query_attributes(self):
|
||||||
|
|
|
@ -795,7 +795,10 @@ async def test_device_class_binary_sensor(hass, device_class, google_type):
|
||||||
"agentUserId": "test-agent",
|
"agentUserId": "test-agent",
|
||||||
"devices": [
|
"devices": [
|
||||||
{
|
{
|
||||||
"attributes": {"queryOnlyOpenClose": True},
|
"attributes": {
|
||||||
|
"queryOnlyOpenClose": True,
|
||||||
|
"discreteOnlyOpenClose": True,
|
||||||
|
},
|
||||||
"id": "binary_sensor.demo_sensor",
|
"id": "binary_sensor.demo_sensor",
|
||||||
"name": {"name": "Demo Sensor"},
|
"name": {"name": "Demo Sensor"},
|
||||||
"traits": ["action.devices.traits.OpenClose"],
|
"traits": ["action.devices.traits.OpenClose"],
|
||||||
|
|
|
@ -208,6 +208,11 @@ async def test_onoff_switch(hass):
|
||||||
|
|
||||||
assert trt_off.query_attributes() == {"on": False}
|
assert trt_off.query_attributes() == {"on": False}
|
||||||
|
|
||||||
|
trt_assumed = trait.OnOffTrait(
|
||||||
|
hass, State("switch.bla", STATE_OFF, {"assumed_state": True}), BASIC_CONFIG
|
||||||
|
)
|
||||||
|
assert trt_assumed.sync_attributes() == {"commandOnlyOnOff": True}
|
||||||
|
|
||||||
on_calls = async_mock_service(hass, switch.DOMAIN, SERVICE_TURN_ON)
|
on_calls = async_mock_service(hass, switch.DOMAIN, SERVICE_TURN_ON)
|
||||||
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": True}, {})
|
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": True}, {})
|
||||||
assert len(on_calls) == 1
|
assert len(on_calls) == 1
|
||||||
|
@ -2022,7 +2027,10 @@ async def test_openclose_binary_sensor(hass, device_class):
|
||||||
BASIC_CONFIG,
|
BASIC_CONFIG,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert trt.sync_attributes() == {"queryOnlyOpenClose": True}
|
assert trt.sync_attributes() == {
|
||||||
|
"queryOnlyOpenClose": True,
|
||||||
|
"discreteOnlyOpenClose": True,
|
||||||
|
}
|
||||||
|
|
||||||
assert trt.query_attributes() == {"openPercent": 100}
|
assert trt.query_attributes() == {"openPercent": 100}
|
||||||
|
|
||||||
|
@ -2032,7 +2040,10 @@ async def test_openclose_binary_sensor(hass, device_class):
|
||||||
BASIC_CONFIG,
|
BASIC_CONFIG,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert trt.sync_attributes() == {"queryOnlyOpenClose": True}
|
assert trt.sync_attributes() == {
|
||||||
|
"queryOnlyOpenClose": True,
|
||||||
|
"discreteOnlyOpenClose": True,
|
||||||
|
}
|
||||||
|
|
||||||
assert trt.query_attributes() == {"openPercent": 0}
|
assert trt.query_attributes() == {"openPercent": 0}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue