Add ozw garage door barrier support (#37316)
This commit is contained in:
1 parent
4679e670f1
commit
f6df85f8ce
6 files changed
+223
-1
No files matched your search
@@ -33,6 +33,12 @@ def cover_data_fixture():
|
||||
return load_fixture("ozw/cover_network_dump.csv")
|
||||
|
||||
|
||||
@pytest.fixture(name="cover_gdo_data", scope="session")
|
||||
def cover_gdo_data_fixture():
|
||||
"""Load cover_gdo MQTT data and return it."""
|
||||
return load_fixture("ozw/cover_gdo_network_dump.csv")
|
||||
|
||||
|
||||
@pytest.fixture(name="climate_data", scope="session")
|
||||
def climate_data_fixture():
|
||||
"""Load climate MQTT data and return it."""
|
||||
@@ -136,6 +142,17 @@ async def cover_msg_fixture(hass):
|
||||
return message
|
||||
|
||||
|
||||
@pytest.fixture(name="cover_gdo_msg")
|
||||
async def cover_gdo_msg_fixture(hass):
|
||||
"""Return a mock MQTT msg with a cover barrier state change message."""
|
||||
sensor_json = json.loads(
|
||||
await hass.async_add_executor_job(load_fixture, "ozw/cover_gdo.json")
|
||||
)
|
||||
message = MQTTMessage(topic=sensor_json["topic"], payload=sensor_json["payload"])
|
||||
message.encode()
|
||||
return message
|
||||
|
||||
|
||||
@pytest.fixture(name="climate_msg")
|
||||
async def climate_msg_fixture(hass):
|
||||
"""Return a mock MQTT msg with a climate mode change message."""
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
"""Test Z-Wave Covers."""
|
||||
from homeassistant.components.cover import ATTR_CURRENT_POSITION
|
||||
from homeassistant.components.ozw.cover import VALUE_SELECTED_ID
|
||||
|
||||
from .common import setup_ozw
|
||||
|
||||
VALUE_ID = "Value"
|
||||
|
||||
|
||||
async def test_cover(hass, cover_data, sent_messages, cover_msg):
|
||||
"""Test setting up config entry."""
|
||||
@@ -84,3 +87,47 @@ async def test_cover(hass, cover_data, sent_messages, cover_msg):
|
||||
msg = sent_messages[4]
|
||||
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||
assert msg["payload"] == {"Value": 0, "ValueIDKey": 625573905}
|
||||
|
||||
|
||||
async def test_barrier(hass, cover_gdo_data, sent_messages, cover_gdo_msg):
|
||||
"""Test setting up config entry."""
|
||||
receive_message = await setup_ozw(hass, fixture=cover_gdo_data)
|
||||
# Test loaded
|
||||
state = hass.states.get("cover.gd00z_4_barrier_state")
|
||||
assert state is not None
|
||||
assert state.state == "closed"
|
||||
|
||||
# Test opening
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"open_cover",
|
||||
{"entity_id": "cover.gd00z_4_barrier_state"},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(sent_messages) == 1
|
||||
msg = sent_messages[0]
|
||||
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||
assert msg["payload"] == {"Value": 4, "ValueIDKey": 281475083239444}
|
||||
|
||||
# Feedback on state
|
||||
cover_gdo_msg.decode()
|
||||
cover_gdo_msg.payload[VALUE_ID][VALUE_SELECTED_ID] = 4
|
||||
cover_gdo_msg.encode()
|
||||
receive_message(cover_gdo_msg)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("cover.gd00z_4_barrier_state")
|
||||
assert state is not None
|
||||
assert state.state == "open"
|
||||
|
||||
# Test closing
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"close_cover",
|
||||
{"entity_id": "cover.gd00z_4_barrier_state"},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(sent_messages) == 2
|
||||
msg = sent_messages[1]
|
||||
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||
assert msg["payload"] == {"Value": 0, "ValueIDKey": 281475083239444}
|
||||
Reference in new issue
Block a user