core/tests/components/ohme/conftest.py
Dan Raper d365092bcc
Add price cap support to Ohme (#140537)
* Add price cap support

* Change service input to box mode

* Add icon for set_price_cap service

* Improve test coverage

* Change ohme service description wording
2025-03-16 14:05:08 +01:00

74 lines
2.0 KiB
Python

"""Provide common fixtures."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
from ohme import ChargerPower, ChargerStatus
import pytest
from homeassistant.components.ohme.const import DOMAIN
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.ohme.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture
def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
"""Return the default mocked config entry."""
return MockConfigEntry(
title="test@example.com",
domain=DOMAIN,
version=1,
data={
CONF_EMAIL: "test@example.com",
CONF_PASSWORD: "hunter2",
},
)
@pytest.fixture
def mock_client():
"""Fixture to mock the OhmeApiClient."""
with (
patch(
"homeassistant.components.ohme.config_flow.OhmeApiClient",
autospec=True,
) as client,
patch(
"homeassistant.components.ohme.OhmeApiClient",
new=client,
),
):
client = client.return_value
client.async_login.return_value = True
client.status = ChargerStatus.CHARGING
client.power = ChargerPower(0, 0, 0, 0)
client.target_soc = 50
client.target_time = (8, 0)
client.battery = 80
client.preconditioning = 15
client.serial = "chargerid"
client.ct_connected = True
client.cap_available = True
client.cap_enabled = True
client.energy = 1000
client.device_info = {
"name": "Ohme Home Pro",
"model": "Home Pro",
"sw_version": "v2.65",
}
client.vehicles = ["Nissan Leaf", "Tesla Model 3"]
client.current_vehicle = "Nissan Leaf"
yield client