Add switch support to the Flo integration (#38268)
* Add switch domain to Flo integration * lint * updates post rebase * fix after rebase * remove device state attrs * oops * stale name and docstring
This commit is contained in:
1 parent
52a9921ed3
commit
ca5e752514
7 files changed
+357
-1
No files matched your search
@@ -79,3 +79,19 @@ def aioclient_mock_fixture(aioclient_mock):
|
||||
status=200,
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
# Mocks the valve open call for flo.
|
||||
aioclient_mock.post(
|
||||
"https://api-gw.meetflo.com/api/v2/devices/98765",
|
||||
text=load_fixture("flo/device_info_response.json"),
|
||||
status=200,
|
||||
headers={"Content-Type": "application/json"},
|
||||
json={"valve": {"target": "open"}},
|
||||
)
|
||||
# Mocks the valve close call for flo.
|
||||
aioclient_mock.post(
|
||||
"https://api-gw.meetflo.com/api/v2/devices/98765",
|
||||
text=load_fixture("flo/device_info_response_closed.json"),
|
||||
status=200,
|
||||
headers={"Content-Type": "application/json"},
|
||||
json={"valve": {"target": "closed"}},
|
||||
)
|
||||
@@ -45,6 +45,8 @@ async def test_device(hass, config_entry, aioclient_mock_fixture, aioclient_mock
|
||||
assert device.pending_critical_alerts_count == 0
|
||||
assert device.pending_warning_alerts_count == 2
|
||||
assert device.has_alerts is True
|
||||
assert device.last_known_valve_state == "open"
|
||||
assert device.target_valve_state == "open"
|
||||
|
||||
call_count = aioclient_mock.call_count
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
"""Tests for the switch domain for Flo by Moen."""
|
||||
from homeassistant.components.flo.const import DOMAIN as FLO_DOMAIN
|
||||
from homeassistant.components.switch import DOMAIN
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, STATE_OFF, STATE_ON
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import TEST_PASSWORD, TEST_USER_ID
|
||||
|
||||
|
||||
async def test_valve_switches(hass, config_entry, aioclient_mock_fixture):
|
||||
"""Test Flo by Moen valve switches."""
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await async_setup_component(
|
||||
hass, FLO_DOMAIN, {CONF_USERNAME: TEST_USER_ID, CONF_PASSWORD: TEST_PASSWORD}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.data[FLO_DOMAIN]["devices"]) == 1
|
||||
|
||||
entity_id = "switch.shutoff_valve"
|
||||
assert hass.states.get(entity_id).state == STATE_ON
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "turn_off", {"entity_id": entity_id}, blocking=True
|
||||
)
|
||||
assert hass.states.get(entity_id).state == STATE_OFF
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "turn_on", {"entity_id": entity_id}, blocking=True
|
||||
)
|
||||
assert hass.states.get(entity_id).state == STATE_ON
|
||||
Reference in new issue
Block a user