mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Remove v2 API support for HomeWizard P1 Meter (#137261)
This commit is contained in:
parent
9a565885cb
commit
d1d498e27d
@ -25,7 +25,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: HomeWizardConfigEntry) -
|
|||||||
|
|
||||||
api: HomeWizardEnergy
|
api: HomeWizardEnergy
|
||||||
|
|
||||||
if token := entry.data.get(CONF_TOKEN):
|
is_battery = entry.unique_id.startswith("HWE-BAT") if entry.unique_id else False
|
||||||
|
|
||||||
|
if (token := entry.data.get(CONF_TOKEN)) and is_battery:
|
||||||
api = HomeWizardEnergyV2(
|
api = HomeWizardEnergyV2(
|
||||||
entry.data[CONF_IP_ADDRESS],
|
entry.data[CONF_IP_ADDRESS],
|
||||||
token=token,
|
token=token,
|
||||||
@ -37,7 +39,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: HomeWizardConfigEntry) -
|
|||||||
clientsession=async_get_clientsession(hass),
|
clientsession=async_get_clientsession(hass),
|
||||||
)
|
)
|
||||||
|
|
||||||
await async_check_v2_support_and_create_issue(hass, entry)
|
if is_battery:
|
||||||
|
await async_check_v2_support_and_create_issue(hass, entry)
|
||||||
|
|
||||||
coordinator = HWEnergyDeviceUpdateCoordinator(hass, api)
|
coordinator = HWEnergyDeviceUpdateCoordinator(hass, api)
|
||||||
try:
|
try:
|
||||||
|
@ -160,7 +160,7 @@ def mock_config_entry_v2() -> MockConfigEntry:
|
|||||||
CONF_IP_ADDRESS: "127.0.0.1",
|
CONF_IP_ADDRESS: "127.0.0.1",
|
||||||
CONF_TOKEN: "00112233445566778899ABCDEFABCDEF",
|
CONF_TOKEN: "00112233445566778899ABCDEFABCDEF",
|
||||||
},
|
},
|
||||||
unique_id="HWE-P1_5c2fafabcdef",
|
unique_id="HWE-BAT_5c2fafabcdef",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import pytest
|
|||||||
|
|
||||||
from homeassistant.components.homewizard.const import DOMAIN
|
from homeassistant.components.homewizard.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||||
|
from homeassistant.const import CONF_IP_ADDRESS, CONF_TOKEN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
@ -52,6 +53,36 @@ async def test_load_unload_v2(
|
|||||||
assert mock_config_entry_v2.state is ConfigEntryState.NOT_LOADED
|
assert mock_config_entry_v2.state is ConfigEntryState.NOT_LOADED
|
||||||
|
|
||||||
|
|
||||||
|
async def test_load_unload_v2_as_v1(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_homewizardenergy: MagicMock,
|
||||||
|
) -> None:
|
||||||
|
"""Test loading and unloading of integration with v2 config, but without using it."""
|
||||||
|
|
||||||
|
# Simulate v2 config but as a P1 Meter
|
||||||
|
mock_config_entry = MockConfigEntry(
|
||||||
|
title="Device",
|
||||||
|
domain=DOMAIN,
|
||||||
|
data={
|
||||||
|
CONF_IP_ADDRESS: "127.0.0.1",
|
||||||
|
CONF_TOKEN: "00112233445566778899ABCDEFABCDEF",
|
||||||
|
},
|
||||||
|
unique_id="HWE-P1_5c2fafabcdef",
|
||||||
|
)
|
||||||
|
|
||||||
|
mock_config_entry.add_to_hass(hass)
|
||||||
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||||
|
assert len(mock_homewizardenergy.combined.mock_calls) == 1
|
||||||
|
|
||||||
|
await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
||||||
|
|
||||||
|
|
||||||
async def test_load_failed_host_unavailable(
|
async def test_load_failed_host_unavailable(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
|
@ -36,6 +36,10 @@ async def test_repair_acquires_token(
|
|||||||
client = await hass_client()
|
client = await hass_client()
|
||||||
|
|
||||||
mock_config_entry.add_to_hass(hass)
|
mock_config_entry.add_to_hass(hass)
|
||||||
|
hass.config_entries.async_update_entry(
|
||||||
|
mock_config_entry, unique_id="HWE-BAT_5c2fafabcdef"
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
with patch("homeassistant.components.homewizard.has_v2_api", return_value=True):
|
with patch("homeassistant.components.homewizard.has_v2_api", return_value=True):
|
||||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user