mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Do not test internals in flo tests (#138306)
* Do not test internals in flo tests * fix
This commit is contained in:
parent
a85bb98743
commit
14e1b55b5a
75
tests/components/flo/snapshots/test_init.ambr
Normal file
75
tests/components/flo/snapshots/test_init.ambr
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_setup_entry
|
||||||
|
list([
|
||||||
|
DeviceRegistryEntrySnapshot({
|
||||||
|
'area_id': None,
|
||||||
|
'config_entries': <ANY>,
|
||||||
|
'config_entries_subentries': <ANY>,
|
||||||
|
'configuration_url': None,
|
||||||
|
'connections': set({
|
||||||
|
tuple(
|
||||||
|
'mac',
|
||||||
|
'11:11:11:11:11:11',
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
'disabled_by': None,
|
||||||
|
'entry_type': None,
|
||||||
|
'hw_version': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'identifiers': set({
|
||||||
|
tuple(
|
||||||
|
'flo',
|
||||||
|
'98765',
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
'is_new': False,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'manufacturer': 'Flo by Moen',
|
||||||
|
'model': 'flo_device_075_v2',
|
||||||
|
'model_id': None,
|
||||||
|
'name': 'Smart water shutoff',
|
||||||
|
'name_by_user': None,
|
||||||
|
'primary_config_entry': <ANY>,
|
||||||
|
'serial_number': '111111111111',
|
||||||
|
'suggested_area': None,
|
||||||
|
'sw_version': '6.1.1',
|
||||||
|
'via_device_id': None,
|
||||||
|
}),
|
||||||
|
DeviceRegistryEntrySnapshot({
|
||||||
|
'area_id': None,
|
||||||
|
'config_entries': <ANY>,
|
||||||
|
'config_entries_subentries': <ANY>,
|
||||||
|
'configuration_url': None,
|
||||||
|
'connections': set({
|
||||||
|
tuple(
|
||||||
|
'mac',
|
||||||
|
'1a:2b:3c:4d:5e:6f',
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
'disabled_by': None,
|
||||||
|
'entry_type': None,
|
||||||
|
'hw_version': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'identifiers': set({
|
||||||
|
tuple(
|
||||||
|
'flo',
|
||||||
|
'32839',
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
'is_new': False,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'manufacturer': 'Flo by Moen',
|
||||||
|
'model': 'puck_v1',
|
||||||
|
'model_id': None,
|
||||||
|
'name': 'Kitchen sink',
|
||||||
|
'name_by_user': None,
|
||||||
|
'primary_config_entry': <ANY>,
|
||||||
|
'serial_number': '111111111112',
|
||||||
|
'suggested_area': None,
|
||||||
|
'sw_version': '1.1.15',
|
||||||
|
'via_device_id': None,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
# ---
|
@ -2,18 +2,8 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.flo.const import DOMAIN as FLO_DOMAIN
|
from homeassistant.const import ATTR_FRIENDLY_NAME, STATE_OFF, STATE_ON
|
||||||
from homeassistant.const import (
|
|
||||||
ATTR_FRIENDLY_NAME,
|
|
||||||
CONF_PASSWORD,
|
|
||||||
CONF_USERNAME,
|
|
||||||
STATE_OFF,
|
|
||||||
STATE_ON,
|
|
||||||
)
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
|
|
||||||
from .common import TEST_PASSWORD, TEST_USER_ID
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
@ -24,13 +14,9 @@ async def test_binary_sensors(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test Flo by Moen sensors."""
|
"""Test Flo by Moen sensors."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
assert await async_setup_component(
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
hass, FLO_DOMAIN, {CONF_USERNAME: TEST_USER_ID, CONF_PASSWORD: TEST_PASSWORD}
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(hass.data[FLO_DOMAIN][config_entry.entry_id]["devices"]) == 2
|
|
||||||
|
|
||||||
valve_state = hass.states.get(
|
valve_state = hass.states.get(
|
||||||
"binary_sensor.smart_water_shutoff_pending_system_alerts"
|
"binary_sensor.smart_water_shutoff_pending_system_alerts"
|
||||||
)
|
)
|
||||||
|
@ -7,13 +7,8 @@ from aioflo.errors import RequestError
|
|||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.flo.const import DOMAIN as FLO_DOMAIN
|
from homeassistant.const import STATE_UNAVAILABLE
|
||||||
from homeassistant.components.flo.coordinator import FloDeviceDataUpdateCoordinator
|
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, STATE_UNAVAILABLE
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
|
|
||||||
from .common import TEST_PASSWORD, TEST_USER_ID
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
@ -28,59 +23,8 @@ async def test_device(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test Flo by Moen devices."""
|
"""Test Flo by Moen devices."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
assert await async_setup_component(
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
hass, FLO_DOMAIN, {CONF_USERNAME: TEST_USER_ID, CONF_PASSWORD: TEST_PASSWORD}
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(hass.data[FLO_DOMAIN][config_entry.entry_id]["devices"]) == 2
|
|
||||||
|
|
||||||
valve: FloDeviceDataUpdateCoordinator = hass.data[FLO_DOMAIN][
|
|
||||||
config_entry.entry_id
|
|
||||||
]["devices"][0]
|
|
||||||
assert valve.api_client is not None
|
|
||||||
assert valve.available
|
|
||||||
assert valve.consumption_today == 3.674
|
|
||||||
assert valve.current_flow_rate == 0
|
|
||||||
assert valve.current_psi == 54.20000076293945
|
|
||||||
assert valve.current_system_mode == "home"
|
|
||||||
assert valve.target_system_mode == "home"
|
|
||||||
assert valve.firmware_version == "6.1.1"
|
|
||||||
assert valve.device_type == "flo_device_v2"
|
|
||||||
assert valve.id == "98765"
|
|
||||||
assert valve.last_heard_from_time == "2020-07-24T12:45:00Z"
|
|
||||||
assert valve.location_id == "mmnnoopp"
|
|
||||||
assert valve.hass is not None
|
|
||||||
assert valve.temperature == 70
|
|
||||||
assert valve.mac_address == "111111111111"
|
|
||||||
assert valve.model == "flo_device_075_v2"
|
|
||||||
assert valve.manufacturer == "Flo by Moen"
|
|
||||||
assert valve.device_name == "Smart Water Shutoff"
|
|
||||||
assert valve.rssi == -47
|
|
||||||
assert valve.pending_info_alerts_count == 0
|
|
||||||
assert valve.pending_critical_alerts_count == 0
|
|
||||||
assert valve.pending_warning_alerts_count == 2
|
|
||||||
assert valve.has_alerts is True
|
|
||||||
assert valve.last_known_valve_state == "open"
|
|
||||||
assert valve.target_valve_state == "open"
|
|
||||||
|
|
||||||
detector: FloDeviceDataUpdateCoordinator = hass.data[FLO_DOMAIN][
|
|
||||||
config_entry.entry_id
|
|
||||||
]["devices"][1]
|
|
||||||
assert detector.api_client is not None
|
|
||||||
assert detector.available
|
|
||||||
assert detector.device_type == "puck_oem"
|
|
||||||
assert detector.id == "32839"
|
|
||||||
assert detector.last_heard_from_time == "2021-03-07T14:05:00Z"
|
|
||||||
assert detector.location_id == "mmnnoopp"
|
|
||||||
assert detector.hass is not None
|
|
||||||
assert detector.temperature == 61
|
|
||||||
assert detector.humidity == 43
|
|
||||||
assert detector.water_detected is False
|
|
||||||
assert detector.mac_address == "1a2b3c4d5e6f"
|
|
||||||
assert detector.model == "puck_v1"
|
|
||||||
assert detector.manufacturer == "Flo by Moen"
|
|
||||||
assert detector.device_name == "Kitchen Sink"
|
|
||||||
assert detector.serial_number == "111111111112"
|
|
||||||
|
|
||||||
call_count = aioclient_mock.call_count
|
call_count = aioclient_mock.call_count
|
||||||
|
|
||||||
|
@ -1,25 +1,32 @@
|
|||||||
"""Test init."""
|
"""Test init."""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from syrupy import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components.flo.const import DOMAIN as FLO_DOMAIN
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from .common import TEST_PASSWORD, TEST_USER_ID
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("aioclient_mock_fixture")
|
@pytest.mark.usefixtures("aioclient_mock_fixture")
|
||||||
async def test_setup_entry(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
|
async def test_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
"""Test migration of config entry from v1."""
|
"""Test migration of config entry from v1."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
assert await async_setup_component(
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
hass, FLO_DOMAIN, {CONF_USERNAME: TEST_USER_ID, CONF_PASSWORD: TEST_PASSWORD}
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(hass.data[FLO_DOMAIN][config_entry.entry_id]["devices"]) == 2
|
assert config_entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
|
assert (
|
||||||
|
dr.async_entries_for_config_entry(device_registry, config_entry.entry_id)
|
||||||
|
== snapshot
|
||||||
|
)
|
||||||
|
|
||||||
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||||
|
assert config_entry.state is ConfigEntryState.NOT_LOADED
|
||||||
|
@ -2,15 +2,12 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.flo.const import DOMAIN as FLO_DOMAIN
|
|
||||||
from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorStateClass
|
from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorStateClass
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import ATTR_ENTITY_ID
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||||
|
|
||||||
from .common import TEST_PASSWORD, TEST_USER_ID
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
@ -20,13 +17,9 @@ async def test_sensors(hass: HomeAssistant, config_entry: MockConfigEntry) -> No
|
|||||||
"""Test Flo by Moen sensors."""
|
"""Test Flo by Moen sensors."""
|
||||||
hass.config.units = US_CUSTOMARY_SYSTEM
|
hass.config.units = US_CUSTOMARY_SYSTEM
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
assert await async_setup_component(
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
hass, FLO_DOMAIN, {CONF_USERNAME: TEST_USER_ID, CONF_PASSWORD: TEST_PASSWORD}
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(hass.data[FLO_DOMAIN][config_entry.entry_id]["devices"]) == 2
|
|
||||||
|
|
||||||
# we should have 5 entities for the valve
|
# we should have 5 entities for the valve
|
||||||
assert (
|
assert (
|
||||||
hass.states.get("sensor.smart_water_shutoff_current_system_mode").state
|
hass.states.get("sensor.smart_water_shutoff_current_system_mode").state
|
||||||
@ -95,13 +88,9 @@ async def test_manual_update_entity(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test manual update entity via service homeasasistant/update_entity."""
|
"""Test manual update entity via service homeasasistant/update_entity."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
assert await async_setup_component(
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
hass, FLO_DOMAIN, {CONF_USERNAME: TEST_USER_ID, CONF_PASSWORD: TEST_PASSWORD}
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(hass.data[FLO_DOMAIN][config_entry.entry_id]["devices"]) == 2
|
|
||||||
|
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
|
|
||||||
call_count = aioclient_mock.call_count
|
call_count = aioclient_mock.call_count
|
||||||
|
@ -13,11 +13,8 @@ from homeassistant.components.flo.switch import (
|
|||||||
SERVICE_SET_SLEEP_MODE,
|
SERVICE_SET_SLEEP_MODE,
|
||||||
SYSTEM_MODE_HOME,
|
SYSTEM_MODE_HOME,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import ATTR_ENTITY_ID
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
|
|
||||||
from .common import TEST_PASSWORD, TEST_USER_ID
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
@ -33,12 +30,9 @@ async def test_services(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test Flo services."""
|
"""Test Flo services."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
assert await async_setup_component(
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
hass, FLO_DOMAIN, {CONF_USERNAME: TEST_USER_ID, CONF_PASSWORD: TEST_PASSWORD}
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(hass.data[FLO_DOMAIN][config_entry.entry_id]["devices"]) == 2
|
|
||||||
assert aioclient_mock.call_count == 8
|
assert aioclient_mock.call_count == 8
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
|
@ -2,13 +2,9 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.flo.const import DOMAIN as FLO_DOMAIN
|
|
||||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, STATE_OFF, STATE_ON
|
from homeassistant.const import STATE_OFF, STATE_ON
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
|
|
||||||
from .common import TEST_PASSWORD, TEST_USER_ID
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
@ -19,13 +15,9 @@ async def test_valve_switches(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test Flo by Moen valve switches."""
|
"""Test Flo by Moen valve switches."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
assert await async_setup_component(
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
hass, FLO_DOMAIN, {CONF_USERNAME: TEST_USER_ID, CONF_PASSWORD: TEST_PASSWORD}
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(hass.data[FLO_DOMAIN][config_entry.entry_id]["devices"]) == 2
|
|
||||||
|
|
||||||
entity_id = "switch.smart_water_shutoff_shutoff_valve"
|
entity_id = "switch.smart_water_shutoff_shutoff_valve"
|
||||||
assert hass.states.get(entity_id).state == STATE_ON
|
assert hass.states.get(entity_id).state == STATE_ON
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user