hass-core/tests/components/drop_connect/conftest.py
Patrick Frazer fce1b6d248
Add DROP integration (#104319)
* Add DROP integration

* Remove all but one platform for first PR

* Simplify initialization of hass.data[] structure

* Remove unnecessary mnemonic 'DROP_' prefix from DOMAIN constants

* Remove unnecessary whitespace

* Clarify configuration 'confirm' step description

* Remove unnecessary whitespace

* Use device class where applicable

* Remove unnecessary constructor and change its elements to class variables

* Change base entity inheritance to CoordinatorEntity

* Make sensor definitions more concise

* Rename HA domain from drop to drop_connect

* Remove underscores from class and function names

* Remove duplicate temperature sensor

* Change title capitalization

* Refactor using SensorEntityDescription

* Remove unnecessary intermediate dict layer

* Remove generated translations file

* Remove currently unused string values

* Use constants in sensor definitions

* Replace values with constants

* Move translation keys

* Remove unnecessary unique ID and config entry references

* Clean up DROPEntity initialization

* Clean up sensors

* Rename vars and functions according to style

* Remove redundant self references

* Clean up DROPSensor initializer

* Add missing state classes

* Simplify detection of configured devices

* Change entity identifiers to create device linkage

* Move device_info to coordinator

* Remove unnecessary properties

* Correct hub device IDs

* Remove redundant attribute

* Replace optional UID with assert

* Remove redundant attribute

* Correct coordinator initialization

* Fix mypy error

* Move API functionality to 3rd party library

* Abstract device to sensor map into a dict

* Unsubscribe MQTT on unload

* Move entity device information

* Make type checking for mypy conditional

* Bump dropmqttapi to 1.0.1

* Freeze dataclass to match parent class

* Fix race condition in MQTT unsubscribe setup

* Ensure unit tests begin with invalid MQTT state

* Change unit tests to reflect device firmware

* Move MQTT subscription out of the coordinator

* Tidy up initializer

* Move entirety of MQTT subscription out of the coordinator

* Make drop_api a class property

* Remove unnecessary type checks

* Simplify some unit test asserts

* Remove argument matching default

* Add entity category to battery and cartridge life sensors
2023-12-22 14:24:08 +01:00

177 lines
5.4 KiB
Python

"""Define fixtures available for all tests."""
import pytest
from homeassistant.components.drop_connect.const import (
CONF_COMMAND_TOPIC,
CONF_DATA_TOPIC,
CONF_DEVICE_DESC,
CONF_DEVICE_ID,
CONF_DEVICE_NAME,
CONF_DEVICE_OWNER_ID,
CONF_DEVICE_TYPE,
CONF_HUB_ID,
DOMAIN,
)
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
@pytest.fixture
def config_entry_hub(hass: HomeAssistant):
"""Config entry version 1 fixture."""
return MockConfigEntry(
domain=DOMAIN,
unique_id="DROP-1_C0FFEE_255",
data={
CONF_COMMAND_TOPIC: "drop_connect/DROP-1_C0FFEE/255/cmd",
CONF_DATA_TOPIC: "drop_connect/DROP-1_C0FFEE/255/#",
CONF_DEVICE_DESC: "Hub",
CONF_DEVICE_ID: 255,
CONF_DEVICE_NAME: "Hub DROP-1_C0FFEE",
CONF_DEVICE_TYPE: "hub",
CONF_HUB_ID: "DROP-1_C0FFEE",
CONF_DEVICE_OWNER_ID: "DROP-1_C0FFEE_255",
},
version=1,
)
@pytest.fixture
def config_entry_salt(hass: HomeAssistant):
"""Config entry version 1 fixture."""
return MockConfigEntry(
domain=DOMAIN,
unique_id="DROP-1_C0FFEE_8",
data={
CONF_COMMAND_TOPIC: "drop_connect/DROP-1_C0FFEE/8/cmd",
CONF_DATA_TOPIC: "drop_connect/DROP-1_C0FFEE/8/#",
CONF_DEVICE_DESC: "Salt Sensor",
CONF_DEVICE_ID: 8,
CONF_DEVICE_NAME: "Salt Sensor",
CONF_DEVICE_TYPE: "salt",
CONF_HUB_ID: "DROP-1_C0FFEE",
CONF_DEVICE_OWNER_ID: "DROP-1_C0FFEE_255",
},
version=1,
)
@pytest.fixture
def config_entry_leak(hass: HomeAssistant):
"""Config entry version 1 fixture."""
return MockConfigEntry(
domain=DOMAIN,
unique_id="DROP-1_C0FFEE_20",
data={
CONF_COMMAND_TOPIC: "drop_connect/DROP-1_C0FFEE/20/cmd",
CONF_DATA_TOPIC: "drop_connect/DROP-1_C0FFEE/20/#",
CONF_DEVICE_DESC: "Leak Detector",
CONF_DEVICE_ID: 20,
CONF_DEVICE_NAME: "Leak Detector",
CONF_DEVICE_TYPE: "leak",
CONF_HUB_ID: "DROP-1_C0FFEE",
CONF_DEVICE_OWNER_ID: "DROP-1_C0FFEE_255",
},
version=1,
)
@pytest.fixture
def config_entry_softener(hass: HomeAssistant):
"""Config entry version 1 fixture."""
return MockConfigEntry(
domain=DOMAIN,
unique_id="DROP-1_C0FFEE_0",
data={
CONF_COMMAND_TOPIC: "drop_connect/DROP-1_C0FFEE/0/cmd",
CONF_DATA_TOPIC: "drop_connect/DROP-1_C0FFEE/0/#",
CONF_DEVICE_DESC: "Softener",
CONF_DEVICE_ID: 0,
CONF_DEVICE_NAME: "Softener",
CONF_DEVICE_TYPE: "soft",
CONF_HUB_ID: "DROP-1_C0FFEE",
CONF_DEVICE_OWNER_ID: "DROP-1_C0FFEE_255",
},
version=1,
)
@pytest.fixture
def config_entry_filter(hass: HomeAssistant):
"""Config entry version 1 fixture."""
return MockConfigEntry(
domain=DOMAIN,
unique_id="DROP-1_C0FFEE_4",
data={
CONF_COMMAND_TOPIC: "drop_connect/DROP-1_C0FFEE/4/cmd",
CONF_DATA_TOPIC: "drop_connect/DROP-1_C0FFEE/4/#",
CONF_DEVICE_DESC: "Filter",
CONF_DEVICE_ID: 4,
CONF_DEVICE_NAME: "Filter",
CONF_DEVICE_TYPE: "filt",
CONF_HUB_ID: "DROP-1_C0FFEE",
CONF_DEVICE_OWNER_ID: "DROP-1_C0FFEE_255",
},
version=1,
)
@pytest.fixture
def config_entry_protection_valve(hass: HomeAssistant):
"""Config entry version 1 fixture."""
return MockConfigEntry(
domain=DOMAIN,
unique_id="DROP-1_C0FFEE_78",
data={
CONF_COMMAND_TOPIC: "drop_connect/DROP-1_C0FFEE/78/cmd",
CONF_DATA_TOPIC: "drop_connect/DROP-1_C0FFEE/78/#",
CONF_DEVICE_DESC: "Protection Valve",
CONF_DEVICE_ID: 78,
CONF_DEVICE_NAME: "Protection Valve",
CONF_DEVICE_TYPE: "pv",
CONF_HUB_ID: "DROP-1_C0FFEE",
CONF_DEVICE_OWNER_ID: "DROP-1_C0FFEE_255",
},
version=1,
)
@pytest.fixture
def config_entry_pump_controller(hass: HomeAssistant):
"""Config entry version 1 fixture."""
return MockConfigEntry(
domain=DOMAIN,
unique_id="DROP-1_C0FFEE_83",
data={
CONF_COMMAND_TOPIC: "drop_connect/DROP-1_C0FFEE/83/cmd",
CONF_DATA_TOPIC: "drop_connect/DROP-1_C0FFEE/83/#",
CONF_DEVICE_DESC: "Pump Controller",
CONF_DEVICE_ID: 83,
CONF_DEVICE_NAME: "Pump Controller",
CONF_DEVICE_TYPE: "pc",
CONF_HUB_ID: "DROP-1_C0FFEE",
CONF_DEVICE_OWNER_ID: "DROP-1_C0FFEE_255",
},
version=1,
)
@pytest.fixture
def config_entry_ro_filter(hass: HomeAssistant):
"""Config entry version 1 fixture."""
return MockConfigEntry(
domain=DOMAIN,
unique_id="DROP-1_C0FFEE_255",
data={
CONF_COMMAND_TOPIC: "drop_connect/DROP-1_C0FFEE/95/cmd",
CONF_DATA_TOPIC: "drop_connect/DROP-1_C0FFEE/95/#",
CONF_DEVICE_DESC: "RO Filter",
CONF_DEVICE_ID: 95,
CONF_DEVICE_NAME: "RO Filter",
CONF_DEVICE_TYPE: "ro",
CONF_HUB_ID: "DROP-1_C0FFEE",
CONF_DEVICE_OWNER_ID: "DROP-1_C0FFEE_255",
},
version=1,
)