Don't create water heater entity when no temp sensor for my-PV integration (#184042)

This commit is contained in:
rrooggiieerr
2026-10-05 11:55:03 +00:00
committed by Franck Nijhof
parent 5b79f0bb99
commit e337b225f7
2 changed files with 24 additions and 23 deletions
@@ -17,7 +17,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import DOMAIN
from .coordinator import MyPVConfigEntry, MyPVCoordinator
from .entity import MyPVDataEntity
from .entity import MyPVBaseEntity
async def async_setup_entry(
@@ -29,8 +29,10 @@ async def async_setup_entry(
coordinator = config_entry.runtime_data
entities = []
if coordinator.device.supports_main_mode(MyPVDeviceMainMode.HOT_WATER) and (
configuration := coordinator.device.get_setup_configuration("ww1target")
if (
coordinator.device.supports_main_mode(MyPVDeviceMainMode.HOT_WATER)
and coordinator.device.current_temperature is not None
and (configuration := coordinator.device.get_setup_configuration("ww1target"))
):
entity_description = WaterHeaterEntityDescription(
key="temp1",
@@ -47,7 +49,7 @@ async def async_setup_entry(
async_add_entities(entities)
class MyPVWaterHeater(MyPVDataEntity, WaterHeaterEntity):
class MyPVWaterHeater(MyPVBaseEntity, WaterHeaterEntity):
"""my-PV water heater."""
_attr_name = None
+18 -19
View File
@@ -1,6 +1,6 @@
"""Test the my-PV water heater."""
from unittest.mock import AsyncMock, Mock, patch
from unittest.mock import AsyncMock, patch
from my_pv.exceptions import MyPVAuthenticationError, MyPVConnectionError
import pytest
@@ -47,6 +47,23 @@ async def test_water_heater(
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
async def test_water_heater_no_temp_sensor(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_my_pv_client: AsyncMock,
) -> None:
"""Test if a water_heater is not created when there is no temperature sensor connected."""
mock_config_entry.add_to_hass(hass)
mock_my_pv_client.current_temperature = None
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get("water_heater.my_pv_ac_elwa_2")
assert state is None
async def test_water_heater_unavailable_not_connected(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
@@ -65,24 +82,6 @@ async def test_water_heater_unavailable_not_connected(
assert state.state == STATE_UNAVAILABLE
async def test_water_heater_unavailable_data_value_none(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_my_pv_client: AsyncMock,
) -> None:
"""Test if a water_heater is unavailable when data value is None."""
mock_config_entry.add_to_hass(hass)
mock_my_pv_client.get_data_value = Mock(return_value=None)
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get("water_heater.my_pv_ac_elwa_2")
assert state.state == STATE_UNAVAILABLE
async def test_water_heater_turn_off(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,