init home-assistant
This commit is contained in:
1
home-assistant/tests/components/coolmaster/__init__.py
Normal file
1
home-assistant/tests/components/coolmaster/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for the Coolmaster component."""
|
||||
135
home-assistant/tests/components/coolmaster/conftest.py
Normal file
135
home-assistant/tests/components/coolmaster/conftest.py
Normal file
@@ -0,0 +1,135 @@
|
||||
"""Fixtures for the Coolmaster integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.climate import HVACMode
|
||||
from homeassistant.components.coolmaster.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
DEFAULT_INFO: dict[str, str] = {
|
||||
"version": "1",
|
||||
}
|
||||
|
||||
TEST_UNITS: dict[str, dict[str, Any]] = {
|
||||
"L1.100": {
|
||||
"is_on": False,
|
||||
"thermostat": 20,
|
||||
"temperature": 25,
|
||||
"temperature_unit": "celsius",
|
||||
"fan_speed": "low",
|
||||
"mode": "cool",
|
||||
"error_code": None,
|
||||
"clean_filter": False,
|
||||
"swing": None,
|
||||
},
|
||||
"L1.101": {
|
||||
"is_on": True,
|
||||
"thermostat": 68,
|
||||
"temperature": 50,
|
||||
"temperature_unit": "imperial",
|
||||
"fan_speed": "high",
|
||||
"mode": "heat",
|
||||
"error_code": "Err1",
|
||||
"clean_filter": True,
|
||||
"swing": "horizontal",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class CoolMasterNetUnitMock:
|
||||
"""Mock for CoolMasterNetUnit."""
|
||||
|
||||
def __init__(self, unit_id: str, attributes: dict[str, Any]) -> None:
|
||||
"""Initialize the CoolMasterNetUnitMock."""
|
||||
self.unit_id = unit_id
|
||||
self._attributes = attributes
|
||||
for key, value in attributes.items():
|
||||
setattr(self, key, value)
|
||||
|
||||
async def set_fan_speed(self, value: str) -> CoolMasterNetUnitMock:
|
||||
"""Set the fan speed."""
|
||||
self._attributes["fan_speed"] = value
|
||||
return CoolMasterNetUnitMock(self.unit_id, self._attributes)
|
||||
|
||||
async def set_mode(self, value: str) -> CoolMasterNetUnitMock:
|
||||
"""Set the mode."""
|
||||
self._attributes["mode"] = value
|
||||
return CoolMasterNetUnitMock(self.unit_id, self._attributes)
|
||||
|
||||
async def set_thermostat(self, value: float) -> CoolMasterNetUnitMock:
|
||||
"""Set the target temperature."""
|
||||
self._attributes["thermostat"] = value
|
||||
return CoolMasterNetUnitMock(self.unit_id, self._attributes)
|
||||
|
||||
async def set_swing(self, value: str | None) -> CoolMasterNetUnitMock:
|
||||
"""Set the swing mode."""
|
||||
if value == "":
|
||||
raise ValueError
|
||||
self._attributes["swing"] = value
|
||||
return CoolMasterNetUnitMock(self.unit_id, self._attributes)
|
||||
|
||||
async def turn_on(self) -> CoolMasterNetUnitMock:
|
||||
"""Turn a unit on."""
|
||||
self._attributes["is_on"] = True
|
||||
return CoolMasterNetUnitMock(self.unit_id, self._attributes)
|
||||
|
||||
async def turn_off(self) -> CoolMasterNetUnitMock:
|
||||
"""Turn a unit off."""
|
||||
self._attributes["is_on"] = False
|
||||
return CoolMasterNetUnitMock(self.unit_id, self._attributes)
|
||||
|
||||
async def reset_filter(self) -> CoolMasterNetUnitMock:
|
||||
"""Report that the air filter was cleaned and reset the timer."""
|
||||
self._attributes["clean_filter"] = False
|
||||
return CoolMasterNetUnitMock(self.unit_id, self._attributes)
|
||||
|
||||
|
||||
class CoolMasterNetMock:
|
||||
"""Mock for CoolMasterNet."""
|
||||
|
||||
def __init__(self, *_args: Any, **kwargs: Any) -> None:
|
||||
"""Initialize the CoolMasterNetMock."""
|
||||
self._units = copy.deepcopy(TEST_UNITS)
|
||||
|
||||
async def info(self) -> dict[str, Any]:
|
||||
"""Return info about the bridge device."""
|
||||
return DEFAULT_INFO
|
||||
|
||||
async def status(self) -> dict[str, CoolMasterNetUnitMock]:
|
||||
"""Return the units."""
|
||||
return {
|
||||
unit_id: CoolMasterNetUnitMock(unit_id, attributes)
|
||||
for unit_id, attributes in self._units.items()
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def load_int(hass: HomeAssistant) -> MockConfigEntry:
|
||||
"""Set up the Coolmaster integration in Home Assistant."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
"host": "1.2.3.4",
|
||||
"port": 1234,
|
||||
"supported_modes": [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT],
|
||||
},
|
||||
)
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.coolmaster.CoolMasterNet",
|
||||
new=CoolMasterNetMock,
|
||||
):
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
return config_entry
|
||||
@@ -0,0 +1,15 @@
|
||||
"""The test for the Coolmaster binary sensor platform."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
async def test_binary_sensor(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster binary sensor."""
|
||||
assert hass.states.get("binary_sensor.l1_100_clean_filter").state == "off"
|
||||
assert hass.states.get("binary_sensor.l1_101_clean_filter").state == "on"
|
||||
30
home-assistant/tests/components/coolmaster/test_button.py
Normal file
30
home-assistant/tests/components/coolmaster/test_button.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""The test for the Coolmaster button platform."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
async def test_button(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster button."""
|
||||
assert hass.states.get("binary_sensor.l1_101_clean_filter").state == "on"
|
||||
|
||||
button = hass.states.get("button.l1_101_reset_filter")
|
||||
assert button is not None
|
||||
await hass.services.async_call(
|
||||
BUTTON_DOMAIN,
|
||||
SERVICE_PRESS,
|
||||
{
|
||||
ATTR_ENTITY_ID: button.entity_id,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("binary_sensor.l1_101_clean_filter").state == "off"
|
||||
296
home-assistant/tests/components/coolmaster/test_climate.py
Normal file
296
home-assistant/tests/components/coolmaster/test_climate.py
Normal file
@@ -0,0 +1,296 @@
|
||||
"""The test for the Coolmaster climate platform."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pycoolmasternet_async import SWING_MODES
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.climate import (
|
||||
ATTR_CURRENT_TEMPERATURE,
|
||||
ATTR_FAN_MODE,
|
||||
ATTR_FAN_MODES,
|
||||
ATTR_HVAC_MODE,
|
||||
ATTR_HVAC_MODES,
|
||||
ATTR_SWING_MODE,
|
||||
ATTR_SWING_MODES,
|
||||
DOMAIN as CLIMATE_DOMAIN,
|
||||
FAN_HIGH,
|
||||
FAN_LOW,
|
||||
SERVICE_SET_FAN_MODE,
|
||||
SERVICE_SET_HVAC_MODE,
|
||||
SERVICE_SET_SWING_MODE,
|
||||
SERVICE_SET_TEMPERATURE,
|
||||
ClimateEntityFeature,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.components.coolmaster.climate import FAN_MODES
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_FRIENDLY_NAME,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
ATTR_TEMPERATURE,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
||||
|
||||
async def test_climate_state(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate state."""
|
||||
assert hass.states.get("climate.l1_100").state == HVACMode.OFF
|
||||
assert hass.states.get("climate.l1_101").state == HVACMode.HEAT
|
||||
|
||||
|
||||
async def test_climate_friendly_name(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate friendly name."""
|
||||
assert hass.states.get("climate.l1_100").attributes[ATTR_FRIENDLY_NAME] == "L1.100"
|
||||
assert hass.states.get("climate.l1_101").attributes[ATTR_FRIENDLY_NAME] == "L1.101"
|
||||
|
||||
|
||||
async def test_climate_supported_features(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate supported features."""
|
||||
assert hass.states.get("climate.l1_100").attributes[ATTR_SUPPORTED_FEATURES] == (
|
||||
ClimateEntityFeature.TARGET_TEMPERATURE
|
||||
| ClimateEntityFeature.FAN_MODE
|
||||
| ClimateEntityFeature.TURN_OFF
|
||||
| ClimateEntityFeature.TURN_ON
|
||||
)
|
||||
assert hass.states.get("climate.l1_101").attributes[ATTR_SUPPORTED_FEATURES] == (
|
||||
ClimateEntityFeature.TARGET_TEMPERATURE
|
||||
| ClimateEntityFeature.FAN_MODE
|
||||
| ClimateEntityFeature.SWING_MODE
|
||||
| ClimateEntityFeature.TURN_OFF
|
||||
| ClimateEntityFeature.TURN_ON
|
||||
)
|
||||
|
||||
|
||||
async def test_climate_temperature(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate current temperature."""
|
||||
assert hass.states.get("climate.l1_100").attributes[ATTR_CURRENT_TEMPERATURE] == 25
|
||||
assert hass.states.get("climate.l1_101").attributes[ATTR_CURRENT_TEMPERATURE] == 10
|
||||
|
||||
|
||||
async def test_climate_thermostat(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate thermostat."""
|
||||
assert hass.states.get("climate.l1_100").attributes[ATTR_TEMPERATURE] == 20
|
||||
assert hass.states.get("climate.l1_101").attributes[ATTR_TEMPERATURE] == 20
|
||||
|
||||
|
||||
async def test_climate_hvac_modes(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate hvac modes."""
|
||||
assert hass.states.get("climate.l1_100").attributes[ATTR_HVAC_MODES] == [
|
||||
HVACMode.OFF,
|
||||
HVACMode.COOL,
|
||||
HVACMode.HEAT,
|
||||
]
|
||||
assert (
|
||||
hass.states.get("climate.l1_101").attributes[ATTR_HVAC_MODES]
|
||||
== hass.states.get("climate.l1_100").attributes[ATTR_HVAC_MODES]
|
||||
)
|
||||
|
||||
|
||||
async def test_climate_fan_mode(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate fan mode."""
|
||||
assert hass.states.get("climate.l1_100").attributes[ATTR_FAN_MODE] == FAN_LOW
|
||||
assert hass.states.get("climate.l1_101").attributes[ATTR_FAN_MODE] == FAN_HIGH
|
||||
|
||||
|
||||
async def test_climate_fan_modes(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate fan modes."""
|
||||
assert hass.states.get("climate.l1_100").attributes[ATTR_FAN_MODES] == FAN_MODES
|
||||
assert (
|
||||
hass.states.get("climate.l1_101").attributes[ATTR_FAN_MODES]
|
||||
== hass.states.get("climate.l1_100").attributes[ATTR_FAN_MODES]
|
||||
)
|
||||
|
||||
|
||||
async def test_climate_swing_mode(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate swing mode."""
|
||||
assert ATTR_SWING_MODE not in hass.states.get("climate.l1_100").attributes
|
||||
assert hass.states.get("climate.l1_101").attributes[ATTR_SWING_MODE] == "horizontal"
|
||||
|
||||
|
||||
async def test_climate_swing_modes(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate swing modes."""
|
||||
assert ATTR_SWING_MODES not in hass.states.get("climate.l1_100").attributes
|
||||
assert hass.states.get("climate.l1_101").attributes[ATTR_SWING_MODES] == SWING_MODES
|
||||
|
||||
|
||||
async def test_set_temperature(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate set temperature."""
|
||||
assert hass.states.get("climate.l1_100").attributes[ATTR_TEMPERATURE] == 20
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_TEMPERATURE,
|
||||
{
|
||||
ATTR_ENTITY_ID: "climate.l1_100",
|
||||
ATTR_TEMPERATURE: 30,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("climate.l1_100").attributes[ATTR_TEMPERATURE] == 30
|
||||
|
||||
|
||||
async def test_set_fan_mode(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate set fan mode."""
|
||||
assert hass.states.get("climate.l1_100").attributes[ATTR_FAN_MODE] == FAN_LOW
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_FAN_MODE,
|
||||
{
|
||||
ATTR_ENTITY_ID: "climate.l1_100",
|
||||
ATTR_FAN_MODE: FAN_HIGH,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("climate.l1_100").attributes[ATTR_FAN_MODE] == FAN_HIGH
|
||||
|
||||
|
||||
async def test_set_swing_mode(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate set swing mode."""
|
||||
assert hass.states.get("climate.l1_101").attributes[ATTR_SWING_MODE] == "horizontal"
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_SWING_MODE,
|
||||
{
|
||||
ATTR_ENTITY_ID: "climate.l1_101",
|
||||
ATTR_SWING_MODE: "vertical",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("climate.l1_101").attributes[ATTR_SWING_MODE] == "vertical"
|
||||
|
||||
|
||||
async def test_set_swing_mode_error(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate set swing mode with error."""
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_SWING_MODE,
|
||||
{
|
||||
ATTR_ENTITY_ID: "climate.l1_101",
|
||||
ATTR_SWING_MODE: "",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
|
||||
async def test_set_hvac_mode(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate set hvac mode."""
|
||||
assert hass.states.get("climate.l1_100").state == HVACMode.OFF
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_HVAC_MODE,
|
||||
{
|
||||
ATTR_ENTITY_ID: "climate.l1_100",
|
||||
ATTR_HVAC_MODE: HVACMode.HEAT,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("climate.l1_100").state == HVACMode.HEAT
|
||||
|
||||
|
||||
async def test_set_hvac_mode_off(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate set hvac mode to off."""
|
||||
assert hass.states.get("climate.l1_101").state == HVACMode.HEAT
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_HVAC_MODE,
|
||||
{
|
||||
ATTR_ENTITY_ID: "climate.l1_101",
|
||||
ATTR_HVAC_MODE: HVACMode.OFF,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("climate.l1_101").state == HVACMode.OFF
|
||||
|
||||
|
||||
async def test_turn_on(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate turn on."""
|
||||
assert hass.states.get("climate.l1_100").state == HVACMode.OFF
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{
|
||||
ATTR_ENTITY_ID: "climate.l1_100",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("climate.l1_100").state == HVACMode.COOL
|
||||
|
||||
|
||||
async def test_turn_off(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster climate turn off."""
|
||||
assert hass.states.get("climate.l1_101").state == HVACMode.HEAT
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{
|
||||
ATTR_ENTITY_ID: "climate.l1_101",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("climate.l1_101").state == HVACMode.OFF
|
||||
105
home-assistant/tests/components/coolmaster/test_config_flow.py
Normal file
105
home-assistant/tests/components/coolmaster/test_config_flow.py
Normal file
@@ -0,0 +1,105 @@
|
||||
"""Test the Coolmaster config flow."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.coolmaster.config_flow import AVAILABLE_MODES
|
||||
from homeassistant.components.coolmaster.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
|
||||
def _flow_data():
|
||||
options = {"host": "1.1.1.1"}
|
||||
for mode in AVAILABLE_MODES:
|
||||
options[mode] = True
|
||||
options["swing_support"] = False
|
||||
return options
|
||||
|
||||
|
||||
async def test_form(hass: HomeAssistant) -> None:
|
||||
"""Test we get the form."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] is None
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.coolmaster.config_flow.CoolMasterNet.status",
|
||||
return_value={"test_id": "test_unit"},
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.coolmaster.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry,
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], _flow_data()
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result2["title"] == "1.1.1.1"
|
||||
assert result2["data"] == {
|
||||
"host": "1.1.1.1",
|
||||
"port": 10102,
|
||||
"supported_modes": AVAILABLE_MODES,
|
||||
"swing_support": False,
|
||||
}
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_form_timeout(hass: HomeAssistant) -> None:
|
||||
"""Test we handle a connection timeout."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.coolmaster.config_flow.CoolMasterNet.status",
|
||||
side_effect=TimeoutError(),
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], _flow_data()
|
||||
)
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
|
||||
async def test_form_connection_refused(hass: HomeAssistant) -> None:
|
||||
"""Test we handle a connection error."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.coolmaster.config_flow.CoolMasterNet.status",
|
||||
side_effect=ConnectionRefusedError(),
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], _flow_data()
|
||||
)
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
|
||||
async def test_form_no_units(hass: HomeAssistant) -> None:
|
||||
"""Test we handle no units found."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.coolmaster.config_flow.CoolMasterNet.status",
|
||||
return_value={},
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], _flow_data()
|
||||
)
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["errors"] == {"base": "no_units"}
|
||||
27
home-assistant/tests/components/coolmaster/test_init.py
Normal file
27
home-assistant/tests/components/coolmaster/test_init.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""The test for the Coolmaster integration."""
|
||||
|
||||
from homeassistant.components.coolmaster.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
async def test_load_entry(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test Coolmaster initial load."""
|
||||
# 2 units times 4 entities (climate, binary_sensor, sensor, button).
|
||||
assert hass.states.async_entity_ids_count() == 8
|
||||
assert load_int.state is ConfigEntryState.LOADED
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test Coolmaster unloading an entry."""
|
||||
assert load_int.entry_id in hass.data.get(DOMAIN)
|
||||
await hass.config_entries.async_unload(load_int.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert load_int.state is ConfigEntryState.NOT_LOADED
|
||||
assert not hass.data.get(DOMAIN)
|
||||
15
home-assistant/tests/components/coolmaster/test_sensor.py
Normal file
15
home-assistant/tests/components/coolmaster/test_sensor.py
Normal file
@@ -0,0 +1,15 @@
|
||||
"""The test for the Coolmaster sensor platform."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
async def test_sensor(
|
||||
hass: HomeAssistant,
|
||||
load_int: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test the Coolmaster sensor."""
|
||||
assert hass.states.get("sensor.l1_100_error_code").state == "OK"
|
||||
assert hass.states.get("sensor.l1_101_error_code").state == "Err1"
|
||||
Reference in New Issue
Block a user